Hi All,
I'm sure that this is a really easy one but I'm newb to Powershell and its delights and am really struggling.
I am trying to output the results of the Get Last Logon.ps1 to a .csv file. This script is available on the Technet Script Centre so I wont include it all but just the bit that I think is the important bit and what I have done.
The script creates an array called $servers using the Get-Content cmdlet from a list of machine names in a .txt file.
I'm trying to use the Export-Csv cmdlet which seems like a really easy way to achieve what I want. However the only line that is output is the last machine in the in the list.
I have tried using For-Each but I just get in a mess.
Extract below:
#Creating Custom PSObject For Output
New-Object -TypeName PSObject -Property @{
Computer=$Computer
User=$User
SID=$Script:UserSID
Time=$Script:Time
CurrentlyLoggedOn=$Loaded
} | Select-Object Computer, User, SID, Time, CurrentlyLoggedOn | Export-Csv "c:\scripts\test.csv" -notype
I hope someone can point out what I'm doing wrong.
Thanks in advance,
Sean
↧