Last active
February 17, 2022 08:15
-
-
Save MarcoGriep88/f8f844febfa50c54433b6098c898d7aa to your computer and use it in GitHub Desktop.
Ivanti DSM - Delete old computer objects
This file contains 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', | |
#localhost:8090 | |
[string]$argUser = 'domain\user', | |
#domain\username | |
[string]$argPassword = 'password', | |
#Password123 | |
[string]$context = "emdb:\rootDSE\Managed Users & Computers\*", | |
[switch]$WhatIf = $false | |
) | |
#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)" | |
new-psdrive -name emdb -root $Server -scope script -psprovider blsemdb -Credential $credential | |
emdb: | |
$dateString = Read-Host "Delete computer if older than date (yyyy-MM-dd):" | |
$date = [DateTime]::parseexact($dateString, 'yyyy-MM-dd', $null) | |
$computers = Get-EmdbComputer $context -Recurse | |
foreach ($machine in $computers) | |
{ | |
if ($machine.LastSyncDate -lt $date) { | |
Write-Host "Deleting machine $($machine.Name)" | |
if ($WhatIf -eq $False) { $machine.Delete(); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment