Powershell

Table of Contents

NTFS


Create Files

Move directories

Permissions

Search Hidden Item

Get-ChildItem 'c:\users\public\desktop' -recurse -force


Remove hidden item
Remove-Item -path 'c:\users\public\desktop\Google Chrome.lnk' -Force


Find folder permissions

$OutFile = "C:\temp\Permissions.csv"
$Header = "Folder
Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
Add-Content -Value $Header -Path $OutFile
$RootPath = "\\fs03\Admin"
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}
foreach ($Folder in $Folders){
$ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access }
Foreach ($ACL in $ACLs){ $OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
Add-Content -Value $OutInfo -Path $OutFile
}}


Account SID's

$sid = [System.Security.Principal.WindowsIdentity]::GetCurrent().groups
$accounts = $sid.Translate([System.Security.Principal.NTAccount]).value
$hash = @{"sid"=$sid.value;"Accounts"=$accounts}
$obj = New-Object -TypeName psobject -Property $hash
for ($i=0; $i -lt $obj.sid.Length; $i++)
{"{0:D2}. {1} - {2}" -f ($i),$obj.Accounts[$i],$obj.sid[$i]}


Copy file to another

$source = Get-ChildItem -Path "C:\users\sumeet\Documents\source"
$destination = Get-ChildItem -Path "C:\users\sumeet\Documents\Destination"
Copy-Item -Path $source.fullname -Destination $destination[0].DirectoryName -Exclude $destination.fullname


Reiterate through many files and replace exiting text

Set-Location -Path "C:\inetpub\wwwroot"
$files = get-childitem -path "C:\inetpub\wwwroot" -Include "*.htm" -Recurse -Force| Select-Object -ExpandProperty name
ForEach ($file in $files) {
$object = get-content -path $file | ForEach-Object {$_ -replace "PoSHPythonCSS","PoshPythonCSS"}
$object | Set-Content -Path $file
}



Bitlocker



To check the status of Bitlocker. Helpful when checking encription/decrpytion times.

manage-bde.exe -status c:


Start bitlocker on Drive C:

$SecureString = ConvertTo-SecureString "3212" -AsPlainText -Force Disable-BitLocker -MountPoint "C:" -EncryptionMethod Aes256 -UsedSpaceOnly -Pin $SecureString -TPMandPinProtector