Correction, now the $_.SamAccountName is not added to the HomeDirectory suggestions!
On Wed, Aug 5, 2015 at 9:21 AM, Todd Lemmiksoo <[email protected]> wrote: > I got the script working, needed to change the order of the OU's. Now the > "WhatIf" does not show the full extent of the Set-ADUser command. > > On Tue, Aug 4, 2015 at 4:48 PM, Emin <[email protected]> wrote: > >> No, it can't be the space in 'Information Technology'. I've got it >> working in my env. where I've multiple spaces in the OU names. >> >> What about? >> >> Get-ADUser -ResultSetSize $null -Filter * -SearchBase $targetOU" | >> Foreach-Object { >> $_ | Set-ADuser -HomeDrive "K:" -HomeDirectory >> "\\XXXXXXXXXX\UserData\$($_.SamAccountName)" -WhatIf >> } >> >> >> On Tue, Aug 4, 2015 at 11:21 PM, Todd Lemmiksoo <[email protected]> >> wrote: >> >>> 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]> >>> wrote: >>> >>>> Seems likely that your $targetOU is invalid, based on the error. >>>> >>>> >>>> >>>> *From:* [email protected] [mailto: >>>> [email protected]] *On Behalf Of *Todd Lemmiksoo >>>> *Sent:* Tuesday, August 4, 2015 4:30 PM >>>> *To:* [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)" -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 >>> >> >> > > > -- > T. Todd Lemmiksoo > -- T. Todd Lemmiksoo
