Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

PowerShell Script Error. Please help!!!

$
0
0
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. 

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 Function
Function LogWrite

{
   Param ([string]$logstring)
   Add-content $Logfile -value $logstring
}


Viewing all articles
Browse latest Browse all 2562

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>