https://learn.microsoft.
com/en-us/powershell/
To Check the PowerShell version
get-host
get-host |select-object version
$PSVersionTable
Set PowerShell’s Execution Policy
Restricted – PowerShell won’t run any scripts. This is
PowerShell’s default execution policy.
AllSigned – PowerShell will only run scripts that are
signed with a digital signature. If you run a script signed
by a publisher PowerShell hasn’t seen before,
PowerShell will ask whether you trust the script’s
publisher.
RemoteSigned – PowerShell won’t run scripts
downloaded from the Internet unless they have a digital
signature, but scripts not downloaded from the Internet
will run without prompting. If a script has a digital
signature, PowerShell will prompt you before it runs a
script from a publisher it hasn’t seen before.
Unrestricted – PowerShell ignores digital signatures but
will still prompt you before running a script downloaded
from the Internet.
Bypass – Everything runs without a warning. Be careful
with this one.
Undefined – No policy is defined in the current scope.
This is used to allow fall-back to policies defined in lower
scopes (more details below) or to the OS defaults.
Check the current policy
Get-ExecutionPolicy
Change the policy into RemoteSigned
Set-ExecutionPolicy RemoteSigned
Run Your First PowerShell script
Create a script file with following content. Name the file
as MyScript.ps1
Write-Host "Hello, world"
Save the MyScript.ps1 file into following folder
C:\Scripts
Run Following commands at PowerShell
PS C:\> Set-Location C:\Scripts
PS C:\Scripts> .\MyScript.ps1
Alternatively you can use cmd.exe to run the scripts
In this case following script is used to get the information.
computer hostname = w
$computers = "w"
Get-WmiObject -Class win32_bios -cn $computers |
Format-table __Server, Manufacturer, Version -AutoSize
You can use PowerShell scripts against Multiple
Computers
In this scenario Windows Server 2012 R2 server domain
environment is used to run the scripts.
Save following script in MyScript.ps1 file.
$computers = Get-Content -Path C:\Scripts\Computers.txt
Get-WmiObject -Class win32_bios -cn $computers -EA
silentlyContinue |
Format-table __Server, Manufacturer, Version –AutoSize
And Make sure the computers list in the network is
saved as a text file in Computers.txt.
win7
S2012
The path of the text file should be
C:\Scripts\Computers.txt
Run the PowerShell script
PS C:\> Set-Location C:\Scripts
PS C:\Scripts> .\MyScript.ps1