Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Combining get-adcomputer and Win32_computersystem

$
0
0

Hi

I am trying to write a script that will return Name and lastLogondate from get-adcomputer and username from Win32_computersystem and write it to a out-file. below is what I have so far but I cant get anything to write to the file. no errors.

Remove-ItemC:\Temp\results.txt

 

$day=Read-Host'Enter the number since last logon.'

 

$then= (Get-Date).AddDays(-$day)

 

$ou="OU=Installations,DC=conso,DC=ds,DC=com"

 

$Results= @()

 

$results+=ForEach($compObjin$than) { 

 

$cs=Get-ADComputer-PropertiesName,lastLogonDate,Description-Filter {lastLogonDate-lt$then} -SearchBase$ou#| FT Name,Description,lastLogonDate | Out-File C:\Temp\results.txt

 

$logon=GWMI-ClassWin32_computerSystem-PropertyUserName-ComputerName$compObj|FTUserName

 

New-Object-TypeNamepsobject-Property @{                  

     

'ComputerName'=$cs.Name            

'Date'=$cs.LastlogonDate              

'User'=$logon.username

 

 }

 

}

 

$results|Select-ObjectComputerName,User,Date|Out-FileC:\Temp\results.txt

 

Thanks


Viewing all articles
Browse latest Browse all 6937

Trending Articles