### Accessing things using cd PSDrives ```ps Get-PSDrive cd Env: cd HKCU: ``` Network share ```ps * way of accessing network shares via powershell New-PSDrive -name BOING -psprovider FileSystem -root \ \hostname\sharename cd BOING: ``` ### Outputting to files Writing to plain text files ```ps Get-ChildItem -path C:\Windows | Select-Object -Property Name | Out-File -Encoding UTF8 WindowsDir.txt ``` ### Location of users folders ```ps (New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path ``` and you can save this to a variable via ```ps Set-Variable dlpath (New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path ``` and then use via ```ps cd $dlpath ``` ### Misc Examples Do something when GoogleChrome downloads have finished. ```ps while ( { get-item \\machine-name\share-name\etc\Downloads\*.cr* | measure-object | select-object { $_.Count -gt 0 } } ) { echo hello ; sleep 1 ; } ; calc ``` where in this instance it launches the calculator when downloads are done. ### Preventing HID Devices From Waking See [here](https://w.allsup.co/lang/ps/PowerManagement). ## *Nix equivalents Which: ```ps Get-Command Get-Command wt | select-object -property Source # These two do the sae Get-Command wt | foreach { $_.Source } (get-command wt).Source # Copy to clipboard Get-Command wt | foreach { $_.Source } | clip ``` ## Am I Admin ```ps if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(` [Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Host "Not running as Administrator." -ForegroundColor Red } else { Write-Host "Running as administrator." -ForegroundColor Green } ```