windows server 2008 r2 - Powershell query works in prompt, but not in script -
i trying create script takes input of hostname , tells me current logged on user. works when run command 1 1 on powershell prompt (as admin), doesn't produce expected output when run actual script itself.
here relevant code:
$row.hostname = $hostname $getwmiobject = get-wmiobject -class win32_computersystem -computername $hostname $username = $getwmiobject.username if($username -eq $null) { $row.username = "no current logged on user" } else {$row.username = $username } $csvfile += $row $csvfile |sort-object hostname | export-csv "foo.csv
when ran in command line, right user. when ran script, "no current logged on user". have no clue why happening.
edit: suppose it's of import mention have output writing out file, made changes in code above.
check whatever input have $hostname
variable characters, such newline `n
. when type out, may not give error , work because doesn't have process things that.
powershell windows-server-2008-r2 powershell-v3.0 domaincontroller
No comments:
Post a Comment