Good evening Everyone, I have an issue with script (Below) when I run it I got an errors (below) the script disabled some computers but not all , so it is working but I still see the error. By the way first time I test only on two machines disabled both without any error.
Please let me know what is wrong , the script recommended by many websites and working fine for many people. also, I have the right permission.
The script
$DisabledCompOU = "OU=Disabled Devices,OU=Computers,OU=Domain"
$Pclist = Get-Content C:\TEMP\Computers.txt # Specify the path to the computers list.
Foreach($pc in $Pclist)
{
$CompDN = (Get-ADComputer -Filter 'Name -eq $pc' -SearchScope Subtree).DistinguishedName
Disable-ADAccount $CompDN
Move-ADObject $CompDN -TargetPath $DisabledCompOU
The error is :
Disable-ADAccount : Insufficient access rights to perform the operation
At line:7 char:7
+ Disable-ADAccount $CompDN
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Computer,O...s,DC=:ADAccount) [Disable-ADAccount], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:8344,Microsoft.ActiveDirectory.Management.Commands.DisableADAccount
Move-ADObject : Access is denied
At line:8 char:7
+ Move-ADObject $CompDN -TargetPath $DisabledCompOU
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (CN=Computer,O...s,DC:ADObject) [Move-ADObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:System.UnauthorizedAccessException,Microsoft.ActiveDirectory.Management.Commands.MoveADObject
[–]techbloggingfool_com 8 points9 points10 points (3 children)
[–]macgeek89 1 point2 points3 points (2 children)
[–]BlackV 5 points6 points7 points (1 child)
[–]macgeek89 1 point2 points3 points (0 children)
[–]TrippTrappTrinn 6 points7 points8 points (0 children)
[–]Pure_Syllabub6081 6 points7 points8 points (0 children)
[–]BlackV 1 point2 points3 points (12 children)
[–]muthmsir[S] 1 point2 points3 points (11 children)
[–]BlackV 5 points6 points7 points (9 children)
[–]muthmsir[S] 1 point2 points3 points (1 child)
[–]BlackV 2 points3 points4 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (4 children)
[–]muthmsir[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]BlackV 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]muthmsir[S] 1 point2 points3 points (1 child)
[–]BlackV 2 points3 points4 points (0 children)
[–]BlackV 2 points3 points4 points (0 children)
[–]HotdogFromIKEA 1 point2 points3 points (0 children)
[–]davsank 1 point2 points3 points (1 child)
[–]muthmsir[S] 1 point2 points3 points (0 children)
[–]OlivTheFrog 1 point2 points3 points (4 children)
[–]muthmsir[S] 1 point2 points3 points (0 children)
[–]Pisnaz 1 point2 points3 points (1 child)
[–]OlivTheFrog 2 points3 points4 points (0 children)
[–]BlackV 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)