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

Script to Query AD for List of Software

$
0
0

Hi All , newbie here.

I have following script to query AD, get list of PC/servers that match filter ( operating system) , do a ping test and if successful will prompt to enter name of software to search and list , how can I get this to write to a CSV file , so far bit stuck

$Computer = Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*' } -Properties OperatingSystem | Select Name, OperatingSystem
# Test Connection with Ping
 ForEach ($Computer in $Computer){
       
        if(Test-Connection $computer -Quiet -Count 2){
            Write-Host -ForegroundColor Green "Ping Reply received from $computer."
            write-host "`Connecting to $computer..."
            }
}

$Path = foreach ($Computer in $Computer) { Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall}

$searchterm = read-host “Enter search term for uninstallers”
$uninstallers = $Path
$founditems = $uninstallers | ? {(Get-ItemProperty -path (“HKLM:\”+$_.name) -name Displayname -erroraction silentlycontinue) -match $searchterm}
write-host “Searched registry for uninstall information on $searchterm”
write-host “——————————————”
if ($founditems -eq $null) {“None found”} else {
write-host “Found “($founditems | measure-object).count” item(s):`n”
$founditems | % {
    Write-Host “Displayname: “$_.getvalue(“Displayname”)
    Write-Host “Displayversion: “$_.getvalue(“Displayversion”)
    Write-Host “InstallDate: “$_.getvalue(“InstallDate”)
    Write-Host “InstallSource: “$_.getvalue(“InstallSource”)
    Write-Host “UninstallString: “$_.getvalue(“UninstallString”)
    Write-Host “`n”
}
}
else
        {
            Write-Host -ForegroundColor Red "No Ping Reply received from $computer"
        }


Viewing all articles
Browse latest Browse all 6937

Trending Articles