lang/ps/ PsExamples1


Accessing things using cd

PSDrives

Get-PSDrive
cd Env:
cd HKCU:

Network share

* 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

Get-ChildItem -path C:\Windows | Select-Object -Property Name | Out-File -Encoding UTF8 WindowsDir.txt

Location of users folders

(New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path

and you can save this to a variable via

Set-Variable dlpath (New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path

and then use via

cd $dlpath

Misc Examples

Do something when GoogleChrome downloads have finished.

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.