Guys.
Banging my head against the wall slightly with this one. I am looking to pull a list of AD names out of a certain OU and pass them along in the script to use.
I am looking to query the machine and obtain the following
Computer Name , Logged On User, Last Reboot time.
Now if i remove the line below then the script runs and returns Computer Name and Logged On user. However i need last reboot date.
$Reboot = Get-CimInstance -ClassName win32_operatingsystem -ComputerName $PSItem | Select-Object -ExpandProperty lastbootuptime
--------------
The code i have so far is below.
$Computers = Get-QADComputer -SizeLimit 0 -SearchRoot "OU PATH HERE" |
Select-Object -ExpandProperty Name
$Computers | ForEach-Object {
$User = Get-CimInstance Win32_ComputerSystem -ComputerName $PSItem | Select-Object -ExpandProperty UserName
$Reboot = Get-CimInstance -ClassName win32_operatingsystem -ComputerName $PSItem | Select-Object -ExpandProperty lastbootuptime
$Obj = New-Object -TypeName PSObject -Property @{
"Computer" = $PSItem
"User" = $User
"Reboot" = $Reboot
}
Write-Output $Obj}