I am in an IT role and was looking to automate some of our "PC Refresh" process, I am not well versed with powershell scripts. Below is a script I got together to meet our needs. Basically we need these exact folders and at the bottom those files (Just the bookmarks). I'm trying to incorporate the script also pulling those bookmarks as well with the folders. I have been trying different things with various information on this website and others and can't seem to find exactly what I need.
$FoldersToCopy = @(
'Desktop'
'Downloads'
'Favorites'
'Documents'
'Pictures'
'Videos'
'AppData\Roaming\Adobe\Acrobat\DC\Security'
'AppData\Roaming\Microsoft\Office'
'AppData\Roaming\Microsoft\Proof'
'AppData\Roaming\Microsoft\Signature'
'AppData\Roaming\Microsoft\Speech'
'AppData\Roaming\Microsoft\Spelling'
'AppData\Roaming\Microsoft\Stationary'
'AppData\Roaming\Microsoft\Sticky Notes'
'AppData\Roaming\Microsoft\Templates'
'AppData\Roaming\Microsoft\Uproof'
)
$ConfirmComp = $null
$ConfirmUser = $null
while( $ConfirmComp -ne 'y' ){
$Computer = Read-Host -Prompt 'Enter the computer to copy from'
if( -not ( Test-Connection -ComputerName $Computer -Count 2 -Quiet ) ){
Write-Warning "$Computer is not online. Please enter another computer name."
continue
}
$ConfirmComp = Read-Host -Prompt "The entered computer name was:`t$Computer`r`nIs this correct? (y/n)"
}
while( $ConfirmUser -ne 'y' ){
$User = Read-Host -Prompt 'Enter the user profile to copy from'
if( -not ( Test-Path -Path "\\$Computer\c$\Users\$User" -PathType Container ) ){
Write-Warning "$User could not be found on $Computer. Please enter another user profile."
continue
}
$ConfirmUser = Read-Host -Prompt "The entered user profile was:`t$User`r`nIs this correct? (y/n)"
}
$SourceRoot = "\\$Computer\c$\Users\$User"
$DestinationRoot = "C:\Users\$User"
foreach( $Folder in $FoldersToCopy ){
$Source = Join-Path -Path $SourceRoot -ChildPath $Folder
$Destination = Join-Path -Path $DestinationRoot -ChildPath $Folder
if( -not ( Test-Path -Path $Source -PathType Container ) ){
Write-Warning "Could not find path`t$Source"
continue
}
Robocopy.exe $Source $Destination /E /IS /NP /NFL
}
'AppData\Local\Google\Chrome\User Data\Default\Bookmarks'
'AppData\Local\Google\Chrome\User Data\Default\Bookmarks.bak'
'AppData\Local\Microsoft\Edge\User Data\Default\Bookmarks'
'AppData\Local\Microsoft\Edge\User Data\Default\Bookmarks.msbak'
As the main script shows what I'd like to happen. I'll sign into the replacement PC with my admin account and run the script. Put in the PC name and User name then it will pull the folders and files automatically populating the locations with the data (which with just folders works perfectly). Then at that point I'll be done with that section of our process. I know I could add "AppData\Local\Google\Chrome\User Data\Default" and just delete everything except those files (due to possible issues/conflicts management only wants the bookmarks to be copied) Also some files in that folder wont copy on the script if the user is actively using chrome or edge. I feel there is a simple section that can be added I just don't know how to incorporate it.
I appreciate any feedback or material I can look at to better learn Powershell script utilization.
EDIT: I should add the 'AppData\Roaming\Microsoft\Office' section is just for the .ACL files is there a way to only copy those file extensions if they exist as well?