TECH BASICS
How to work with PowerShell ?

As per Microsoft,
PowerShell is a cross-platform task automation and configuration management framework, consisting of a command-line shell and scripting language.
PowerShell help in automating administrative tasks of Windows based systems. Initially, Windows PowerShell was build on top of .NET Framework and worked on Windows only. In recent releases, PowerShell started using .NET Core 3.1 as its runtime. Now PowerShell runs on Windows, macOS, and Linux platforms.
Windows PowerShell — Windows platform only
Windows PowerShell Core — Cross Platform
.NET Core is a free, cross-platform, open-source developer platform for building many different types of applications.
Using PowerShell
PowerShell can be launched from Start Menu on Window OS. In case of other OS you can run pwsh in command terminal to load PowerShell.
if you docker on your system then you can work it out like this -
> docker run --rm -it mcr.microsoft.com/azure-powershell
$PSVersionTable
contains a hash table which stores information about PowerShell version and Build. (In a hash table, data is stored in an array format, where each data value has its own unique index value.)
PS /> $PSVersionTable
The Get-Command
cmdlet gets all commands that are installed on the computer, including cmdlets, aliases, functions, filters, scripts, and applications.
PS /> (Get-Command).Count

Execution Policy is another good feature of PowerShell, it is designed to prevent a user from unknowingly running a script. (When you are not able to execute a script please verify this settings immediately)
PS C:\> Get-ExecutionPolicy
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

CMDLETS
Compiled commands in PowerShell are called cmdlets. They are in singular Verb-Noun commands which makes them easily discoverable. Functions and Alias also exist in PowerShell ecosystem.
Verb-Noun
Get-Process
** Get-Verb can list approved PowerShell verbs available in the system.

** Get-Alias can list available alias in the system

PowerShell Module
PowerShell modules allow you to combine multiple scripts to simplify code management, accessibility and sharing.
To list what modules are loaded in current powershell session
PS /> Get-Module
If you want to see what all modules are available on the system
PS /> Get-Module -ListAvailable

If you want to know from where current PowerShell session is looking for module details.
PS /> $env:PSModulePath
PS /> $env:PSModulePath -split ";"# if you want to add location of any path (but this will be for session)PS /> $env:PSModulePath = $env:PSModulePath + ";D:/MyPWSHModule"
If you want to set permanent value
PS C:\Users\Arun> $current = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')
PS C:\Users\Arun> $current -split ";"C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files (x86)\Microsoft Azure\PowershellPS C:\Users\Arun> $newpath = $current + ';C:\MyNewPath'PS C:\Users\Arun> [Environment]::SetEnvironmentVariable("PSModulePath", $newpath, 'Machine')
Finding command available with that Module
PS /> Get-Command -Module PSReadLine
PS /> Get-Command -Module PSReadLine -Verb Get
Good to know Commands
Get-Command is designed to help you locate commands.
# used to search installed commands
PS /> Get-Command -Verb get -Noun *TIME*PS /> Get-Command -Name *service*

Get-Help helps you to find out details about a command
PS /> Get-Help -Name *TIME*


PS /> help Get-Process | more

Objects are everywhere in PowerShell. PowerShell uses objects as its output
Objects have many different types of information associated with them. This information is called members.
To find out the information attached with an object use “Get-Member” cmdlet.
Get-Member helps you discover what objects, properties, and methods are available for commands.
PS /> Get-Process | Get-Member

A property is a characteristic about an item
A method is an action that can be taken on an item
PS /> Get-Process | Get-Member -MemberType property

PS /> Get-Process | Get-Member -MemberType Method

# List all property and methods
PS C:\Users\Arun> Get-Service | Get-Member
PS C:\Users\Arun> Get-Service -Name Tomcat8Status Name DisplayName
------ ---- -----------
Running Tomcat8 Apache Tomcat
PS C:\Users\Arun> (Get-Service -Name Tomcat8).StatusRunning# Using MethodPS C:\Users\Arun> (Get-Service -Name Tomcat8).Stop()Running
The Select-Object
cmdlet “filters” various properties from being returned to the PowerShell pipeline.
PS /> Get-Process | Select-Object -Property 'Id','StartTime'

Where-Object is similar to where clause in SQL.
PS /> Get-Process | Select-Object -Property 'Id','StartTime','HandleCount' | Where-Object -FilterScript { $_.Id -eq "1" } | Format-Table -AutoSize

If you have experience working on bash shells, you know the usability of history command. Similar command is also available in powershell now.
PS /> Invoke-History
PS /> Get-History | Out-File history.txt
Providers
A provider in PowerShell is an interface that allows file system like access to a datastore. There are a number of built-in providers in PowerShell. You can list them using -
PS /> Get-PSProvider

The System drives that these providers use to expose their datastore, can be determined with the GetPSDrive cmdlet. The Get-PSDrive cmdlet not only displays drives exposed by providers, but it also displays Windows/Linux logical drives including drives mapped to network shares if any.
Get-WMIObject Win32_Service -filter "startname='DOMAIN\\SVC_ACNT_NAME'" | Select-Object -Property Name,Status,State
WMI and CIM
Windows Management Instrumentation (WMI) is the infrastructure for management data and operations on Windows-based operating systems. WMI uses the Common Information Model (CIM) industry standard to represent systems, applications, networks, devices, and other managed components.
PowerShell has inbuild Cmdlets which allows you to work with WMI and CIM objects. WMI and CIM both access similar information, its just WMI is legacy version.
Ex:PS C:\Users\Arun> Get-CimInstance -ClassName Win32_BIOS | Select-Object -Property SerialNumberPS C:\Users\Arun> Get-WmiObject -Class Win32_Process | Format-List -Property PSComputerName, Name, ExitCode, Name, ProcessID, StartMode, State, StatusPS C:\Users\Arun> (Get-WmiObject -Class Win32_Service -Filter "name='WinRM'" -ComputerName Server01).StopService()
PowerShell Package Management
From version 5, PowerShell came with concept of package manager which is referred as PackageManagement in cmd line, It allows you to search, download and install Powershell modules and scripts from a variety of sources in a unified manner.
To list what are existing providers in place :
PS /> Get-PackageProvider
As a matter of fact PackageManagement also comes as a module
PS /> Get-Command -Module PackageManagement

Now you have PackageManagement in place. What about the repository from where packages are coming ? List the repositories configured on your system
PS /> Get-PSRepositoryName InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
**PowerShell Gallery is the central repository for PowerShell content. But you can create private repositories as well.
This Post is not over yet ! I will add more details in coming days.
I would suggest bookmark this to get latest updates.
Thanks