daknetworks.com

You are here: Blog Powershell 5 | Powershell 6 | Powershell 7 | Modules

Powershell 5 | Powershell 6 | Powershell 7 | Modules

Powershell 5 | Powershell 6 | Powershell 7 | Modules

BACKGROUND

Powershell v5: comes with Windows-10 and only works on Windows. Scripting language only.
Powershell Core (aka v6):  used for .NET development. Installable on all systems Windows, Mac, Linux.
Powershell v7: separate install. Co-exist install with v5. One SHELL for both Windows and .Net.


MODULES

Modules are packages that contains PowerShell items, such as cmdlets, providers, functions, workflows, variables, and aliases. Modules are kept and found in repositories or repos. In the repos, they are listed out as Script, Binary, Manifest.
get-module


PACKAGEPROVIDERS

Packageproviders is a wrapper around a package management system (apt-get, yum, winget, etc). This is needed because there are different types of providers. To explain, let's look at the builtin providers which are found with:
get-packageprovider

It will output:
msi: Microsoft Installation
msu: Microsoft Update
powershellget: From online gallery/repository.
programs: From Add/Remove Programs

Since not all items are .deb or .rpm, this is why there is a need for different packageproviders.

To see other providers:
find-packageprovider

To install other providers:
install-packageprovider nuget


REPOS

Repositories (aka Repos, aka galleries)
PSGallery: self publish repo for PowerShell users. While this is a MS platform, it is not trusted automatically as there is no code review.
NuGet: self publish repo for PowerShell and .Net users. While this is a MS platform, it is not trusted automatically as there is no code review.
Chocolatey: both a packageprovider and a repo, chocolately is an independent provider free from large corporation regulation.
get-packagesource

To install packagesource:
Register-PackageSource -Name Nuget -Location "http://www.nuget.org/api/v2" -ProviderName Nuget

But there is a newer version of Nuget for newer clients. So let's un-register:
unRegister-PackageSource NuGet

To install packagesource:
register-PackageSource -Name Nuget -Location "https://api.nuget.org/v3/index.json" -ProviderName Nuget


INSTALLATION

There are a few ways to install PowerShell v7:

1-Winget:
winget install PowerShell

2-PDQ:
PowerShell is available in the PDQ Library/Repo. Simply download the PowerShell Package and deploy to as many systems as needed.

3-PowerShell:
PowerShell-v5 can be used to install Powershell-v7 with the following one-liner:
Invoke-Expression "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

4-GitHub
You can manually download the msi file at GitHub:
wget https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/PowerShell-7.1.4-win-x64.msi -outfile PowerShell-7.1.4-win-x64.msi
msiexec.exe /i "PowerShell-7.1.4-win-x64.msi" ALLUSERS=1 /qn /norestart /log output.log

Once installed, PowerShell-v5 and PowerShell-v7 will co-exist and run at the same time.


INSPECT ENVIRONMENT

To inspect some of PowerShell items, run the following:

$env:psmodulepath -split(';')

To see the current version:
$PSVersionTable

To list the modules in the current session:
get-module

To get the modules that are installed on the system through PowerShellGet:
get-installedmodule

To get the modules that are installed on the system but not yet imported into the current session. Note that Get-Module looks for available modules in the path specified by the $env:PSModulePath environment variable as listed above:
get-module -listavailable

Some modules are built-in modules and automatically installed with Powershell.

You will see in the list is PowerShellGet. The PowerShellGet module is the module used to discovering, installing, updating and publishing other PowerShell modules.
To get the commands in a module:
Get-Command -Module <module-name>
Get-Command -Module PackageManagement
Get-Command -Module PowerShellGet

To get help with the commands:
Get-Help <command-name>
Get-Help <command-name> -Online

And to import a module into the session:
Import-Module <module-name>

To get the repos that are available on the system:
get-psrepository

NOTES

https://4sysops.com/archives/how-to-install-and-upgrade-to-powershell-71/
https://docs.microsoft.com/en-us/powershell/module/powershellget/?view=powershell-7.1
https://www.red-gate.com/simple-talk/sysadmin/powershell/managing-packages-using-windows-powershell/
https://www.youtube.com/playlist?app=desktop&list=PLyJiOytEPs4etH7Ujq7PU7jlOlHL-9RmV

Contact Dak Networks

We are not taking on new clients at this time.