Guys.
I have two issues with a script I am working on.
1)The script will obtain the Computer name, username and last reboot time. I am pulling a list of computer names from Active Directory. Now if there is a single computer object in the OU then this returns all the info that I am expecting to return. If I put two computers in the OU then its only returning the info for the first machine and not the second.
I would have though this would have worked as I am using ForEach-Object ?
2) I am struggling with the output and would like to export it to CSV , I receive the error below. using write-object $object does display correctly.
Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value
The code I have so far is below
====================
$ADComputers = Get-QADComputer -SizeLimit 0 -SearchRoot "OU NAME HERE" |
ForEach-Object {
$LoggedOnUser = Get-WmiObject win32_computersystem -Computer $_.name | Select username
$RebootTime = Get-WmiObject -class Win32_OperatingSystem -ComputerName $_.name | Select-Object __SERVER,@{label='LastBootUpTime';expression={$_.ConvertToDateTime($_.LastBootUpTime)}}
$Proc = Get-WmiObject Win32_processor -ComputerName $_.name | Select-Object -First 1
$Object = New-Object PSObject -Property @{
ComputerName = $proc.SystemName
LoggedOnUser = $LoggedOnUser.username
RebootTime = $RebootTime.LastBootUpTime
}
}
write-output $Object