Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Checking if computer does not exists

$
0
0

Hello Eric,

A possible solution for you would be to trap the exception thrown by Get-ADComputer and remove the device from SCCM in the catch block.

Example:

$ComputerName = 'MyTest'
$Domain = 'viamonstra.local'
try
{
Get-ADComputer -Identity $ComputerName -Server $Domain
}
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]
{
Write-Verbose -Message ('Device "{0}" not found in Active Directory domain {1}' -f $ComputerName, $Domain)
Write-Verbose -Message ('Removing device "{0}" from SCCM' -f $ComputerName)
...
}

Best,
Daniel


Viewing all articles
Browse latest Browse all 13067

Trending Articles