Skip to content

Instantly share code, notes, and snippets.

@MarcoGriep88
Last active February 17, 2022 08:15
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/f8f844febfa50c54433b6098c898d7aa to your computer and use it in GitHub Desktop.
Save MarcoGriep88/f8f844febfa50c54433b6098c898d7aa to your computer and use it in GitHub Desktop.
Ivanti DSM - Delete old computer objects
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