Created
January 27, 2022 16:21
-
-
Save MarcoGriep88/109107467b9cddddabf4f3b0f175dfbc to your computer and use it in GitHub Desktop.
Ivanti DSM - PSX PowerShell Extensions Script zum reinstallieren von fehlgeschlagenen Policy Instanzen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param | |
( | |
[string]$argServer = "localhost:8090", | |
[string]$argUser = "domain\username", | |
[string]$argPassword = "Passwort12345", | |
[string]$context = "emdb:\rootDSE\Managed Users & Computers\2\. Computers\*" | |
) | |
import-module psx7 -DisableNameChecking | |
$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 | |
try | |
{ | |
new-psdrive -name emdb -root $Server -scope script -psprovider blsemdb -Credential $credential | |
emdb: | |
$computer = Get-EmdbComputer $context -Recurse | |
foreach ($comp in $computer) | |
{ | |
Write-Host "Getting policies for computer ID" + $comp.Name | |
$PolicyList = $comp | Get-EmdbPolicyInstance | |
Foreach ($instance in $PolicyList) | |
{ | |
if ($instance.ComplianceState -eq "NotCompliant") | |
{ | |
$instance.Reinstall(); | |
Write-Host $comp.Name " Set Policy " $instance.ID " " $instance.AssignedObjectName.ToString() "to reinstall." | |
$file = "C:\temp\" + $loggedInUser + "_done.log" | |
$stream = new-object IO.FileStream $file, 'Append', 'Write', 'Read' | |
$sWriter = new-object System.IO.StreamWriter $stream; | |
$ln = $loggedInUser + "; triggered a reinstall on policy instance: " + $instance.ID + " with the Policy Name: " + $instance.AssignedObjectName.ToString() + ";" + $comp.Name; | |
$sWriter.WriteLine($ln) | |
$sWriter.close() | |
} | |
} | |
} | |
} | |
catch | |
{ | |
$stream = new-object IO.FileStream "C:\temp\detpolicies.log", 'Append', 'Write', 'Read' | |
$sWriter = new-object System.IO.StreamWriter $stream; | |
$sWriter.WriteLine($Error[0].Exception) | |
$sWriter.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment