if null question
hi guys,
why null value if statements not working?
function getoutputlog($input) { $targetdir = "c:\tewmp\scriptouput" $logfile = "c:\temp\scriptoutput\log.txt" if(!(test-path -path $targetdir)) { new-item -itemtype directory -path $targetdir } if($input) { $currentdat = get-date out-file $logfile -append -inputobject "### $currentdate ###" } if(!$input) { out-file $logfile -append inputobject "i did it!" } }
regardless of how call function $input equal or $null unable date output.
getoutputlog
getoutputlog "dslsadjls"
looks has using parameter name of $input. once changed function's parameter name, things started work
function test($myvar) { if ($myvar) { # not empty } else { #empty } }having multiple if statements test if empty or not empty not needed, use if/else, if not empty this, otherwise empty this
if find post has answered question, please mark answer. if find post helpful in anyway, please click vote helpful.
don't retire technet
Windows Server > Windows PowerShell
Comments
Post a Comment