Make the change I suggested below.
From: [email protected] [mailto:[email protected]] On
Behalf Of Todd Lemmiksoo
Sent: Wednesday, August 5, 2015 2:18 PM
To: [email protected]
Subject: Re: [NTSysADM] powershell help
OK I have removed the Get-ADUser and code'ed it to hit one user.
#
$sam = "CN=Crowden\, Timothy A,OU=Policy
Free,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net"
Set-ADuser -Identity $sam -HomeDrive "K:" -HomeDirectory
"\\ghsmsdfsfs1\UserData\$($_.SAMAccountName)<file:///\\ghsmsdfsfs1\UserData\$($_.SAMAccountName)>"
#-WhatIf
#}
The result value for HomeDirectory after the set is
\\ghsmsdfsfs1\UserData\<file:///\\ghsmsdfsfs1\UserData\>
On Wed, Aug 5, 2015 at 12:07 PM, Michael B. Smith
<[email protected]<mailto:[email protected]>> wrote:
I don’t see anything wrong with it. Obviously, WhatIf is not going to make any
changes.
Simplify it a little.
Get-ADUser -ResultSetSize $null -Filter * -SearchBase $targetOU |
Foreach-Object {
$sam = $_.SamAccountName
Set-ADuser -Identity $sam -HomeDrive "K:" -HomeDirectory
"\\ghsmsdfsfs1\UserData\$sam<file:///\\ghsmsdfsfs1\UserData\$sam>" -WhatIf
}
From: [email protected]<mailto:[email protected]>
[mailto:[email protected]<mailto:[email protected]>]
On Behalf Of Todd Lemmiksoo
Sent: Wednesday, August 5, 2015 12:33 PM
To: [email protected]<mailto:[email protected]>
Subject: Re: [NTSysADM] powershell help
Import-Module ActiveDirectory
Start-Transcript -Path "C:\Temp\transcript.txt"
$targetOU = "OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net"
Get-ADUser -ResultSetSize $null -Filter * -SearchBase $targetOU |
Foreach-Object {
$sam = $_.SamAccountName
Set-ADuser -Identity $sam -HomeDrive "K:" -HomeDirectory
"\\ghsmsdfsfs1\UserData\$($_.SamAccountName)<file:///\\ghsmsdfsfs1\UserData\$($_.SamAccountName)>"
-WhatIf
}
Stop-Transcript
Transcript started, output file is C:\Temp\transcript.txt
What if: Performing operation "Set" on Target "CN=LeJeune\,
Jennifer,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Hudson\, Chris,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Cangelosi\,
Toni,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Schexnayder\, Mark
L,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Baum\, Kevin,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Qasem\, Jamil
S,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Hudson\, Jennifer
L,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Test Office365,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Albert\, Karen,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Woods\,
Brandon,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Selvage\, John,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Gibson\, Susan,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Jackson\,
Copeland,OU=Information
Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net".
What if: Performing operation "Set" on Target "CN=Shadeed\,
Jennifer,OU=Information Technology,OU=BR-
The home directory value is
\\servername\UserData\<file:///\\servername\UserData\>
On Wed, Aug 5, 2015 at 10:36 AM, Michael B. Smith
<[email protected]<mailto:[email protected]>> wrote:
Show us the current command and the transcript please.
From: [email protected]<mailto:[email protected]>
[mailto:[email protected]<mailto:[email protected]>]
On Behalf Of Todd Lemmiksoo
Sent: Wednesday, August 5, 2015 11:31 AM
To: [email protected]<mailto:[email protected]>
Subject: Re: [NTSysADM] powershell help
Correction, now the $_.SamAccountName is not added to the HomeDirectory
suggestions!
On Wed, Aug 5, 2015 at 9:21 AM, Todd Lemmiksoo
<[email protected]<mailto:[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]<mailto:[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)<file:///\\XXXXXXXXXX\UserData\$($_.SamAccountName)>"
-WhatIf
}
On Tue, Aug 4, 2015 at 11:21 PM, Todd Lemmiksoo
<[email protected]<mailto:[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]<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
--
T. Todd Lemmiksoo
--
T. Todd Lemmiksoo
--
T. Todd Lemmiksoo
--
T. Todd Lemmiksoo