You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Import Microsoft.PowerShell.Management version 3.1 does not allow use of Write-EventLog #8026
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.
Write-EventLog function (provided by the Microsoft.PowerShell.Management module version 3.1.0) should be available. As a side note, should i do a get-module on Microsoft.PowerShell.Management version 3.1, and view the exported commands on the module, I can clearly see that Write-EventLog is available. Once I import the 3.1 version Microsoft.PowerShell.Management module, the exported command is not listed as an exported command.
Thanks!
Actual behavior
Write-EventLog is not available.
Environment data
PS C:\Users\test> $psversiontable
Name Value
PSVersion 6.1.0
PSEdition Core
GitCommitId 6.1.0
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
I've successfully imported other modules from the 5.1 release without having to import-Module WindowsCompatibility. For example, the "Import-Module netadapter" command will import the netadapter module from 5.1 and I have available all the netadapter commands - i.e. Get-NetAdapter. Why can I not do this with the older Microsoft.PowerShell.Management module?
Windows 10 1809 is released with some Windows PowerShell modules compatible with PowerShell Core 6.1. Such modules have a special flag. Rest of modules should be used by means of proxing.
Modules packaged with distributive like Microsoft.PowerShell.Management is core modules and can not be loaded in other PowerShell versions.
Thank you iSazonov, if that is the case, the import-module command should throw an error/message to the user stating that the conflicting module can not be imported. As of now, it imports the module without exposing the exported commands (with no message/indication that anything is wrong).
I think there is a bug in that PSCore6 shouldn't look into the Windows PowerShell core modules as it gives confusing output where a command appears to be available, but won't actually work as module analysis finds the cmdlet in the Windows PowerShell module, but module loading looks in the PSCore6 version and doesn't find it. cc Rob Holt (@rjmholt)
However, the expected way to get this to work IS with the WindowsCompatibility module (which isn't shipped by default with PSCore6.1). You need to do:
The Windows PowerShell Microsoft.PowerShell.Management module has been marked as Core compatible (the manifest of the module confirms this)
gmo Microsoft.PowerShell.Management | fl * reports the correct Path property (in the Windows PowerShell home dir), but (gmo -FullyQualifiedName @{ ModuleName = Microsoft.PowerShell.Management; MaximumVersion = '4.0' })[0].ModuleBase gives me the PSCore $PSHOME.
I think we need to:
Look into why the Windows PowerShell module is marked as Core-compatible
Fix whatever the bug is with the ModuleBase property there (probably caused by the same thing as the erroneous load)
Fix autoloading so that if the command could resolve to one that works, it will pick the right one. This is already on my todo list, but it appears there's no explicit issue for it.
I ran a "Import-Module Microsoft.PowerShell.Management -maximumversion 4.0" prior to running the Get-Module command you specified - that way you could view the get-module results for both versions of the Microsoft.PowerShell.Management module.
Yes, it appears that we should not have marked that module as Core in Windows PowerShell and rely on WindowsCompatibility module to use those cmdlets. Rob Holt (@rjmholt) I'll leave it to you to make the fix in Windows.
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.
Activity
iSazonov commentedon Oct 15, 2018
Seems you need to use https://github.com/PowerShell/WindowsCompatibility
cmichaelingram commentedon Oct 15, 2018
Thanks for the quick response iSazonov. That's the way we were doing it - at least until PowerShell Core 6.1 was released. With PS Core 6.1, they rolled the Windows Compatibility pack into the 6.1 release so you shouldn't have to add it in - at least that is my understanding and based on what I'm seeing in practice (https://docs.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-core-61?view=powershell-6).
I've successfully imported other modules from the 5.1 release without having to import-Module WindowsCompatibility. For example, the "Import-Module netadapter" command will import the netadapter module from 5.1 and I have available all the netadapter commands - i.e. Get-NetAdapter. Why can I not do this with the older Microsoft.PowerShell.Management module?
iSazonov commentedon Oct 16, 2018
Windows 10 1809 is released with some Windows PowerShell modules compatible with PowerShell Core 6.1. Such modules have a special flag. Rest of modules should be used by means of proxing.
Modules packaged with distributive like Microsoft.PowerShell.Management is core modules and can not be loaded in other PowerShell versions.
cmichaelingram commentedon Oct 16, 2018
Thank you iSazonov, if that is the case, the import-module command should throw an error/message to the user stating that the conflicting module can not be imported. As of now, it imports the module without exposing the exported commands (with no message/indication that anything is wrong).
iSazonov commentedon Oct 16, 2018
Steve Lee (@SteveL-MSFT) Please look the feedback.
SteveL-MSFT commentedon Oct 18, 2018
I think there is a bug in that PSCore6 shouldn't look into the Windows PowerShell core modules as it gives confusing output where a command appears to be available, but won't actually work as module analysis finds the cmdlet in the Windows PowerShell module, but module loading looks in the PSCore6 version and doesn't find it. cc Rob Holt (@rjmholt)
However, the expected way to get this to work IS with the WindowsCompatibility module (which isn't shipped by default with PSCore6.1). You need to do:
Then the
Write-EventLogcmdlet will work.iSazonov commentedon Oct 18, 2018
Related PR #7727. Perhaps we need more general fix.
rjmholt commentedon Oct 18, 2018
Chris Ingram (@cmichaelingram) can you execute the following on your machine and paste the results here:
On my machine I'm seeing a few strange things:
Microsoft.PowerShell.Managementmodule has been marked asCorecompatible (the manifest of the module confirms this)gmo Microsoft.PowerShell.Management | fl *reports the correctPathproperty (in the Windows PowerShell home dir), but(gmo -FullyQualifiedName @{ ModuleName = Microsoft.PowerShell.Management; MaximumVersion = '4.0' })[0].ModuleBasegives me the PSCore$PSHOME.I think we need to:
ModuleBaseproperty there (probably caused by the same thing as the erroneous load)cmichaelingram commentedon Oct 18, 2018
Rob Holt (@rjmholt) Sure thing!
I ran a "Import-Module Microsoft.PowerShell.Management -maximumversion 4.0" prior to running the Get-Module command you specified - that way you could view the get-module results for both versions of the Microsoft.PowerShell.Management module.
SteveL-MSFT commentedon Oct 19, 2018
Yes, it appears that we should not have marked that module as
Corein Windows PowerShell and rely on WindowsCompatibility module to use those cmdlets. Rob Holt (@rjmholt) I'll leave it to you to make the fix in Windows.iSazonov commentedon Oct 19, 2018
I see no reason to load core modules from other PowerShell version at all. I think we should block this in PowerShell Core.