Cleaned up warnings in UserProfileBackup
This commit is contained in:
parent
b02b46baa3
commit
e41c8897dd
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if($Computer -eq $null){
|
if($null -eq $Computer){
|
||||||
$Computer = Read-Host -Prompt 'Enter computer name: '
|
$Computer = Read-Host -Prompt 'Enter computer name: '
|
||||||
}
|
}
|
||||||
$ConfirmUser = $null
|
$ConfirmUser = $null
|
||||||
|
|
@ -42,7 +42,7 @@
|
||||||
$lastUser = Invoke-Command -ComputerName $Computer -SessionOption (New-PSSessionOption -NoMachineProfile) -ScriptBlock {
|
$lastUser = Invoke-Command -ComputerName $Computer -SessionOption (New-PSSessionOption -NoMachineProfile) -ScriptBlock {
|
||||||
Get-ChildItem -Path C:\Users -Directory -Force -Exclude Public,Default,'Default User','All Users' |
|
Get-ChildItem -Path C:\Users -Directory -Force -Exclude Public,Default,'Default User','All Users' |
|
||||||
Sort-Object -Property LastWriteTime -Descending | Select-Object -First 3 -ExpandProperty Name }
|
Sort-Object -Property LastWriteTime -Descending | Select-Object -First 3 -ExpandProperty Name }
|
||||||
if($lastUser -eq $null){
|
if($null -eq $lastUser){
|
||||||
Write-warning "PC unreachable or no profiles to back up"
|
Write-warning "PC unreachable or no profiles to back up"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
Write-Host "Latest Users: $lastUser"
|
Write-Host "Latest Users: $lastUser"
|
||||||
|
|
||||||
#Asks user to pick which profile to backup
|
#Asks user to pick which profile to backup
|
||||||
while( $ConfirmUser -eq $null ){
|
while($null -eq $ConfirmUser){
|
||||||
$User = Read-Host -Prompt 'Choose user to backup'
|
$User = Read-Host -Prompt 'Choose user to backup'
|
||||||
|
|
||||||
if( -not ( Test-Path -Path "\\$Computer\c$\Users\$User" -PathType Container ) ){
|
if( -not ( Test-Path -Path "\\$Computer\c$\Users\$User" -PathType Container ) ){
|
||||||
|
|
@ -66,13 +66,6 @@
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
<#
|
|
||||||
Write-Host "Scanning user profile..."
|
|
||||||
$profileSize = scan-dir "\\$Computer\c$\Users\$User"
|
|
||||||
|
|
||||||
$sizeout = "{1} profile is {0:n3}GB" -f $profileSize,$user
|
|
||||||
Write-Host $sizeout
|
|
||||||
#>
|
|
||||||
|
|
||||||
$ConfirmUser = Read-Host -Prompt "Copy profile? (y/n) or Restore profile (r)"
|
$ConfirmUser = Read-Host -Prompt "Copy profile? (y/n) or Restore profile (r)"
|
||||||
|
|
||||||
|
|
@ -333,14 +326,3 @@
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}#End Function
|
}#End Function
|
||||||
|
|
||||||
#Helper Function
|
|
||||||
function scan-dir($Path) {
|
|
||||||
if ( (Test-Path $Path) -and (Get-Item $Path).PSIsContainer ){
|
|
||||||
$DirectorySize = (Get-ChildItem -Path $path -File -Recurse -Force -ErrorAction SilentlyContinue |
|
|
||||||
Measure-Object -Property Length -Sum).Sum / 1GB
|
|
||||||
|
|
||||||
Return $DirectorySize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue