Hello. I'm working on a script to disable user accounts and part of it includes a mail forward. I keep receiving this error though and I'm not sure why so any help would be greatly appreciated.
$WillMail = read-host "Will mail be forwarded? Enter Y or N: "
if (($WillMail -eq "Y") -or ($WillMail -eq "Yes"))
{
#Mailbox to forward
$UserEmail = Read-Host "Enter mailbox to forward: "
Mailbox to forward to
$ForwardEmail = Read-Host "Enter mailbox to forward to: "
}
Else
{
if (($WillMail -eq "N") -or ($WillMail -eq "No"))
{
Logwrite "==Mail was NOT forwarded"
}
}
Function LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
Error
Will mail be forwarded? Enter Y or N: : N
Add-Content : Cannot bind argument to parameter 'Path' because it is null.
At \\velnyad01\c$\DisableUserTest.ps1:9 char:15
+ Add-content <<<< $Logfile -value $logstring
+ CategoryInfo : InvalidData: (:) [Add-Content], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddContentC
ommand
Code
#Will Mail be forwarded$WillMail = read-host "Will mail be forwarded? Enter Y or N: "
if (($WillMail -eq "Y") -or ($WillMail -eq "Yes"))
{
#Mailbox to forward
$UserEmail = Read-Host "Enter mailbox to forward: "
Mailbox to forward to
$ForwardEmail = Read-Host "Enter mailbox to forward to: "
}
Else
{
if (($WillMail -eq "N") -or ($WillMail -eq "No"))
{
Logwrite "==Mail was NOT forwarded"
}
}
Spot I believe error is referring to (Add-content would be line 9 in the code)
#Logging FunctionFunction LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}