Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Get a user's Home Directory with Powershell

$
0
0

Ok,

I need to get the HomeDirectory of a user and copy it to another user. Problem is I can't get JUST the home drive. Can anyone help.

Here is my code (or a sampling of a larger script):

$oldID = "WSTG0001"
$newID = "WSTG0006"

$oldHome = get-aduser -LDAPFilter "(sAMAccountName=$oldID)" -Properties homeDirectory | Select-Object -Property homeDirectory

New-ADUser -Path "OU=AppServices,OU=Resources,DC=DOM,DC=ROOT,DC=DOM,DC=ORG" -UserPrincipalName $newID -Name $newID -SamAccountName $newID -DisplayName $newID -GivenName $newID -AccountPassword (ConvertTo-SecureString -AsPlainText "dmsteam" -Force) -ScriptPath msklogon -HomeDrive "G" -HomeDirectory $oldHome -Enabled $True

The problem is that $oldHome keeps getting set to @{homeDirectory=\\SERVER\home}

I just want it to be "\\SERVER\home"

Can anyone help? Thanks!



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>