Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#### 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"
# 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
You can’t perform that action at this time.