Skip to content

Instantly share code, notes, and snippets.

@nshores
Last active February 8, 2020 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshores/8ffac6094fe533ff8a044baa048473df to your computer and use it in GitHub Desktop.
Save nshores/8ffac6094fe533ff8a044baa048473df to your computer and use it in GitHub Desktop.
#### EDIT ME
$newprofilepath = "\\adcfs01\profiledisks\"
$skip = "admin","administrator","ontimetech","adc","old","temp","automate","public","NerdioAdministrator@ADC.local","nerdioadmin","ontimetech.ADC"
#### Don't edit me
$ENV:PATH=”$ENV:PATH;\\Pool-A000005.adc.local\c$\Program Files\FSLogix\Apps”
$oldprofiles = gci c:\users | Sort-Object LastWriteTime -Descending | select -expand fullname -First 2
# foreach old profile
foreach ($old in $oldprofiles) {
$sam = ($old | split-path -leaf)
$sid = (New-Object System.Security.Principal.NTAccount($sam)).translate([System.Security.Principal.SecurityIdentifier]).Value
if ($skip -contains $sam){
write-host "Skipping $sam, on block list"
continue
}
# set the nfolder path to \\newprofilepath\username_sid
$nfolder = ($newprofilepath + $sam)
#write-host "New Folder: $nfolder"
# if $nfolder doesn't exist - create it with permissions
if (!(test-path $nfolder)) {New-Item -Path $nfolder -ItemType directory | Out-Null}
& icacls $nfolder /setowner "$env:userdomain\$sam" /T /C
& icacls $nfolder /grant $env:userdomain\$sam`:`(OI`)`(CI`)F /T
# sets vhd to \\nfolderpath\profile_username.vhdx (you can make vhd or vhdx here)
$vhd = $nfolder + "\$sid" + "_$sam\" + ("Profile_"+$sam+".vhd")
$vhdpath = $nfolder + "\$sid" + "_$sam\"
#make vhd dir
if (!(test-path $vhdpath)) {New-Item -Path $vhdpath -ItemType directory | Out-Null}
#write-host "VHD Path: $vhd"
write-host "Copying $sam to ADCFS01"
frx.exe copy-profile -filename $vhd -username $sam -verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment