вторник, 8 марта 2016 г.

Powershell. Информация об установленном ПО

Скрипт для Icinga 2 - Информация об установленном ПО



##############################

#Скрипт для Icinga 2 - Информация об установленном ПО
#Сатин Павел 07.03.2016
##############################
$returnStateOK = 0
$returnStateWarning = 1
$returnStateCritical = 2
$returnStateUnknown = 3
    $computername = $args[0]
Try
{

$array = @()
#foreach($pc in $computers){
    #Define the variable to hold the location of Currently Installed Programs
    $UninstallKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
    #Create an instance of the Registry Object and open the HKLM base key
    $reg = [microsoft.win32.registrykey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $computername)
    #Drill down into the Uninstall key using the OpenSubKey Method
    $regkey = $reg.OpenSubKey($UninstallKey)
    #Retrieve an array of string that contain all the subkey names
    $subkeys = $regkey.GetSubKeyNames()
    #Open each Subkey and use GetValue Method to return the required values for each
    foreach($key in $subkeys){
        $thisKey = $UninstallKey + "\\" + $key
        $thisSubKey = $reg.OpenSubKey($thisKey)
        $obj = New-Object PSObject
        #$obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername
        $obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))
        $obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))
        $obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))
        $obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))
        $obj | Add-Member -MemberType NoteProperty -Name "InstallDate" -Value $($thisSubKey.GetValue("InstallDate"))
        $array += $obj
    }
#}
Write-Host "Installed software:"
$array | Where-Object { $_.DisplayName } | select DisplayName, Publisher | ConvertTo-Html -Fragment
}
Catch
{
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
Write-Host $ErrorMessage
[System.Environment]::Exit($returnStateCritical)
}

Комментариев нет:

Отправить комментарий