BASH | Powershell |
---|---|
cat $file | less | gci $filename | more |
CMD | less | CMDLET | more |
CMD | grep | CMDLET | findstr CMDLET | out-string -stream | sls Note: *sls* is Select-String |
Get-ChildItem | gci ls dir |
Remove-Item | ri rm rmdir del erase rd |
Get-Command | gcm _(just like *which* in Bash)_ |
Get-Content | gc cat type |
New-Item | ni |
Get-Member | gm |
echo | echo write-host write-verbose write-debug |
ls env:
ls env:U*
echo $env:userprofile
- Per Session
$env:myvar = "abc123"
- Permanent
[Environment]::SetEnvironmentVariable( "Name", "Value", "<OPTION>" )
- where OPTION is one of:
User
(per use profile)Machine
(anyone logged into the machine)Process
(temporary, for this session only, same as $env syntax above)
- where OPTION is one of:
remove-item Env:$myvariable
[Environment]::SetEnvironmentVariable( "Name", $null, "<OPTION>" )
Break long commands into readable chunks by specifying parameters in a hash.
$params = @{ 'class' = 'Win32_BIOS';
'computername'='SERVER-R2';
'filter'='drivetype=3';
'credential'='Administrator' }
Get-WmiObject @params
Create useful aliases (like in Bash) that pass cmdline parameters onto the underlying command
function vbox { vagrant box @Args }
- Windows PowerShell: Splatting
- Split command across mulitple lines
- Splatting with Hashtables or Arrays
Directory Locations | |
---|---|
Per User | $USERPROFLE\Documents\WindowsPowerShell\ |
All users | $windir\system32\WindowsPowerShell\v1.0\ |
Special File Names | (must be in one of the directories above) |
---|---|
Global | profile.ps1 |
Powershell Only | Microsoft.PowerShell_profile.ps1 |
New-Item -ItemType SymbolicLink -Name <SRC> -Target <TGT>
New-Item -itemtype junction -name <SRC> -target <TGT>
man <cmdlet>
<cmdlet> -?
get-help [-detailed -full -parameter <param-name> -examples]
GetType()
- Example:
(get-date).getType()
Get-Member
- Alias:
gm
- Example:
( get-date ).DayOfWeek | gm -f
Set-PSDebug -Trace 1