Copying the ACL
|
1 |
Get-Acl sourceFile | Set-Acl targetFile |
Copy files with the ACL
|
1 |
robocopy source target /e /z /sec |
Add Permission on File
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Function addFilePermission ($FileName, [string]$ACLUserName, [string]$Permission, [string]$Allow_Deny){ if ((Test-Path $FileName) -eq $True) { $file = Get-ChildItem $FileName $acl = $file.GetAccessControl() $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ("$ACLUserName","$Permission","$Allow_Deny") $acl.AddAccessRule($accessrule) $file.SetAccessControl($acl) } else { Write-Host "The system cannot find the file specified." } } addFilePermission "fileName.txt" "olie" "FullControl" "Allow" |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
::Clear Cookies RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2 ::Clear History RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1 ::Clear Form Data RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16 ::Clear Saved Passwords RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32 ::Delete All RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255 :: Delete All w/Clear Add-ons Settings: RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351 |
Syntax:
Get-ChildItemPlus [-Path] <string> [-Level] <integer> [-Type] <string>
Example 1:
Get-ChildItemPlus c:\temp 2 Folder
This command retrieves all of the folders in the c:\temp path till second level.
Example 2:
Get-ChildItemPlus c:\temp 3 Files
This command retrieves all of the files in the c:\temp path till third level.
Parameters:
- Path
Specifies a path to location
- Level
Specifies a depth to search - e.g. c:\windows\system32 is level 2
- Type
The type of object that Get-ChildItem returns: File, Folder, Both
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Function Get-ChildItemPlus { Param ([Parameter(Mandatory = $true, ValueFromPipeline = $false, Position = 0)] [string]$Path = ".", [Parameter(Mandatory = $true, ValueFromPipeline = $false, Position = 1)] [int]$Level = 99, [Parameter(Mandatory = $true, ValueFromPipeline = $false, Position = 2)] [string]$Type = "") switch ($Type) { "Folder" {$Data = Get-ChildItem -Path "$Path" -Recurse | Where-Object {$_.psIsContainer -eq $True}} "File" {$Data = Get-ChildItem -Path "$Path" -Recurse | Where-Object {! $_.psIsContainer}} default {$Data = Get-ChildItem -Path "$Path" -Recurse} } if ($Data -eq $Null) {Break} $Level++ $Output = @() foreach ($Item in $Data) { $Folder = $Item.FullName.ToString() if ($Folder.Split("\").Count -le "$Level") { $Output += "$Folder" } } return $Output } |