I am having trouble using powershell and pslogged on to pull the information of "the last logged on user" and the "logged on timestamp" from the psloggedon tool. Basically what I am trying to do is to read from a text file with all the list of the servers'name, and then use pslogged on on them to get the info. So if I run the following command separately, it works
psloogedon \\server1
but when I do this in powershell it doesn't work
$content = [IO.File]::ReadAllText("C:\assets.txt")
Foreach($computer in $content)
{
Invoke-Expression "psloggedon -x -l \\$computer"
} Export-Csv -NoTypeInformation loggedon.csv
and in the assets.txt we have the following content:
server1
server2
server3
etc...
How can i build based on this to 1) make the script work to use psloggedon to get the information 2) parse the loggedon user, the computer name and the timestamp into a CSV with 3 columns file?
Any help is appreciated....