I am trying to write a powershell script that will Ping each Hostname in an OU in AD, Output a txt file of online hostnames, then using the Get-WmiObject to get a list of software on each online systems. I've tried and I can't seem to figure out how to output the pinged systems to a txt file of hostnames so I can use that file to create the software list. I know pretty much nothing about Powershell, so I've been trying to steal and borrow, but can't figure out how to make it all work. Here is what I've tried. Any help will be greatly appreciated.
Import-Module active*
$rtn = $null
Get-ADComputer -Filter * -Properties * -searchbase "OU=EnterOUstructurehere" |
ForEach-Object {
$rtn = Test-Connection -CN $_.dnshostname -Count 1 -BufferSize 16 -Quiet
IF($rtn -match ‘True’) {write-host -ForegroundColor green $_.dnshostname}
ELSE { Write-host -ForegroundColor red $_.dnshostname }
}
Using Out-file to output a txt file called computers. Use Get to to pull from the computer.txt file and then:
ForEach-Object {Get-WmiObject -Class Win32_Product -Computer $_.Name} | Select-Object Name, Version | Sort-Object Name | Export-CSV "C:\Users\steven.e.hendricks\OneDrive - US Army\Desktop\Software Inventory\SoftwareInventoryfile.csv" -Append -NoTypeInformation