Look at the distinguishedname property of the OU in ADUC. From: [email protected] [mailto:[email protected]] On Behalf Of Todd Lemmiksoo Sent: Tuesday, August 4, 2015 5:21 PM To: [email protected] Subject: Re: [NTSysADM] powershell help
OK, I pulled the OU chain right out of AD. Can it be the space in Information Technology. On Tue, Aug 4, 2015 at 3:47 PM, Michael B. Smith <[email protected]<mailto:[email protected]>> wrote: Seems likely that your $targetOU is invalid, based on the error. From: [email protected]<mailto:[email protected]> [mailto:[email protected]<mailto:[email protected]>] On Behalf Of Todd Lemmiksoo Sent: Tuesday, August 4, 2015 4:30 PM To: [email protected]<mailto:[email protected]> Subject: [NTSysADM] powershell help I am working on a script to change users home directory to a new server/share. Following is my script : #Set AD Home Folder path. Start-Transcript -Path "C:\Temp\transcript.txt" $targetOU = "OU=Accounts,OU=Employees,OU=BR-General,OU=Information Technology,DC=XXXXXX,DC=XXX" Get-ADUser -ResultSetSize $null -Filter * -SearchBase $targetOU" | Foreach-Object { $sam = $_.SamAccountName Set-ADuser -Identity $sam -HomeDrive "K:" -HomeDirectory "\\XXXXXXXXXX\UserData\$($_.SamAccountName)<file:///\\XXXXXXXXXX\UserData\$($_.SamAccountName)>" -WhatIf } Stop-Transcript below is the error I am getting : Get-ADUser : Directory object not found At C:\tools\powershell\Set-AD-Home-folder.ps1:6 char:11 + Get-ADUser <<<< -ResultSetSize $null -Filter * -SearchBase "OU=Accounts,OU=Employees,OU=BR-General,OU=Information Te chnology,DC=XXXXXX,DC=XXX" | Foreach-Object { + CategoryInfo : ObjectNotFound: (:) [Get-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : Directory object not found,Microsoft.ActiveDirectory.Management.Commands.GetADUser Transcript of run is : ********************** Windows PowerShell Transcript Start Start time: 20150804151356 Username : GHSDOMAIN\lemmitt99 Machine : ITP21201 (Microsoft Windows NT 6.1.7601 Service Pack 1) ********************** Transcript started, output file is C:\Temp\transcript.txt Get-ADUser : Directory object not found At C:\tools\powershell\Set-AD-Home-folder.ps1:6 char:11 + Get-ADUser <<<< -ResultSetSize $null -Filter * -SearchBase "OU=Accounts,OU=Employees,OU=BR-General,OU=Information Te chnology,DC=XXXXXX,DC=XXX" | Foreach-Object { + CategoryInfo : ObjectNotFound: (:) [Get-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : Directory object not found,Microsoft.ActiveDirectory.Management.Commands.GetADUser ********************** Windows PowerShell Transcript End End time: 20150804151357 ********************** I am just not seeing it. -- T. Todd Lemmiksoo -- T. Todd Lemmiksoo
