Last active
October 17, 2018 10:48
-
-
Save SteveL-MSFT/3fd2e9db5424282df5b11c33f08699a8 to your computer and use it in GitHub Desktop.
Demos for Windows PowerShell compatibility with PowerShell Core 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Single script for Windows PowerShell and PowerShell Core | |
## Use PSEdition | |
@' | |
if ($PSVersionTable.PSEdition -eq "Core") | |
{ "PowerShell Core!" } | |
else | |
{ "Windows PowerShell!" } | |
'@ > both.ps1 | |
## Handling breaking changes | |
### Get-Content example | |
Get-Content ./both.ps1 –Encoding Byte | |
Get-Content ./both.ps1 –AsByteStream | |
### Leverage PSEdition and splatting | |
@' | |
$IsPSCore = $PSVersionTable.PSEdition -eq 'Core' | |
$params = @{ Path = './content.ps1' } | |
if ($IsPSCore) | |
{ | |
$params += @{ AsByteStream = $true } | |
} | |
else | |
{ | |
$params += @{ Encoding = 'Byte' } | |
} | |
Get-Content @params | |
'@ > ./content.ps1 | |
# Windows Server 2019 and Windows 10 Oct Update | |
## 1900+ cmdlets in Windows work in PowerShell Core 6.1 | |
Get-module –listavailable | |
## AD Module | |
Get-ADComputer $env:COMPUTERNAME | |
## AppX Module | |
Get-AppPackage | Select-Object Name | |
## Issues? | |
start https://github.com/PowerShell/PowerShellModuleCoverage/issues | |
# Use Windows Compatibility Module | |
## PKI module isn't ported yet | |
Get-module pki -listavailable | |
get-module pki -ListAvailable -SkipEditionCheck | |
Import-module pki –skipeditioncheck | |
New-SelfSignedCertificate -Type Custom -Subject "E=patti.fuller@contoso.com,CN=Patti Fuller" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.4","2.5.29.17={text}email=patti.fuller@contoso.com&upn=pattifuller@contoso.com") -KeyUsage DataEncipherment -KeyAlgorithm RSA -KeyLength 2048 -SmimeCapabilities -CertStoreLocation "Cert:\CurrentUser\My" | |
## Use PKI module successfully | |
Install-module windowscompatibility -allowprerelease -scope CurrentUser | |
Import-WinModule pki | |
Get-Command -Module pki | |
$cert = New-SelfSignedCertificate -Type Custom -Subject "E=patti.fuller@contoso.com,CN=Patti Fuller" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.4","2.5.29.17={text}email=patti.fuller@contoso.com&upn=pattifuller@contoso.com") -KeyUsage DataEncipherment -KeyAlgorithm RSA -KeyLength 2048 -SmimeCapabilities -CertStoreLocation "Cert:\CurrentUser\My" | |
$cert | |
$cert | Remove-Item | |
## PowerShell modules with missing cmdlets | |
Get-Clipboard | |
Get-Command Get-Clipboard | select Source | |
Import-WinModule microsoft.powershell.management | |
'hello' | Set-Clipboard | |
Get-Clipboard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment