added demo for using Windows PowerShell modules (#4886)

* added demo for using Windows PowerShell modules

* fix spelling

* address PR feedback

* address PR feedback

* added WindowsPSModulePath to dictionary
This commit is contained in:
Steve Lee 2017-10-03 10:47:05 -07:00 committed by Aditya Patwardhan
parent ee902a649e
commit 464d6879b7
2 changed files with 61 additions and 0 deletions

View file

@ -432,6 +432,13 @@ journalctl
SystemD
#endregion
#region demos/WindowsPowerShellModules/README.md Overrides
- demos/WindowsPowerShellModules/README.md
PowerShellGallery
PSSnapins
WindowsPSModulePath
#endregion
#region docker/README.md Overrides
- docker/README.md
andschwa's

View file

@ -0,0 +1,54 @@
# Using Windows PowerShell modules with PowerShell Core
## Windows PowerShell vs PowerShell Core
Existing Windows PowerShell users are familiar with the large number of modules available, however, they are not necessarily compatible with PowerShell Core.
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/).
Windows PowerShell 5.1 is based on .Net Framework 4.6.1, while PowerShell Core is based on .Net Core 2.0.
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).
## Importing a Windows PowerShell module
Since compatibility cannot be ensured, PowerShell Core, by default, does not look in the Windows PowerShell module path to find those modules.
However, advanced users can explicitly enable PowerShell Core to include the Windows PowerShell module path and attempt to import those modules.
First, install the [WindowsPSModulePath](https://www.powershellgallery.com/packages/WindowsPSModulePath) module from the PowerShellGallery:
```powershell
Install-Module WindowsPSModulePath -Scope CurrentUser
```
Then run `Add-WindowsPSModulePath` cmdlet to add the Windows PowerShell module path to your PowerShell Core module path:
```powershell
Add-WindowsPSModulePath
```
Note that this is only effective in the current PowerShell session.
If you want to persist this, you can add `Add-WindowsPSModulePath` to your profile:
```powershell
"Add-WindowsPSModulePath" >> $profile
```
Once the module path has been updated, you can list available modules:
```powershell
Get-Module -ListAvailable
```
Note that PowerShell Core is not aware which Windows PowerShell modules will work and which will not so all are listed.
We plan to improve this experience in the future.
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:
```powershell
Get-VM
# this will automatically load the Hyper-V module
```
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.
## How you can help
Provide comments on Windows PowerShell modules that work or don't work in our [tracking issue](https://github.com/PowerShell/PowerShell/issues/4062).