Windows Server 2012 ships with PowerShell version 3
To check version use...
$PSVersionTable.PSVersion
Assuming you are in a PowerShell window and the script you want to run has a .ps1 extension and is in your current working directory, run...
./myscript.ps1
From outside PowerShell (i.e. Windows command prompt), you can use...
powershell -File ./myscript.ps1
If your default script execution policy does not allow this, try...
powershell -executionpolicy bypass -File ./myscript.ps1
Get-Childitem -Path Env:* | Sort-Object Name
${env:UserName}
${env:UserDomain}
${env:ComputerName}
${env:Path}
Get-Childitem $Env:Temp -Recurse
Help About_Environment_Variables
Get-Module -ListAvailable
All current environment variables
Current User
Current User's Domain
Current Computer Name
Path
Show Temp Files
Get more information
List installed PowerShell modules
Windows Version/Build information...
Get-WmiObject Win32_OperatingSystem | Select PSComputerName, Caption, OSArchitecture, Version, BuildNumber | FL
powershell "dir | tee test.txt"Â
Interactive Session...
Enter-PSSession myServer
...
Exit-PSSession
Remote Command...
Invoke-Command -ComputerName myServer, myOtherServer -ScriptBlock {Get-UICulture}
To run a script (available on your local computer)...
Invoke-Command -ComputerName myServer, myOtherServer -FilePath c:\mypath\myScript.ps1
Further information...
https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/running-remote-commands?view=powershell-7Windows Version for Remote Computer...
Get-WmiObject Win32_OperatingSystem -ComputerName "Remote_Machine_Name" |
Select PSComputerName, Caption, OSArchitecture, Version, BuildNumber | FL