Powershell: Difference between revisions

From miki
Jump to navigation Jump to search
Line 4: Line 4:
== Reference ==
== Reference ==
<source lang="powershell">
<source lang="powershell">
# Documentation
# Documentation, information
Update-Help # Update help system - to run as Administrator
Update-Help # Update help system - to run as Administrator
help Test-Path # Get help on a command, on an alias...
help Test-Path # Get help on a command, on an alias...
Line 12: Line 12:
Get-Command about_* # DOES NOT WORK
Get-Command about_* # DOES NOT WORK
Get-Command -Verb Add
Get-Command -Verb Add

Get-Alias ps # ... Get-Process
Get-Alias ps # 'Get-Process'
Get-Alias -Definition Get-Process # ... ps
Get-Alias -Definition Get-Process # 'ps'
gal | findstr Get-Process # Unix style

ps | Get-Member
ps | Get-Member


# Frequent aliases
# Frequent aliases
Get-Command # alias: gcm
# gcm -> Get-Command
Get-Process # alias: ps
# ps -> Get-Process
# help -> Get-Help
Get-Help # alias: help
# alias -> Get-Alias
Get-Alias # alias: alias, gal
Get-Member # alias: gm
# gal -> Get-Alias
New-Item # alias: ni, md, mkdir
# gm -> Get-Member
# ni -> New-Item
Remove-Item # alias: del, erase, rd, ri, rm, rmdir
# md -> New-Item
# mkdir -> New-Item
# del -> Remove-Item
# erase -> Remove-Item
# rd -> Remove-Item
# ri -> Remove-Item
# rm -> Remove-Item
# rmdir -> Remove-Item
# where -> Where-Object
# dir -> Get-ChildItem
# ls -> Get-ChildItem
# gci -> Get-ChildItem

# Options can be abbreviated
Get-Alias -Definition Get-Process
gal -def Get-Process

# Grep-like
gal | findstr Get-Process
gal | where {$_.Definition -eq 'Get-Help'}
dir Alias: | where {$_.Definition -eq 'Get-Help'}
</source>
</source>



Revision as of 12:57, 22 February 2022

Links

Reference

# Documentation, information
Update-Help              # Update help system - to run as Administrator
help Test-Path           # Get help on a command, on an alias...
help Test-Path -full     # ... and on all options
help Test-Path -examples # ... see examples. VERY USEFUL. Eg. help save-help examples

Get-Command about_*      # DOES NOT WORK
Get-Command -Verb Add

Get-Alias ps                      # 'Get-Process'
Get-Alias -Definition Get-Process # 'ps'
gal | findstr Get-Process         # Unix style

ps | Get-Member

# Frequent aliases
#   gcm    ->  Get-Command
#   ps     ->  Get-Process
#   help   ->  Get-Help
#   alias  ->  Get-Alias
#   gal    ->  Get-Alias
#   gm     ->  Get-Member
#   ni     ->  New-Item
#   md     ->  New-Item
#   mkdir  ->  New-Item
#   del    ->  Remove-Item
#   erase  ->  Remove-Item
#   rd     ->  Remove-Item
#   ri     ->  Remove-Item
#   rm     ->  Remove-Item
#   rmdir  ->  Remove-Item
#   where  ->  Where-Object
#   dir    ->  Get-ChildItem
#   ls     ->  Get-ChildItem
#   gci    ->  Get-ChildItem

# Options can be abbreviated
Get-Alias -Definition Get-Process
gal -def Get-Process

# Grep-like
gal | findstr Get-Process
gal | where {$_.Definition -eq 'Get-Help'}
dir Alias: | where {$_.Definition -eq 'Get-Help'}

Tips

Measure execution time of a command

Measure-Command { dir }
Measure-Command { dir | Out-default}   # To get output
Measure-Command { choco list }

Update help on offline computers

From MS devblogs:

<source lang="powershell">

  1. On online computer

New-Item c:\tmp\help Save-Help -DestinationPath c:\tmp\help -Module * -Force

  1. On offline computer
  2. ... transfer files to c:\tmp\help
  3. ... start powershell in admin (Win-X-A)

Update-Help -SourcePath c:\tmp\help -Module * -Force </source