revlis.nl
Stash of notes about OSS, OSes, devops, virtualization, programming (hobby) projects, security and tech news
July 9, 2019 — 9:17
I’ve been using PS for a while now and I don’t hate it anymore :) In fact, I think it’s very usable for lots of tasks and automation. Easy to learn too, a bit like “python-lite” for sysadmins perhaps.
Here’s some Useful commands
discover/help:
Get-Command *help*
orGet-Command-Module PackageManagement
Get-Member
to view properties e.g.Get-Disk | Get-Member
Get-Alias
access:
Get-ExecutionPolicy -List
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
- Run as admin:
powershell.exe -Command "Start-Process cmd -Verb RunAs"
support for csv, xml and json is included:
Import-CSV
Export-CSV
ConvertTo-XML
ConvertFrom-Json
ConvertTo-Json
And stuff like:
- piping to
select
,sort
andwhere
(grep) Invoke-WebRequest $url
(curl)- Logging sessions:
Start-Transcript
Stop-Transcript
- Viewing Certificates:
cd Cert:\
(now you can ‘dir’ etc) - PS Linting: https://github.com/PowerShell/PSScriptAnalyzer and Testing: https://pester.dev
Remote usage is also possible over WinRM (or OpenSSH):
Enter-PSSession -ComputerName <host>
Then there’s Loops, Params, Arrays and Hash Tables e.g. foreach
, Param([string]$arg)
, @()
and @{}
…
Besides for Windows and Azure, PS (Core) can also be used on Linux/MacOS and then there’s PowerCLI for VMware. Not bad, not bad at all.
More info:
- https://learn.microsoft.com/en-us/shows/it-ops-talk/how-to-install-powershell-7
- https://docs.microsoft.com/en-us/powershell/scripting/install/installing-windows-powershell?view=powershell-6
- https://docs.microsoft.com/en-us/powershell/dsc/overview/overview
- https://github.com/powershell/powershell
- https://github.com/PowerShell/openssh-portable