rdiff-backup-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[rdiff-backup-users] Windows: backing up files the administrator cant re


From: don hess
Subject: [rdiff-backup-users] Windows: backing up files the administrator cant read
Date: Fri, 18 Jun 2010 17:14:36 -0400

The only thing I found to work was SubInACL.  Make sure that you have the 
5.2.3790.1180 version because the earlier versions are broken and it must be 
run on a 32 bit environment.  This means on 64 bit windows, run it in the 32 
bit Powershell.  This will allow you to take ownership of the file and change 
permissions.  Here is a Powershell script I wrote to help copy some really 
messy directories.


#==============================================================================================
# NAME:    Copy-DirWithPerms.ps1
# AUTHOR:   Don Hess
# DATE:    2010-04-08
# REV:      1.0.0
# COMMENT:  
#
# REVISION:
# 1.0.0      Release
#
# TODO: 
# SubinACL needs to have the output log file changed so that when you play it 
back, the perms
# are applied to the destination directory
# Simplify and compartmentalize so you can run robocopy or subinacl.
# More switches to allow subinacl to do backup and restore one directory or 
recursively.
#==============================================================================================

param   ( [string] $s       = "NA"
      , [string] $d       = 
"NA"   
      , [switch] $perms    = 
[switch]::$false
      , [switch] $rc       = 
[switch]::$false
      , [switch] $f       = 
[switch]::$false
      , [switch] $h       = 
[switch]::$false)   
      

[string] $strScriptName   = 'Copy-DirWithPerms.ps1';
[string] $script:datetimecolon   = Get-Date -uformat 
"%Y-%m-%d %I:%M:%S %p  TZ(%Z)";   # YYYY-MM-DD 
HH-MM-SS AM/PM  note the Powershell Get-Help Get-Date -full has the wrong 
letter abreviations to get the date we want, this will work instead
[string] $script:datetimeunder = Get-Date -uformat "%Y-%m-%d 
%I_%M_%S %p";   # YYYY-MM-DD HH-MM-SS AM/PM  note the Powershell 
Get-Help Get-Date -full has the wrong letter abreviations to get the date we 
want, this will work instead
[string] $script:cname    = ( Get-Content 
env:computername );
[string] $script:strUserPrincipalName = $env:USERNAME + "@" + 
$env:USERDNSDOMAIN;   # Get current user principal name

# Turn both switches on by default if nothing is specified.
if ( ($perms -eq $false) -and ($rc -eq $false) )
{   $perms = $true;  $rc = $true; }

# -h  help output
function helpme()
{   
     
     
     Write-Host "";
     Write-Host "     Copy a directory to a 
destination with all permissions intact.";
     Write-Host "";
     Write-Host "     Usage:";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp;$strScriptName -s <string> 
-d <string> &#91;-rc&#93; &#91;-h&#93;";
&nbsp; &nbsp;&nbsp; Write-Host "";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp;Switches&#58;";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; -s&nbsp; &nbsp; &nbsp; 
&nbsp;Source directory.&nbsp; Required";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; -d&nbsp; &nbsp; &nbsp; 
&nbsp;Destination directory.&nbsp; Required";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; -perms&nbsp; &nbsp;Run 
permission fix only, take owership and full control via user ";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp;running the script to make sure everything can be copied.";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; -rc&nbsp; &nbsp; &nbsp; 
Run robocopy only";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; -f&nbsp; &nbsp; &nbsp; 
&nbsp;Force run.&nbsp; Used with -rc for the second run when the destination";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp;directory is already present.";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; -h&nbsp; &nbsp; &nbsp; 
&nbsp;This Help.";
&nbsp; &nbsp;&nbsp; Write-Host "";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp;Examples&#58;";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; Copy-DirWithPerms.ps1 -s 
`"\\server\d$\dir1`" -d `"\\server\e$\dir2`" ";
&nbsp; &nbsp;&nbsp; Write-Host "";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; Do not run subinACL, run 
just robocopy";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; Copy-DirWithPerms.ps1 -s 
`"\\server\share1`" -d `"\\server\e$\dir2`" -rc";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; &nbsp;";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; Run just subinACL to fix 
permissions";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; Copy-DirWithPerms.ps1 -s 
`"\\server\share1`" -perms";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; &nbsp;";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp;Notes&#58;";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp;The user running this 
script must be able to take ownership of directories";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; &nbsp; and files.&nbsp; 
This applies for the -perms and -rc switches and is usually for";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; &nbsp; a domain admin.";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp;The destination directory 
sharing is not set up, you must do that manually";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp;Robocopy will create a 
missing destination directory when using -rc but will ";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; &nbsp; not do the sharing 
permissions.";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp;You can copy network shares 
but the destination should really be specified&nbsp; ";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; &nbsp; to the admin share 
&#40;\\server\d$\dir&#41; instead of the network share to ";
&nbsp; &nbsp;&nbsp; Write-Host "&nbsp; &nbsp; &nbsp; &nbsp; eliminate any 
potential permission issues. ";
&nbsp; &nbsp;&nbsp; 

&#125;

if &#40; $h.isPresent &#41; &#123; helpme; Return;&#125;

&#91;string&#93; $script&#58;log = "NA"
# Set output switch "$l" so the funcOutputResult funtion work correctly
if &#40; $log -ne "NA" &#41;
&#123; &#91;switch&#93; $script&#58;l = $true; &#125;
else
&#123; &#91;switch&#93; $script&#58;l = $false; &#125;


##### Check logging capability #####
# Check if path is something other than ending in a file.
if &#40; $l.isPresent -and &#40;-not &#40;Test-Path -path "$log" -pathType 
Leaf&#41;&#41; &#41;&nbsp; 
&#123; 
&nbsp; &nbsp;$null = New-Item -Path "$log" -ItemType file -ErrorVariable $evar 
-ErrorAction SilentlyContinue
&nbsp; &nbsp;if &#40; $? -eq $false &#41; &#123; Write-Host "Cannot write to 
log file location&#58; `'$log`' " -Backgroundcolor red; Return 3; &#125; 
&#125;
# Check if path ends in a file
if &#40; $l.isPresent -and &#40;Test-Path -path "$log" -pathType Leaf&#41; &#41;
&#123;
&nbsp; &nbsp;# test of permissions on log file
&nbsp; &nbsp;Out-File -Filepath "$log" -Inputobject " " -Append -ErrorVariable 
$evar -ErrorAction SilentlyContinue
&nbsp; &nbsp;# if log file test of write fails, yell and bail out.
&nbsp; &nbsp;if &#40; $? -eq $false &#41; &#123; Write-Host "&nbsp; Cannot 
write to log file location&#58; `'$log`' " -Backgroundcolor red; Return 3; 
&#125;
&#125;


# This will output text to the screen or file 
function funcOutputResult &#40; &#91;switch&#93; $d, &#91;switch&#93; $ft, 
&#91;switch&#93; $fl, &#91;switch&#93; $all, &#91;object&#93; $textobj, 
&#91;string&#93; $strBColor, &#91;string&#93; $strFColor &#41;
&#123;
&nbsp; &nbsp;# -textobj can be a string object, datetime, array, or may other 
objects that 
&nbsp; &nbsp;#&nbsp; &nbsp; need to looped through to get their output.
&nbsp; &nbsp;# -d will display to screen
&nbsp; &nbsp;# -l will log to file.&nbsp; This is a script wide switch set 
outside this function.&nbsp; 
&nbsp; &nbsp;#&nbsp; &nbsp; You need to make sure the $log file location is 
specified as a param.
&nbsp; &nbsp;# -fl is Format-List
&nbsp; &nbsp;# -ft is Format-Table
&nbsp; &nbsp;# -all is to show all attibutes of the Format-List or Format-Table
&nbsp; &nbsp;# -strBColor is background color
&nbsp; &nbsp;# -strFColor is forground color
&nbsp; &nbsp;
&nbsp; &nbsp;# -fl and -ft overrides -strBColor and -strFColor
&nbsp; &nbsp;
&nbsp; &nbsp;# check if log file path has been passed to us.
&nbsp; &nbsp;if &#40; $l.IsPresent -and $log -eq "NA" &#41; 
&nbsp; &nbsp;&#123; Write-Host "Log file doesn't exist" -BackgroundColor Red; 
Return; &#125;
&nbsp; &nbsp;
&nbsp; &nbsp;if &#40; $ft.IsPresent -or $fl.IsPresent &#41;
&nbsp; &nbsp;&#123; 
&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $l.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# if display is present output that next 
and when done do the logging&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $d.IsPresent &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $fl.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; if &#40; 
$all.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; $_ | Format-List * | Out-Host; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; else 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; $_ | Format-List | Out-Host; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $ft.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; if &#40; 
$all.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; $_ | Format-Table * | Out-Host; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; else 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; $_ | Format-Table | Out-Host; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125; # Done writing to display
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Now write to log file
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $fl.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;# Write list formated 
output to file
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $all.IsPresent 
&#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;$textobj 
| ForEach-Object &#123; $_ | Format-List * | Out-File -Filepath "$log" -Append 
-ErrorVariable $evar -ErrorAction SilentlyContinue; &#125;;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# check if 
write failed
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $? 
-eq $false &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; &nbsp; 
&nbsp;$textout = "Failed to write to log file&#58; $log." ;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;Write-Host $textout -BackgroundColor Red;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else # -all is not present
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$textobj | 
ForEach-Object &#123; $_ | Format-List | Out-File -Filepath "$log" -Append 
-ErrorVariable $evar -ErrorAction SilentlyContinue; &#125;;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# check if 
write failed
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $? 
-eq $false &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; &nbsp; 
&nbsp;$textout = "Failed to write to log file&#58; $log." ;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;Write-Host $textout -BackgroundColor Red;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $ft.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;# Write list formated 
output to file
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $all.IsPresent 
&#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;$textobj 
| ForEach-Object &#123; $_ | Format-Table * | Out-File -Filepath "$log" -Append 
-ErrorVariable $evar -ErrorAction SilentlyContinue; &#125;;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# check if 
write failed
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $? 
-eq $false &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; &nbsp; 
&nbsp;$textout = "Failed to write to log file&#58; $log." ;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;Write-Host $textout -BackgroundColor Red;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else # -all is not present
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$textobj | 
ForEach-Object &#123; $_ | Format-Table | Out-File -Filepath "$log" -Append 
-ErrorVariable $evar -ErrorAction SilentlyContinue; &#125;;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# check if 
write failed
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $? 
-eq $false &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; &nbsp; 
&nbsp;$textout = "Failed to write to log file&#58; $log." ;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;Write-Host $textout -BackgroundColor Red;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&#125; # End logging of -fl and -ft
&nbsp; &nbsp;&nbsp; &nbsp;else # No logging
&nbsp; &nbsp;&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $d.IsPresent &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $fl.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; if &#40; 
$all.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; $_ | Format-List * | Out-Host; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; else 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; $_ | Format-List | Out-Host; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $ft.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; if &#40; 
$all.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; $_ | Format-Table * | Out-Host; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; else 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; $_ | Format-Table | Out-Host; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125; # Done writing to display
&nbsp; &nbsp;&nbsp; &nbsp;&#125; # End just display of -fl and -ft
&nbsp; &nbsp;&#125; # End -fl and -ft 
&nbsp; &nbsp;
&nbsp; &nbsp;else # $ft and $fl are not present 
&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $l.IsPresent &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# if display is present output that next 
and when done do the logging&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $d.IsPresent &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $strBColor -ne "" 
&#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; 
$strFColor -ne "" &#41; # bg=y, fg=y
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; Write-Host $_ -BackgroundColor $strBColor 
-ForegroundColor $strFColor; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else # bg=y, 
fg=n
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; Write-Host $_ -BackgroundColor $strBColor; 
&#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; 
$strFColor -ne "" &#41; # bg=n, fg=y
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; Write-Host $_ -ForegroundColor $strFColor; 
&#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else # bg=n, 
fg=n
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; Write-Host $_; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Now write to log file
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$textobj | ForEach-Object &#123; $_ | 
Out-File -Filepath "$log" -Append -ErrorVariable $evar -ErrorAction 
SilentlyContinue; &#125;;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# check if write failed
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $? -eq $false &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; &nbsp; &nbsp;$textout = "Failed 
to write to log file&#58; $log." ;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Write-Host $textout 
-BackgroundColor Red;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&#125; # End plain logging
&nbsp; &nbsp;&nbsp; &nbsp;else # No logging
&nbsp; &nbsp;&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $d.IsPresent &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $strBColor -ne "" 
&#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; 
$strFColor -ne "" &#41; # bg=y, fg=y
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; Write-Host $_ -BackgroundColor $strBColor 
-ForegroundColor $strFColor; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else # bg=y, 
fg=n
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; Write-Host $_ -BackgroundColor $strBColor; 
&#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; 
$strFColor -ne "" &#41; # bg=n, fg=y
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; Write-Host $_ -ForegroundColor $strFColor; 
&#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else # bg=n, 
fg=n
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; 
$textobj | ForEach-Object &#123; Write-Host $_; &#125;; &#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&#125; # End of logging for "$ft and $fl are not 
present" 
&nbsp; &nbsp;&#125; # End $ft and $fl are not present 
&#125;


function funcSanityChecks&#40;&#41;
&#123;
&nbsp; &nbsp;# Check for multiple issues with inputs
&nbsp; &nbsp;#
&nbsp; &nbsp;# Inputs&#58; &nbsp; &nbsp;Just the params passed in script 
execution
&nbsp; &nbsp;#
&nbsp; &nbsp;# Returns&#58;&nbsp; &nbsp;1 if something is wrong, 0 if 
everything is OK.

&nbsp; &nbsp;#&nbsp; &nbsp;what version of subinacl is needed?&nbsp; 
&nbsp;subinacl version 5.2.3790.1180
&nbsp; &nbsp;#&nbsp; &nbsp;what version of robocopy is needed? robocopy Version 
XP010
&nbsp; &nbsp;
&nbsp; &nbsp;#&nbsp; &nbsp;need to be in a 32 bit environment.&nbsp; 
$env&#58;PROCESSOR_ARCHITECTURE&nbsp; =&nbsp; "x86" if we are on 32 bit, else 
is is AMD64
&nbsp; &nbsp;if &#40; &#40;$env&#58;PROCESSOR_ARCHITECTURE -ne "x86"&#41; -and 
&#40;$perms.isPresent&#41;&#41;
&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;$textobj = "&nbsp; This script must be run in a 32 
bit environment because of the subinacl program.";
&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" -strFColor 
"Red";
&nbsp; &nbsp;&nbsp; &nbsp;Return 1;
&nbsp; &nbsp;&#125;
&nbsp; &nbsp;
&nbsp; &nbsp;#$subvercheck = &#40;&#40; subinacl \? &#41; | Where-Object &#123; 
$_ -cmatch "SubInAcl version 5.2.3790.1180"; &#125; &#41;;
&nbsp; &nbsp;#if &#40;&nbsp; &#41;
&nbsp; &nbsp;#&#123;
&nbsp; &nbsp;#&nbsp; &nbsp;$textobj = "&nbsp; This script must be run in a 32 
bit environment because of the subinacl program.";
&nbsp; &nbsp;#&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" -strFColor 
"Red";
&nbsp; &nbsp;#&nbsp; &nbsp;Return 1;
&nbsp; &nbsp;#&#125;
&nbsp; &nbsp;
&nbsp; &nbsp;if &#40; &#40;Test-Path -PathType Container "$strSource"&#41; -and 
&#40;$perms.isPresent -or $rc.isPresent&#41; &#41;
&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;Out-Null; # Everything is fine.
&nbsp; &nbsp;&#125;
&nbsp; &nbsp;else # Doesn't exist
&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;$textobj = "&nbsp; Please input the source path 
directory";
&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" -strFColor 
"Red";
&nbsp; &nbsp;&nbsp; &nbsp;Return 1;
&nbsp; &nbsp;&#125;

&nbsp; &nbsp;if&nbsp; &#40; $rc.isPresent &#41;
&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;# Check if parent directory exits
&nbsp; &nbsp;&nbsp; &nbsp;&#91;string&#93; $f1 = Split-Path&nbsp; 
"$strDest";&nbsp; &nbsp;&nbsp; &nbsp;# Gives us the parent
&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;if &#40; Test-Path -PathType Container "$f1" &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Out-Null; # Everything is fine.
&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;else
&nbsp; &nbsp;&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$textobj = "&nbsp; The parent directory 
does not exist for&#58; `'$strDest`' ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" 
-strFColor "Red";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Return 1;
&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;# Check if destination directory already exists, and 
user is not looking to run robocopy only
&nbsp; &nbsp;&nbsp; &nbsp;# Robocopy will create the directory if it is 
missing, this is to prevent overwrite of existing files.
&nbsp; &nbsp;&nbsp; &nbsp;if &#40; &#40;Test-Path -PathType Container 
"$strDest"&#41; -and &#40;$f -eq $false&#41; &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$textobj = "&nbsp; The destination 
directory `'$strDest`' `n&nbsp; is already present.&nbsp; This script does not 
allow merging of directories. ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" 
-strFColor "Red";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$textobj = "&nbsp; Please rename the 
existing destination directory and try again.&nbsp; ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" 
-strFColor "Red";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Return 1;
&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&#125;

&nbsp; &nbsp;Return 0;
&#125; # End funcSanityChecks



############################### MAIN ###############################
####################################################################

# Note that file logging is handled by the funcOutputResult function 
automatically
$textobj = "------------------ $datetimecolon ------------------";
funcOutputResult -d -textobj "$textobj";

$textobj = "&nbsp; Computer name&#58; $cname";
funcOutputResult -d -textobj "$textobj";

# Set to more readable variables
&#91;string&#93; $script&#58;strSource = $s;
&#91;string&#93; $script&#58;strDest&nbsp; &nbsp;= $d;

&#91;array&#93; $arrSanityResult = funcSanityChecks;

switch &#40; $arrSanityResult&#91;0&#93; &#41;
&#123;
&nbsp; &nbsp;0 &#123;
&nbsp; &nbsp;&nbsp; &nbsp;# Everything is fine
&nbsp; &nbsp;&nbsp; &nbsp;Out-Null;
&nbsp; &nbsp;&#125;
&nbsp; &nbsp;1 &#123; 
&nbsp; &nbsp;&nbsp; &nbsp;$textobj = &#40; "&nbsp; Error in funcSanityChecks 
function." &#41;;
&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" -strFColor 
"Red";
&nbsp; &nbsp;&nbsp; &nbsp;Return; 
&nbsp; &nbsp;&#125;
&nbsp; &nbsp;default &#123;
&nbsp; &nbsp;&nbsp; &nbsp;$textobj = &#40; "&nbsp; Weird error `'" + 
$arrSanityResult&#91;0&#93;.tostring&#40;&#41; + "`' was returned from the 
sanity checks." &#41;;
&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" -strFColor 
"Red";
&nbsp; &nbsp;&nbsp; &nbsp;Return;
&nbsp; &nbsp;&#125;
&#125;


if &#40; $perms.isPresent &#41;
&#123;
#&nbsp; &nbsp;# Get permissions of from source directory via subinacl, store to 
log file
#&nbsp; &nbsp;&#91;string&#93; $suboutputlog = "$env&#58;TEMP" + '\permsfile-' 
+ "$datetimeunder" + '.txt';
#&nbsp; &nbsp;&#91;string&#93; $args2 = '/noverbose /outputlog="' + 
$suboutputlog + '" /subdirectories "' + $strSource + '" /display';
#&nbsp; &nbsp;&#91;Diagnostics.Process&#93;&#58;&#58;Start&#40;"subinacl", 
"$args2"&#41;.WaitForExit&#40;&#41;; 
#&nbsp; &nbsp;if &#40; $? &#41; 
#&nbsp; &nbsp;&#123; &nbsp; &nbsp;$textobj = "&nbsp; Subinacl perm backup to 
`'$outputlog`' completed ";
#&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj";
#&nbsp; &nbsp;&#125; 
#&nbsp; &nbsp;else
#&nbsp; &nbsp;&#123;&nbsp; &nbsp;$textobj = "***** Subinacl perm backup to 
`'$outputlog`' FAILED. ***** ";
#&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" -strBColor 
"Red";
#&nbsp; &nbsp;&nbsp; &nbsp;Return 3;
#&nbsp; &nbsp;&#125;
#&nbsp; &nbsp;
#&nbsp; &nbsp;
#&nbsp; &nbsp;# Create destination directory, note that parent dir was checked 
for 
#&nbsp; &nbsp;# and an existing destination directory in funcSanityChecks
#&nbsp; &nbsp;New-Item -ItemType Directory -Path "$strDest" -ErrorAction 
SilentlyContinue | Out-Null;
#&nbsp; &nbsp;if &#40; $? &#41; 
#&nbsp; &nbsp;&#123; &nbsp; &nbsp;$textobj = "&nbsp; Create destination 
`'$strDest`' completed ";
#&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj";
#&nbsp; &nbsp;&#125; 
#&nbsp; &nbsp;else
#&nbsp; &nbsp;&#123;&nbsp; &nbsp;$textobj = "***** Create destination 
`'$strDest`' FAILED. ***** ";
#&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" -strBColor 
"Red";
#&nbsp; &nbsp;&nbsp; &nbsp;Return 3;
#&nbsp; &nbsp;&#125;
#&nbsp; &nbsp;
#&nbsp; &nbsp;
#&nbsp; &nbsp;# Set permissions of to destination directory via subinacl
#&nbsp; &nbsp;&#91;string&#93; $args2 = '/playfile "' + $suboutputlog + '"';
#&nbsp; &nbsp;&#91;Diagnostics.Process&#93;&#58;&#58;Start&#40;"subinacl", 
"$args2"&#41;.WaitForExit&#40;&#41;; 
#&nbsp; &nbsp;if &#40; $? &#41; 
#&nbsp; &nbsp;&#123; &nbsp; &nbsp;$textobj = "&nbsp; Subinacl perm restore from 
`'$outputlog`' completed ";
#&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj";
#&nbsp; &nbsp;&#125; 
#&nbsp; &nbsp;else
#&nbsp; &nbsp;&#123;&nbsp; &nbsp;$textobj = "***** Subinacl perm restore from 
`'$outputlog`' FAILED. ***** ";
#&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" -strBColor 
"Red";
#&nbsp; &nbsp;&nbsp; &nbsp;Return 3;
#&nbsp; &nbsp;&#125;


&nbsp; &nbsp;function funcTakeOwnershipFullAccess &#40; &#91;string&#93; $path1 
&#41;
&nbsp; &nbsp;&#123;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;# To set ownership on <FolderPath>&#58;
&nbsp; &nbsp;&nbsp; &nbsp;# subinacl /subdirectories <FolderPath> 
/setowner=<DomainName\UserName>
&nbsp; &nbsp;&nbsp; &nbsp;# To set ownership for all the <FolderPath> 
objects&#58;
&nbsp; &nbsp;&nbsp; &nbsp;# subinacl /subdirectories <FolderPath>\*.* 
/setowner=<DomainName\UserName>
&nbsp; &nbsp;&nbsp; &nbsp;&#91;string&#93; $suboutputlog = "$env&#58;TEMP" + 
'\permschange-' + "$datetimeunder" + '.txt';
&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;Get-ChildItem $path1 | ForEach-Object &#123;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$strCurrentFullName = $_.FullName;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $_.psIsContainer -eq $false 
&#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Set the owner to who we 
are so we can get and set permissions as needed later.
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#&#91;string&#93; $args2 = 
'/outputlog="' + $suboutputlog + '" /subdirectories "' + $strCurrentFullName + 
'" /setowner="' + $strUserPrincipalName + '"' ;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#91;string&#93; $args2 = 
'/noverbose /subdirectories "' + $strCurrentFullName + '" /setowner="' + 
$strUserPrincipalName + '"' ;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;&#91;Diagnostics.Process&#93;&#58;&#58;Start&#40;"subinacl", 
"$args2"&#41;.WaitForExit&#40;&#41;; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $? &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; &nbsp; 
&nbsp;$textobj = "&nbsp; Ownership of $strCurrentFullName completed ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;funcOutputResult -d -textobj "$textobj";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;$textobj 
= "***** Ownership of $strCurrentFullName completed ***** ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;funcOutputResult -d -textobj "$textobj" -strBColor "Red";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Return 3;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Allow full access so we 
can copy the file.
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$aclCurrent = Get-Acl -path 
"$strCurrentFullName"
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$Ar = New-Object&nbsp; 
system.security.accesscontrol.filesystemaccessrule&#40;"$strUserPrincipalName","FullControl","Allow"&#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;$aclCurrent.AddAccessRule&#40;$Ar&#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Set-Acl -path 
"$strCurrentFullName" -aclObject $aclCurrent
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $? &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; &nbsp; 
&nbsp;$textobj = "&nbsp; Full control of $strCurrentFullName completed ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;funcOutputResult -d -textobj "$textobj";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;$textobj 
= "***** Full control of $strCurrentFullName completed ***** ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;funcOutputResult -d -textobj "$textobj" -strBColor "Red";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Return 3;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $_.psIsContainer -eq $true &#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Set the owner to who we 
are so we can get and set permissions as needed later.
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#&#91;string&#93; $args2 = 
'/outputlog="' + $suboutputlog + '" /subdirectories "' + $strCurrentFullName + 
'" /setowner="' + $strUserPrincipalName + '"' ;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#91;string&#93; $args2 = 
'/noverbose /subdirectories "' + $strCurrentFullName + '" /setowner="' + 
$strUserPrincipalName + '"' ;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;&#91;Diagnostics.Process&#93;&#58;&#58;Start&#40;"subinacl", 
"$args2"&#41;.WaitForExit&#40;&#41;; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $? &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; &nbsp; 
&nbsp;$textobj = "&nbsp; Ownership of $strCurrentFullName completed ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;funcOutputResult -d -textobj "$textobj";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;$textobj 
= "***** Ownership of $strCurrentFullName completed ***** ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;funcOutputResult -d -textobj "$textobj" -strBColor "Red";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Return 3;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# Allow full access so we 
can copy the file.
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$aclCurrent = Get-Acl -path 
"$strCurrentFullName"
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$Ar = New-Object&nbsp; 
system.security.accesscontrol.filesystemaccessrule&#40;"$strUserPrincipalName","FullControl","Allow"&#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;$aclCurrent.AddAccessRule&#40;$Ar&#41;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Set-Acl -path 
"$strCurrentFullName" -aclObject $aclCurrent
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if &#40; $? &#41; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123; &nbsp; 
&nbsp;$textobj = "&nbsp; Full control of $strCurrentFullName completed ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;funcOutputResult -d -textobj "$textobj";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#123;&nbsp; &nbsp;$textobj 
= "***** Full control of $strCurrentFullName completed ***** ";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; 
&nbsp;funcOutputResult -d -textobj "$textobj" -strBColor "Red";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Return 3;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;# call ourselves to go 
through this directory
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;funcTakeOwnershipFullAccess 
"$strCurrentFullName";
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&#125;

&nbsp; &nbsp;# call our function to get everything started.
&nbsp; &nbsp;funcTakeOwnershipFullAccess "$strSource";

&#125; # End of if &#40; $rc -eq $false &#41;


if &#40; $rc.isPresent &#41;
&#123;
&nbsp; &nbsp;# Run robocopy to copy contents from source to destination with 
all permissions
&nbsp; &nbsp;# Note you need to have the Manage Auditing user right for 
robocopy to work.
&nbsp; &nbsp;&#91;string&#93; $roboutputlog = "$env&#58;TEMP" + '\robocopylog-' 
+ "$datetimeunder" + '.txt';
&nbsp; &nbsp;&#91;string&#93; $args2 = '"' + $strSource + '" ' + '"' + $strDest 
+ '" /V /NP /E /COPYALL /B /IPG&#58;3 /R&#58;10 /W&#58;30 /TEE /LOG&#58;"' + 
$roboutputlog + '"';
&nbsp; &nbsp;&#91;Diagnostics.Process&#93;&#58;&#58;Start&#40;"robocopy", 
"$args2"&#41;.WaitForExit&#40;&#41;; 
&nbsp; &nbsp;if &#40; $? &#41; 
&nbsp; &nbsp;&#123; &nbsp; &nbsp;$textobj = "&nbsp; Robocopy copy from 
`'$strSource`' `n&nbsp; to `'$strDest`' completed ";
&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj";
&nbsp; &nbsp;&#125; 
&nbsp; &nbsp;else
&nbsp; &nbsp;&#123;&nbsp; &nbsp;$textobj = "***** Robocopy copy from 
`'$strSource`' to `'$strDest`' FAILED. ***** ";
&nbsp; &nbsp;&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj" -strBColor 
"Red";
&nbsp; &nbsp;&nbsp; &nbsp;Return 3;
&nbsp; &nbsp;&#125;
&nbsp; &nbsp;&nbsp; &nbsp;# Robocopy switch descriptions&#58;
&nbsp; &nbsp;&nbsp; &nbsp;# /V &nbsp; &nbsp;&nbsp; &nbsp;&#58;&#58; produce 
Verbose output, showing skipped files.
&nbsp; &nbsp;&nbsp; &nbsp;# /NP &nbsp; &nbsp;&nbsp; &nbsp;&#58;&#58; No 
Progress - don't display % copied.
&nbsp; &nbsp;&nbsp; &nbsp;# /E &nbsp; &nbsp;&nbsp; &nbsp;&#58;&#58; copy 
subdirectories, including Empty ones.
&nbsp; &nbsp;&nbsp; &nbsp;# /COPYALL &nbsp; &nbsp;&#58;&#58; COPY ALL file info 
&#40;equivalent to /COPY&#58;DATSOU&#41;.
&nbsp; &nbsp;&nbsp; &nbsp;# /B &nbsp; &nbsp;&nbsp; &nbsp;&#58;&#58; copy files 
in Backup mode.
&nbsp; &nbsp;&nbsp; &nbsp;# /IPG&#58;n &nbsp; &nbsp;&#58;&#58; Inter-Packet Gap 
&#40;ms&#41;, to free bandwidth on slow lines.
&nbsp; &nbsp;&nbsp; &nbsp;# /R&#58;n &nbsp; &nbsp;&nbsp; &nbsp;&#58;&#58; 
number of Retries on failed copies&#58; default 1 million.
&nbsp; &nbsp;&nbsp; &nbsp;# /W&#58;n &nbsp; &nbsp;&nbsp; &nbsp;&#58;&#58; Wait 
time between retries&#58; default is 30 seconds.
&nbsp; &nbsp;&nbsp; &nbsp;# /TEE &nbsp; &nbsp;&nbsp; &nbsp;&#58;&#58; output to 
console window, as well as the log file.
&nbsp; &nbsp;&nbsp; &nbsp;# /LOG&#58;file &#58;&#58; output status to LOG file 
&#40;overwrite existing log&#41;.
&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;# Other useful switches
&nbsp; &nbsp;&nbsp; &nbsp;# Do not use the mirror feature &#40;/MIR&#41;, it 
will delete on the source if you run into problems
&nbsp; &nbsp;&nbsp; &nbsp;# /MON&#58;n &nbsp; &nbsp;&#58;&#58; MONitor source; 
run again when more than n changes seen.
&nbsp; &nbsp;&nbsp; &nbsp;# /MOT&#58;m &nbsp; &nbsp;&#58;&#58; MOnitor source; 
run again in m minutes Time, if changed.
&nbsp; &nbsp;&nbsp; &nbsp;# /LOG+&#58;file &#58;&#58; output status to LOG file 
&#40;append to existing log&#41;.
&nbsp; &nbsp;
&nbsp; &nbsp;
&nbsp; &nbsp;$textobj = "`n&nbsp; You can now rerun robocopy to make sure 
nothing has been changed on the source while you were copying it. `n&nbsp; You 
should check the robocopy log file `'$roboutputlog`' `n&nbsp; for anything that 
your user did not have permission to read.`n&nbsp; You may also manually delete 
the source directory. `n";
&nbsp; &nbsp;funcOutputResult -d -textobj "$textobj";
&#125;




+----------------------------------------------------------------------
|This was sent by address@hidden via Backup Central.
|Forward SPAM to address@hidden
+----------------------------------------------------------------------





reply via email to

[Prev in Thread] Current Thread [Next in Thread]