Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Error moving my own PC

$
0
0

I have this code that you guys helped me right.

$computers = (get-ItemProperty hklm:\SOFTWARE\Microsoft\MPSD\OSD).OSDComputerName 

$GetOU = (get-ItemProperty hklm:\SOFTWARE\Microsoft\MPSD\OSD).OSDDomainOUName

$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()

$root = $dom.GetDirectoryEntry()

foreach($computer in $computers){

$search = [System.DirectoryServices.DirectorySearcher]$root

$search.Filter = "(cn=$computer)"

$result = $search.FindOne()

$computerToMove = [ADSI]$result.path

$computerToMove.psbase.Moveto([ADSI]"LDAP://$GetOU")}

 

This works when run from within our CM2012 OS task sequence.   But if I run this code on my local workstation I get an error.

 

Exception calling "MoveTo" with "1" argument(s): "Access is denied.

"

At C:\Dropbox\Scripts\PowerShell\Testing\testing tools.ps1:38 char:1

+ $computerToMove.psbase.Moveto([ADSI]"LDAP://$GetOU")}

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException

 

But what is odd is if, on my same workstation, I change the machine value in $computers = (get-ItemProperty hklm:\SOFTWARE\Microsoft\MPSD\OSD).OSDComputerName to a remote machine then it Does work.  

 

How come?

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles