Powershell: Difference between revisions

From miki
Jump to navigation Jump to search
Line 33: Line 33:
Measure-Command { choco list }
Measure-Command { choco list }
</source>
</source>

=== Update help on offline computers ===
From [https://devblogs.microsoft.com/scripting/powertip-use-saved-help-files-to-update-powershell-help/ MS devblogs]:

<source lang="powershell">
# On online computer
New-Item c:\tmp\help
Save-Help -DestinationPath c:\tmp\help -Module * -Force

# On offline computer
# ... transfer files to c:\tmp\help
# ... start powershell in admin (Win-X-A)
Update-Help -SourcePath c:\tmp\help -Module * -Force
</source

Revision as of 12:44, 22 February 2022

Links

Reference

# Documentation
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
ps | Get-Member

# Frequent aliases
Get-Command          # alias: gcm
Get-Process          # alias: ps
Get-Help             # alias: help
Get-Alias            # alias: alias, gal
Get-Member           # alias: gm
New-Item             # alias: ni, md, mkdir
Remove-Item          # alias: del, erase, rd, ri, rm, rmdir

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