Quantcast
Channel: Ivanti User Community: Message List
Viewing all articles
Browse latest Browse all 12704

Re: Remove LANDesk computer objects

$
0
0

I know you didn't want to script something - but use this simple powershell script to do it that I made -

 

adldsync.ps1:

 

# Configuration

$serviceaccount="account"

$password="password"

$corename="core.domain.ext"

$cachelocation="c:\path\ADCache.txt"

 

 

# Use these two lines to include credentials in script by replacing mypassword and myusername.

$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force

$mycreds = New-Object System.Management.Automation.PSCredential ($serviceaccount, $secpasswd)

 

# Use the Get-Credential line to prompt for credentials when you manually run it

#$mycreds = Get-Credential -Credential "myusername"

#New-Object System.Management.Automation.PSCredential ("myusername", $secpasswd)

 

# Create Web Service

$LMWS = New-WebServiceProxy -uri http://$corename/mbsdkservice/msgsdk.asmx?WSDL -Credential $mycreds

 

# Function to remove devices by their hostname from LD.  Put all available FQDNs below.

function deleteComputerFromLD {param([string]$name)

    # Write name being removed to console

    $name

    # Remove from LD

    $LMWS.DeleteComputerByIPName($name)

    $LMWS.DeleteComputerByIPName($name+".domain.ext")

    $LMWS.DeleteComputerByIPName($name+".other.domain.ext")

}

 

 

# Get all computers in AD currently

$arrComputers = Get-ADComputer -Filter * | select-object -expandproperty name

 

 

# Get all computers in AD cache from last scan

$arrCacheComputers = Get-Content $cachelocation

 

 

# Remove any computer no longer in AD from LANDesk

Compare-Object $arrCacheComputers $arrComputers | where {$_.sideindicator -eq "<="} | % {deleteComputerFromLD($_.inputobject)}

 

 

# Update cache

$arrComputers | Out-File $cachelocation

 

 

 

 

 

Schedule this script on your core or another server using this command in your scheduled task:

Start a program: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"

Parameters: -file "C:\path\adldsync.ps1"

 

 

Accounts:

- You will need a AD read-only account to schedule the task under.

- You will need a local/ad service account that has the all devices scope and the ability to delete computers from inventory that you will hard code into this script.

 

 

*Note - this has only been tested on 9.5.2 - but should work with any version of LANDesk that supports the DeleteComputerByIPName web service function.

 

http://petermassa.com/?p=330


Viewing all articles
Browse latest Browse all 12704

Trending Articles