Skip to content

Instantly share code, notes, and snippets.

@MarcoGriep88
Created January 27, 2022 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcoGriep88/278eaab7a8878a7d07e3be15767053ba to your computer and use it in GitHub Desktop.
Save MarcoGriep88/278eaab7a8878a7d07e3be15767053ba to your computer and use it in GitHub Desktop.
Ivanti DSM - Monitor Job Policies for errors (like pending reboot) - PSX PowerShell Extensions Script
#Install-Module ImportExcel
#Connection Options
param
(
[string]$argServer = 'meinbls.intranet.int:8090',
#localhost:8090
[string]$argUser = 'domain\username',
#domain\username
[string]$argPassword = 'Password123',
#Password123
[string]$context = "emdb:\rootDSE\Managed Users & Computers\*"
)
$subRoutineFlag = 0; #Default = 0 (Change only for debugging)
#Prepare PS to Use HEAT DSM
import-module psx7 -DisableNameChecking
#Create global Authentification
$Server = "\\$argServer";
$Username = $argUser;
$global:path = $context
$password = $argPassword | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($Username, $password)
Write-Host "Using context: " + $context
#Connect to HEAT DSM
new-psdrive -name emdb -root $Server -scope script -psprovider blsemdb -Credential $credential
emdb:
$fileName = "C:\temp\" + (Get-Date).Year.ToString() + "_" + (Get-Date).Month.ToString() + "_" + (Get-Date).Day.ToString() + "_" + (Get-Date).Hour.ToString()+ (Get-Date).Minute.ToString() + (Get-Date).Second.ToString() + "_Jobs.xlsx"
$MyJobPolicys = Get-EmdbPolicy "emdb:\rootDSE\Managed Users & Computers\2\. Computers\Patch-Management-Workstations" -PolicyType "JobPolicy"
$data = @"
Computer,InstallParam,Compliance,isActive,Message
"@
foreach($job in $MyJobPolicys) {
$instances = $job.GetPolicyInstances();
foreach($i in $instances) {
$InstallParam = $i.GetInstallationParameters()[0].Value
$ComplianceState = $i.ComplianceState
$isActive = $i.IsActive
$machine = $i.TargetObjectName
$msg = $i.LastComment
Write-Host $machine "-" $msg
$data += [System.Environment]::NewLine + $machine + "," + $InstallParam + "," + $ComplianceState + "," + $isActive + "," + $msg
}
}
$dataList = $data | ConvertFrom-CSV
$dataList | Export-Excel $fileName -Show -AutoSize -IncludePivotTable -PivotRows Compliance -PivotData @{ Computer = "count" } -IncludePivotChart -ChartType PieExploded3D
# $computers = Get-EmdbComputer $context -Recurse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment