All,
I am creating a script that we will use for Decommissioning PC's and what I've thrown together does work. See below:
#Import SCCM Moduleimport-module '\\networkdrive\ConfigurationManager.psd1'
#Import Active Directory Module
Import-Module '\\networkdrive\ActiveDirectory.psd1'
cd CAS:
#Enter Machine Name
$Name = Read-Host 'What is the machine name?'
#Remove from SCCM
Get-CMDevice -Name "$Name"
Remove-CMDevice -DeviceName "$Name" -Force
$ErrorActionPreference= 'silentlycontinue'
#UKLON
#Disable UK Machine AD Account
Disable-ADAccount -Identity "CN=$Name,OU=Windows 7 Prod Workstations,OU=Desktops,OU=Computers,OU=UK,DC=XXX,DC=XXXXXX,DC=net"
#Move UK Machine Object
Move-ADObject -Identity "CN=$Name,OU=Windows 7 Prod Workstations,OU=Desktops,OU=Computers,OU=UK,DC=XXX,DC=XXXXXX,DC=net" -TargetPath "OU=Disabled Computer Accounts,OU=Computers,OU=UK,DC=XXX,DC=XXXXXX,DC=net"
----
So you can see what it does, deletes it from SCCM then disables it in AD and moves it to the disabled machine OU.
Currently I've a line for each Prod Workstation OU, but obviously we've got our testing ones, other bits and pieces etc. So save me having to enter a line for each specific OU is there a way I can just tell it to search from the root of the domain?
TIA
Jake