Skip to content

Commit 464d687

Browse files
SteveL-MSFTadityapatwardhan
authored andcommitted
added demo for using Windows PowerShell modules (PowerShell#4886)
* added demo for using Windows PowerShell modules * fix spelling * address PR feedback * address PR feedback * added WindowsPSModulePath to dictionary
1 parent ee902a6 commit 464d687

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

.spelling

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,13 @@ journalctl
432432
SystemD
433433
#endregion
434434

435+
#region demos/WindowsPowerShellModules/README.md Overrides
436+
- demos/WindowsPowerShellModules/README.md
437+
PowerShellGallery
438+
PSSnapins
439+
WindowsPSModulePath
440+
#endregion
441+
435442
#region docker/README.md Overrides
436443
- docker/README.md
437444
andschwa's
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Using Windows PowerShell modules with PowerShell Core
2+
3+
## Windows PowerShell vs PowerShell Core
4+
5+
Existing Windows PowerShell users are familiar with the large number of modules available, however, they are not necessarily compatible with PowerShell Core.
6+
More information regarding compatibility is in a [blog post](https://blogs.msdn.microsoft.com/powershell/2017/07/14/powershell-6-0-roadmap-coreclr-backwards-compatibility-and-more/).
7+
8+
Windows PowerShell 5.1 is based on .Net Framework 4.6.1, while PowerShell Core is based on .Net Core 2.0.
9+
Although both adhere to .Net Standard 2.0 and can be compatible, some modules may be using APIs or cmdlets not supported on CoreCLR or using APIs from Windows PowerShell that have been deprecated and removed from PowerShell Core (for example, PSSnapins).
10+
11+
## Importing a Windows PowerShell module
12+
13+
Since compatibility cannot be ensured, PowerShell Core, by default, does not look in the Windows PowerShell module path to find those modules.
14+
However, advanced users can explicitly enable PowerShell Core to include the Windows PowerShell module path and attempt to import those modules.
15+
16+
First, install the [WindowsPSModulePath](https://www.powershellgallery.com/packages/WindowsPSModulePath) module from the PowerShellGallery:
17+
18+
```powershell
19+
Install-Module WindowsPSModulePath -Scope CurrentUser
20+
```
21+
22+
Then run `Add-WindowsPSModulePath` cmdlet to add the Windows PowerShell module path to your PowerShell Core module path:
23+
24+
```powershell
25+
Add-WindowsPSModulePath
26+
```
27+
28+
Note that this is only effective in the current PowerShell session.
29+
If you want to persist this, you can add `Add-WindowsPSModulePath` to your profile:
30+
31+
```powershell
32+
"Add-WindowsPSModulePath" >> $profile
33+
```
34+
35+
Once the module path has been updated, you can list available modules:
36+
37+
```powershell
38+
Get-Module -ListAvailable
39+
```
40+
41+
Note that PowerShell Core is not aware which Windows PowerShell modules will work and which will not so all are listed.
42+
We plan to improve this experience in the future.
43+
You can now import a Windows PowerShell module or just execute a known cmdlet and allow auto-module loading to take care of importing the module:
44+
45+
```powershell
46+
Get-VM
47+
# this will automatically load the Hyper-V module
48+
```
49+
50+
Most of the cmdlets based on CDXML will work just fine, as well as some C# based cmdlets that happen to be .NET Standard 2.0 compatible (for example, Hyper-V module) but the Active Directory module, for example, won't work.
51+
52+
## How you can help
53+
54+
Provide comments on Windows PowerShell modules that work or don't work in our [tracking issue](https://github.com/PowerShell/PowerShell/issues/4062).

0 commit comments

Comments
 (0)