1. Linux

1.1. Installation

# Install libunwind8 and libssl1.0 packages.
# Use regex to ensure not to install libssl1.0-dev, as it is a variant that is not required.
sudo apt-get install --yes "^libssl1.0.[0-9]$" libunwind8
dpkg -l | grep -i "libssl1.0"

wget https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/powershell-7.1.3-linux-arm32.tar.gz
wget https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/powershell-7.1.3-linux-arm64.tar.gz
wget https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/powershell_7.1.3-1.debian.10_amd64.deb

mkdir -p ~/powershell-7.1.3
cd ~/powershell-7.1.3
tar -xvf ../powershell-7.1.3-linux-arm32.tar.gz         # 32-bit
tar -xvf ../powershell-7.1.3-linux-arm64.tar.gz         # 64-bit
sudo rm -f /usr/bin/pwsh
sudo ln -s ~/powershell-7.1.3/pwsh /usr/bin/pwsh
cd

pwsh --help
pwsh
$PSVersionTable
exit

+

1.2. Configuration

1.2.1. Disable logging

Fixes too verbose logging and flooding of the /var/log/syslog file.

1.3. Usage

echo 'echo $PSVersionTable' > Test.ps1
cat Test.ps1
pwsh -File Test.ps1

+

2. macOS

3. Windows

3.1. PowerShell 2.0

3.1.1. Installation

3.1.1.1. Windows XP
  • Install .NET Framework 2.0 SP1.

  • Logon as Administrator.

  • Install Windows Management Framework 2.0.

    • Double-click the WindowsXP-KB968930-x86-ENG.exe file.

    • Click Next.

    • Choose I Agree.

    • Click Next.

    • Wait.

    • Click Finish.

  • Restart the computer.

3.1.1.2. Windows Vista
  • Logon as Administrator.

  • Install Windows Management Framework 2.0.

    • Run the Windows6.0-KB968930-x86.msu file with administrative privileges.

    • Click OK.

    • Click Close.

  • Restart the computer.

3.2. PowerShell 4.0

3.2.1. Windows 7

3.2.1.1. Installation
  • Install Windows Management Framework 4.0.

    • 32-bit: Run the Windows6.1-KB2819745-x86-MultiPkg.msu file with administrative privileges.

    • 64-bit: Run the Windows6.1-KB2819745-x64-MultiPkg.msu file with administrative privileges.

    • Click Yes.

    • Click I Accept.

    • Wait.

    • Click Close.

  • Restart the computer.

3.3. PowerShell 5.0

3.3.1. Installation

  • Logon as Administrator.

  • Install Windows Management Framework 5.0.

    • Optional: Double-click the Win7-KB3134760-x86.msu file.

    • Optional: Double-click the Win7AndW2K8R2-KB3134760-x64.msu file.

    • ???

3.4. PowerShell 7.0

3.4.1. Installation

  • Run the PowerShell-7.1.1-win-x64.msi file.

  • Click Next.

    C:\Program Files\PowerShell
  • Click Next.

    ■ Add PowerShell to Path Environment Variable
    ■ Register Windows Event Logging Manifest
    □ Enable PowerShell remoting
    □ Add 'Open here' context menus to Explorer
  • Click Next.

  • Click Install.

  • Click Finish.

3.5. PowerShell 7.5.4.0

3.5.1. Installation

  • Run the PowerShell-7.5.4-win-x64.msi file with administrative privileges to install the 64-bit version.

  • Run the PowerShell-7.5.4-win-x86.msi file with administrative privileges to install the 32-bit version.

  • Click Next.

  • ???

  • Click Finish.

4. Configuration

4.1. Creation of new profile

  • See http://www.howtogeek.com/50236/customizing-your-powershell-profile

  • Log in as <User>.

  • Start PowerShell.

  • Type Get-ExecutionPolicy and press Enter.

  • Optional: Type Help Set-ExecutionPolicy -Full and press Enter.

  • Type Set-ExecutionPolicy RemoteSigned and press Enter.

  • Type Test-Path $profile and press Enter.

  • Type New-Item -path $profile -type file -force and press Enter.

  • Type Test-Path $profile and press Enter.

  • Optional: Type dir C:\Users\<User>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 and press Enter.

  • Optional: Type type C:\Users\<User>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 and press Enter.

  • Close PowerShell.

4.2. Configuration of PowerShell

  • Add "Set-StrictMode -Version Latest" to PowerShell profile.

5. Package Providers

5.1. Installation

  • Enter the following commands at a PowerShell Command Prompt with administrative privileges.

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    Get-PackageProvider -ListAvailable
    
    Get-PackageSource -WarningAction SilentlyContinue
    Get-PackageProvider -Force -Name Chocolatey
    Get-PackageProvider -Force -MinimumVersion 2.8.5.201 -Name NuGet
    Register-PackageSource -ErrorAction SilentlyContinue -Location http://chocolatey.org/api/v2 -Name chocolatey -ProviderName Chocolatey -Trusted
    Register-PackageSource -ErrorAction SilentlyContinue -Name PSGallery -ProviderName PowerShellGet -Trusted
    Get-PackageSource -WarningAction SilentlyContinue
    Find-PackageProvider

5.2. Uninstallation

  • Enter the following commands at a PowerShell Command Prompt with administrative privileges.

    Unregister-PackageSource -ErrorAction SilentlyContinue -Location http://chocolatey.org/api/v2 -Name chocolatey -ProviderName Chocolatey
    Unregister-PackageSource -ErrorAction SilentlyContinue -Name PSGallery -ProviderName PowerShellGet
    $Path = "${Env:ProgramFiles}\PackageManagement\ProviderAssemblies"
    Remove-Item -ErrorAction SilentlyContinue -Force -Path "$Path\Chocolatey" -Recurse -Verbose
    Remove-Item -ErrorAction SilentlyContinue -Force -Path "$Path\NuGet"      -Recurse -Verbose
    Get-PackageSource -WarningAction SilentlyContinue

6. Usage

  • Logon as <User>.

  • Start PowerShell.

  • Type Set-ChildItem -force | Where-Object { $_.Attributes -ge "Encrypted" } and press Enter.

  • Close PowerShell.

6.1. Show all properties

$Object = Get-WmiObject -Class "Win32_computersystem"
SObject = Format-List -Property *
SObject = Format-List *
powershell -ExecutionPolicy Bypass $Env:Path -split ';'

6.2. Downloads

  • Logon as <User>.

  • Start PowerShell.

  • Optional: Type (New-Object System.Net.WebClient).DownloadFile('http://download.piriform.com/ccsetup404.exe', 'c:\users\<user>\downloads\ccsetup404.exe') and press Enter.

  • Type $source = 'http://download.piriform.com/ccsetup404.exe' and press Enter.

  • Type $destination = 'c:\users\<user>\downloads\ccsetup404.exe' and press Enter.

  • Type $wc = New-Object System.Net.WebClient and press Enter.

  • Type $wc.DownloadFile($source, $destination) and press Enter.

  • Type dir c:\users\<user>\downloads and press Enter.

  • Close PowerShell.

6.3. Event Viewer

  • Logon as <User>.

  • Start PowerShell.

  • Type Get-EventLog -List and press Enter.

  • Type Get-EventLog application -newest 10 and press Enter.

  • Type Get-EventLog system -newest 10 and press Enter.

  • Type Get-EventLog system | Where-Object {$_.Index -eq <Index>} and press Enter.

  • Type Get-EventLog system | Where-Object {$_.Index -eq <Index>} | Format-List and press Enter.

  • Close PowerShell.

6.4. Task Scheduler

  • Install PowerShell Pack.

  • Logon as <User>.

  • Start PowerShell.

  • Type Import-Module TaskScheduler and press Enter.

  • Type Get-Command -Module TaskScheduler and press Enter.

  • ???

  • Close PowerShell.

  • Start Command Prompt.

  • Type schtasks /? and press Enter.

  • Type schtasks /query | more and press Enter.

  • Type schtasks /run /? and press Enter.

  • Type schtasks /run /tn "pms backup" and press Enter.

  • Type dir d:\db_backup\backups{asterisk}201405* and press Enter.

  • Type schtasks /change /? | more and press Enter.

  • Type schtasks /change /tn "pms backup" /rp <new password> and press Enter.

  • Close Command Prompt.

  • Start PowerShell.

$servername = "SMRU-PMS-MKT"
$schedule = new-object -com("Schedule.Service")
$schedule.connect($servername)
$tasks = $schedule.getfolder("\").gettasks(0)
$tasks | select name, lasttaskresult, lastruntime

    Name                                   LastTaskResult LastRunTime
    ----                                   -------------- -----------
    Adobe Flash Player Updater                          0 24/08/2013 12:31:00 PM
    PMS Backup                                -2147023570 24/08/2013 12:27:57 PM

* See *https://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows?view=powershell-7.5[^]*.


    GoogleUpdateTaskMachineCore                         0 23/08/2013 4:46:00 PM
    GoogleUpdateTaskMachineUA                           0 24/08/2013 11:46:00 AM
    SidebarExecute                             1073807364 14/06/2012 2:29:25 PM
    {F423585E-0420-4C46-93A1-97B7A08771CE}              0 18/06/2012 10:41:53 AM
-2147023570 -> Logon failure: unknown user name or bad password.
  • Close PowerShell.

6.5. Command Prompt

  • Start PowerShell.

  • Type Invoke-Expression -Command:c:\windows\system32\cmd.exe and press Enter.

  • Type exit and press Enter.

  • Close PowerShell.

6.6. Persistent History

Configuration of persistent history.

$HistoryPath = "C:\Users\<User>\Documents\WindowsPowerShell\History"
if (Test-Path "$HistoryPath\History.xml") {
  Add-History -InputObject (Import-Clixml "$HistoryPath\History.xml")
} elseif (-not (Test-Path $HistoryPath)) {
  $Null = New-Item -Path $HistoryPath -ItemType Directory
}
Register-EngineEvent -SourceIdentifier powershell.exiting -SupportEvent -Action {
  Get-History | Select-Object -Last 100 | Export-Clixml -Path "$HistoryPath\History.xml"
}

Aliases:

new-item alias:np -value C:WindowsSystem32notepad.exe
$HistoryFilePath = Join-Path ([Environment]::GetFolderPath('UserProfile')) .ps_history
Register-EngineEvent PowerShell.Exiting -Action { Get-History | Export-Clixml $HistoryFilePath } | out-null
if (Test-path $HistoryFilePath) { Import-Clixml $HistoryFilePath | Add-History }
# if you don't already have this configured...
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
$password = ConvertTo-SecureString "********" -AsPlainText -Force
$cred= New-Object System.Management.Automation.PSCredential("smru", $password)
New-PSDrive -Name "P" -PSProvider FileSystem -Root "\\10.10.1.2\Public" -Credential $cred
Remove-PSDrive P
New-PSDrive -Name "Q" -PSProvider FileSystem -Root "\\10.10.1.2\Public"
New-PSDrive -Name "Q" -PSProvider FileSystem -Root "\\10.10.1.2\Public" -Persist
$Software1 = Get-ItemProperty -ErrorAction SilentlyContinue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"
$Software1 | Select-Object DisplayName