/build/static/layout/Breadcrumb_cap_w.png

Reapply share settings on migrated home folders

#Backstory: we had a set of home folder shares on a server that we needed to migrate to a new server, DFS allowed us to replicate the content and NTFS #permissions but not the share properties on the folders. wrote the script below to accomplish re-applying the share properties

#####################################################

#applies share permissions to leaf folders that are in username format

#changes ad profile home directory to new location

#folders must end in name that matches the username..

######################################################

$ErrorActionPreference = "Stop"

#get shares in specific folder, i.e. \\server\e$\1,2,3 or whatever it is

Get-ChildItem \\location\offolderstobeshared |

?{ $_.PSIsContainer } | 

Select-Object FullName | 

export-csv -delimiter "`t" -path c:\scripts\SharesQ.txt


#cleanup

get-content c:\scripts\SharesQ.txt |

select-string -pattern '#TYPE Selected.System.IO.DirectoryInfo' -notmatch |

select-string -pattern 'FullName' -notmatch | % {$_ -replace '"', ""} | 

out-file c:\scripts\Shares.txt


#might not need to dump these to files but eh can see whats happening


$Shares = Get-Content c:\scripts\Shares.txt

foreach($share in $Shares) 

{

try{

$client = Split-Path "$share" -leaf

$HideShare = [string]::concat($client,"$")


NET SHARE $HideShare=$share "/GRANT:$client,FULL" 


Get-ADUser -Filter {cn -like "$client"} -ErrorAction Stop

Set-ADuser -Identity $client -HomeDrive "H:" -HomeDirectory "\\NEWSERVER\$hideshare"

}

catch

{

if ($lastexitcode -ne 0) {"$Client" | out-file 'c:\scripts\bad_names.TXT' -Append}

#Collect list of each folder that was unable to be shared due to missing user etc

}

}


Comments

This post is locked
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ