Saturday, June 15, 2019
Robocopy only ACLs from source to target
set source=source
set target=target
robocopy %source% %target% /SECFIX /E /XX /COPY:ASOU /mt:128 /r:0 /w:0 /np /X /V /LOG+:ROBOLOG.TXT
To only copy ACLs from source to Target
Not modifying the data (data will remain intact)
AVOID /SEC :: copy files with SECurity (equivalent to /COPY:DATS). -> INCLUDES D
/COPY:ASOU
/XX :: eXclude eXtra files and directories.
/MT[:n] :: Do multi-threaded copies with n threads (default 8). (must be Win x64 2008 R2 or newerish)
/r:0 /w:0 - wait 0 when error, retry 0 on error
/NP :: No Progress - don't display percentage copied. (fastens the copy in theory)
/X :: report all eXtra files, not just those selected.
/V :: produce Verbose output, showing skipped files.
/LOG+:file :: output status to LOG file (append to existing log). (could also be /UNILOG+:file :: output status to LOG file as UNICODE (append to existing log).
/E :: copy subdirectories, including Empty ones.
/SECFIX :: FIX file SECurity on all files, even skipped files. (enforce matching or equal file -compared source vs target - to be processed)
/COPY:copyflag[s] :: what to COPY for files (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info).
If required add the backup mode (SEbackupPrivilege/SErestorePrivilege)
/B :: copy files in Backup mode.
ALWAYS TEST FIRST
SEE THE RESULTS THEN APPLY WHERE YOU NEED
Labels:
acls,
directories,
files,
robocopy
Friday, July 28, 2017
Powershell List folder content, search by criteria, list files, delete, check existence, report
=========================================
$ErrorActionPreference = "SilentlyContinue";
Stop-Transcript | out-null
$Archivolog = "C:\temp\output-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
$Archivolog2 = "C:\temp\compress-logfiles-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
Start-Transcript -path $Archivolog -append
$criteria = Minidump*.dmp
Write-Host Step Delete MINIDUMP FILEs Start at $(get-date)
$mindump = gci c:\test1 -recurse -Include "$criteria"
if ($mindump -eq $null) {write-host *** No files found to delete ***} else {write-host List of files to delete:; $mindump | % {write-host $_}}
remove-item $mindump -force
$mindump | % {If(test-path $_){ write-host $_";File NOT DELETED"} else {write-host $_";File DELETED"}}
Write-Host Step Delete MINIDUMP FILEs Finished at $(get-date)
Stop-Transcript
$text = [IO.File]::ReadAllText($Archivolog)
New-EventLog –LogName Application –Source "Nakama test"
Write-EventLog –LogName Application –Source "Nakama test" –EntryType Information –EventID 9213 –Message $text
=========================================
$ErrorActionPreference = "SilentlyContinue";
Stop-Transcript | out-null
$Archivolog = "C:\temp\output-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
$Archivolog2 = "C:\temp\compress-logfiles-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
Start-Transcript -path $Archivolog -append
$criteria = Minidump*.dmp
Write-Host Step Delete MINIDUMP FILEs Start at $(get-date)
$mindump = gci c:\test1 -recurse -Include "$criteria"
if ($mindump -eq $null) {write-host *** No files found to delete ***} else {write-host List of files to delete:; $mindump | % {write-host $_}}
remove-item $mindump -force
$mindump | % {If(test-path $_){ write-host $_";File NOT DELETED"} else {write-host $_";File DELETED"}}
Write-Host Step Delete MINIDUMP FILEs Finished at $(get-date)
Stop-Transcript
$text = [IO.File]::ReadAllText($Archivolog)
New-EventLog –LogName Application –Source "Nakama test"
Write-EventLog –LogName Application –Source "Nakama test" –EntryType Information –EventID 9213 –Message $text
=========================================
Wednesday, July 26, 2017
Do something and Log information to event log in Powershell
A quick way to generate a log file that can be used to feed write-eventlog
=========================================
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
$Archivolog = "C:\temp\output-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
$Archivolog2 = "C:\temp\compress-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
Start-Transcript -path $Archivolog -append
Write-Host Step 1 Start at $(get-date)
gci -r C:\temp | where {$_.attributes -notmatch "compressed"} | foreach {compact /C $_.fullname } | out-file $Archivolog2 -Append
gc $Archivolog2
Write-Host Step 1 Finished at $(get-date)
Stop-Transcript
$text = [IO.File]::ReadAllText($Archivolog)
New-EventLog –LogName Application –Source "Nakama test"
Write-EventLog –LogName Application –Source "Nakama test" –EntryType Information –EventID 9213 –Message $text
=========================================
=========================================
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
$Archivolog = "C:\temp\output-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
$Archivolog2 = "C:\temp\compress-$(get-date -f yyyy-MM-dd_hh-mm-ss).txt"
Start-Transcript -path $Archivolog -append
Write-Host Step 1 Start at $(get-date)
gci -r C:\temp | where {$_.attributes -notmatch "compressed"} | foreach {compact /C $_.fullname } | out-file $Archivolog2 -Append
gc $Archivolog2
Write-Host Step 1 Finished at $(get-date)
Stop-Transcript
$text = [IO.File]::ReadAllText($Archivolog)
New-EventLog –LogName Application –Source "Nakama test"
Write-EventLog –LogName Application –Source "Nakama test" –EntryType Information –EventID 9213 –Message $text
=========================================
Sunday, February 12, 2017
Parse ACLs and comparison made between 2 files obtained through setacl.exe command
======================================================
copy wealth_source.csv source.csv /y
copy wealth_target.csv target.csv /y
sed -ie "/^\\\\/{n;d}" source.csv
sed -ie "s/ /;/g" source.csv
awk -F; "{if (NF!=0 && $1==\"\") {$1=prev} prev=$1}1" OFS=; source.csv >source2.csv
sed -i "/^\s*$/d" source2.csv
sed -ie "s/=/;/g" source2.csv
sed -ie "/.*;DACL/d" source2.csv
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\/,\";\",$2); print}" source2.csv >source3.csv
awk -F";" "BEGIN {OFS=\";\"} {print $0, $1\"\\\\\" $3}" source3.csv >source4.csv
sed -ie "/^\\\\/{n;d}" target.csv
sed -ie "s/ /;/g" target.csv
awk -F; "{if (NF!=0 && $1==\"\") {$1=prev} prev=$1}1" OFS=; target.csv >target2.csv
sed -i "/^\s*$/d" target2.csv
sed -ie "s/=/;/g" target2.csv
sed -ie "/.*;DACL/d" target2.csv
del sed *.
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\/,\";\",$2); print}" target2.csv >target3.csv
awk -F";" "BEGIN {OFS=\";\"} {print $0, $1\"\\\\\" $3}" target3.csv >target4.csv
awk -F";" "BEGIN {OFS=\";\"} {print $08, $0}" target4.csv >target5.csv
awk -F";" "BEGIN {OFS=\";\"} {print $08, $0}" source4.csv >source5.csv
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\\\TargetServer\\software/,\"\",$1); print}" target5.csv >target6.csv
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\\\OriginalServer\\Vol1/,\"\",$1); print}" source5.csv >source6.csv
sed -i "/^;/d" target6.csv
sed -i "/^;/d" source6.csv
awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" target6.csv source6.csv > BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV
awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" source6.csv target6.csv > Found-on-target.csv
sed -i "1 i\Value searched;File found on Target (Targetserver);Target Domain found;Target Group found;Target SID found;Target ACL found;Target ACL found;Target ACL found;Source value;Source file;Source Domain;Source group;Source SID;Source ACL;Source ACL;Source ACL" BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV
findstr /c:" Not Found" Found-on-target.csv >only-missings-on-source.csv
del sed *.
======================================================
Script on Windows with awk/sed to parse two files making a comparison between them.
Scenario: robocopied source to target
ReACL is required. Tool used: setacl.exe with mapping.csv file using OLDSID,NEWSID
This script removes what I don't care - Searches based on column or field 1: file/folder+GroupName, if not found it states not found.
copy wealth_source.csv source.csv /y
copy wealth_target.csv target.csv /y
sed -ie "/^\\\\/{n;d}" source.csv
sed -ie "s/ /;/g" source.csv
awk -F; "{if (NF!=0 && $1==\"\") {$1=prev} prev=$1}1" OFS=; source.csv >source2.csv
sed -i "/^\s*$/d" source2.csv
sed -ie "s/=/;/g" source2.csv
sed -ie "/.*;DACL/d" source2.csv
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\/,\";\",$2); print}" source2.csv >source3.csv
awk -F";" "BEGIN {OFS=\";\"} {print $0, $1\"\\\\\" $3}" source3.csv >source4.csv
sed -ie "/^\\\\/{n;d}" target.csv
sed -ie "s/ /;/g" target.csv
awk -F; "{if (NF!=0 && $1==\"\") {$1=prev} prev=$1}1" OFS=; target.csv >target2.csv
sed -i "/^\s*$/d" target2.csv
sed -ie "s/=/;/g" target2.csv
sed -ie "/.*;DACL/d" target2.csv
del sed *.
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\/,\";\",$2); print}" target2.csv >target3.csv
awk -F";" "BEGIN {OFS=\";\"} {print $0, $1\"\\\\\" $3}" target3.csv >target4.csv
awk -F";" "BEGIN {OFS=\";\"} {print $08, $0}" target4.csv >target5.csv
awk -F";" "BEGIN {OFS=\";\"} {print $08, $0}" source4.csv >source5.csv
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\\\TargetServer\\software/,\"\",$1); print}" target5.csv >target6.csv
awk -F";" "BEGIN {OFS=\";\"} {gsub(/\\\\OriginalServer\\Vol1/,\"\",$1); print}" source5.csv >source6.csv
sed -i "/^;/d" target6.csv
sed -i "/^;/d" source6.csv
awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" target6.csv source6.csv > BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV
awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" source6.csv target6.csv > Found-on-target.csv
sed -i "1 i\Value searched;File found on Target (Targetserver);Target Domain found;Target Group found;Target SID found;Target ACL found;Target ACL found;Target ACL found;Source value;Source file;Source Domain;Source group;Source SID;Source ACL;Source ACL;Source ACL" BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV
findstr /c:" Not Found" Found-on-target.csv >only-missings-on-source.csv
del sed *.
======================================================
Script on Windows with awk/sed to parse two files making a comparison between them.
Scenario: robocopied source to target
ReACL is required. Tool used: setacl.exe with mapping.csv file using OLDSID,NEWSID
This script removes what I don't care - Searches based on column or field 1: file/folder+GroupName, if not found it states not found.
AWK vlookup on Windows in my case
I needed to process two files/sheets to find the matches or mark un-match as Not found or anything similar.
These are extremely long files which causes excel to take forever, or even crash everytime I ran a vlookup between these two sheets.
awk vlookup solution would be something like this
Assuming you have 2 files separated by semicolon as the demiliter.
awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" target6.csv source6.csv > BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV
If first column of both files are equal, print columns 1 to 8 from the target6.csv file, plus the entire line from source6.csv if it is not found it will print the value we are looking plus "Not found" and then the entire line from source6.csv
These are extremely long files which causes excel to take forever, or even crash everytime I ran a vlookup between these two sheets.
awk vlookup solution would be something like this
Assuming you have 2 files separated by semicolon as the demiliter.
awk -F";" "NR==FNR{a[$1]=$1\";\"$2\";\"$3\";\"$4\";\"$5\";\"$6\";\"$7\";\"$8;next}{if (a[$1])print a[$1]\";\"$0;else print $1 \" Not Found\"\";\"\";\"\";\"\";\"\";\"\";\"\";\"\";\" $0;}" target6.csv source6.csv > BUSCA-EN-TARGET-LO-QUE-HAY-EN-SOURCE.CSV
If first column of both files are equal, print columns 1 to 8 from the target6.csv file, plus the entire line from source6.csv if it is not found it will print the value we are looking plus "Not found" and then the entire line from source6.csv
Subscribe to:
Posts (Atom)
0 comments:
Post a Comment