PowerShell: Unable to import ActiveDirectory module in PowerShell daily20230225.2 build
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
After installing the latest PowerShell Daily build (daily20230225.2) I am unable to import the ActiveDirectory
module
Import-Module ActiveDirectory
Expected behavior
Module should import with no error.
Actual behavior
Import-Module: Attempting to perform the InitializeDefaultDrives operation on the 'ActiveDirectory' provider failed.
Error details
Import-Module: Attempting to perform the InitializeDefaultDrives operation on the 'ActiveDirectory' provider failed.
PS C:\Users\wojang> Get-Error
Exception :
Type : System.Management.Automation.ProviderInvocationException
ProviderInfo : Microsoft.ActiveDirectory.Management\ActiveDirectory
ErrorRecord :
Exception :
Type : System.TypeInitializationException
TypeName : System.ServiceModel.Diagnostics.TraceUtility
TargetSite :
Name : SetEtwProviderId
DeclaringType : System.ServiceModel.Diagnostics.TraceUtility, System.ServiceModel, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
MemberType : Method
Module : System.ServiceModel.dll
Message : The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.
InnerException :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file
is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config
file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name.
For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The
machine.config file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the
section name. For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors : …
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The
machine.config file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the
section name. For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config
file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name.
For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file
is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
TargetSite :
Name : UnsafeGetSectionNoTrace
DeclaringType : System.ServiceModel.Configuration.ConfigurationHelpers, System.ServiceModel, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089
MemberType : Method
Module : System.ServiceModel.dll
Source : System.ServiceModel
HResult : -2146232062
StackTrace :
at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetSectionNoTrace(String sectionPath)
at System.ServiceModel.Configuration.DiagnosticSection.UnsafeGetSectionNoTrace()
at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
at System.ServiceModel.Diagnostics.TraceUtility..cctor()
Source : System.ServiceModel
HResult : -2146233036
StackTrace :
at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
at System.ServiceModel.ChannelFactory..ctor()
at System.ServiceModel.ChannelFactory`1..ctor(Type channelType)
at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress)
at Microsoft.ActiveDirectory.Management.AdwsConnection.InitializeChannel[TChannel](TChannel& channel, ChannelFactory`1& chFactory, String
endpointName, CommunicationException& commException)
at Microsoft.ActiveDirectory.Management.AdwsConnection.SearchAnObject(ADSearchRequest request)
at Microsoft.ActiveDirectory.Management.AdwsConnection.Search(ADSearchRequest request)
at Microsoft.ActiveDirectory.Management.ADWebServiceStoreAccess.Microsoft.ActiveDirectory.Management.IADSyncOperations.Search(ADSessionHandle
handle, ADSearchRequest request)
at Microsoft.ActiveDirectory.Management.ADObjectSearcher.GetRootDSE(ICollection`1 propertyList, Boolean propertyNamesOnly)
at Microsoft.ActiveDirectory.Management.ADObjectSearcher.GetRootDSE(ICollection`1 propertyList)
at Microsoft.ActiveDirectory.Management.Provider.ADProvider.GetRootDSE(ADSessionInfo sessionInfo, ICollection`1 propertiesToRetrieve)
at Microsoft.ActiveDirectory.Management.Provider.ADProvider.GetRootDSE(ADSessionInfo sessionInfo)
at Microsoft.ActiveDirectory.Management.Provider.ADProvider.InitializeDefaultDrives()
at System.Management.Automation.SessionStateInternal.InitializeProvider(CmdletProvider providerInstance, ProviderInfo provider,
CmdletProviderContext context)
CategoryInfo : InvalidOperation: (:) [], TypeInitializationException
FullyQualifiedErrorId : InitializeDefaultDrivesException
Message : Attempting to perform the InitializeDefaultDrives operation on the 'ActiveDirectory' provider failed.
InnerException :
Type : System.TypeInitializationException
TypeName : System.ServiceModel.Diagnostics.TraceUtility
TargetSite :
Name : SetEtwProviderId
DeclaringType : System.ServiceModel.Diagnostics.TraceUtility, System.ServiceModel, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
MemberType : Method
Module : System.ServiceModel.dll
Message : The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.
InnerException :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file
is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config
file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name.
For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors :
Type : System.Configuration.ConfigurationErrorsException
Message : The 'system.serviceModel/diagnostics' configuration section cannot be created. The
machine.config file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the
section name. For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
Errors : …
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The
machine.config file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the
section name. For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config
file is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name.
For Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file
is missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is
missing information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For
Windows Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
HResult : -2146232062
BareMessage : The 'system.serviceModel/diagnostics' configuration section cannot be created. The machine.config file is missing
information. Verify that this configuration section is properly registered and that you have correctly spelled the section name. For Windows
Communication Foundation sections, run ServiceModelReg.exe -i to fix this error.
TargetSite :
Name : UnsafeGetSectionNoTrace
DeclaringType : System.ServiceModel.Configuration.ConfigurationHelpers, System.ServiceModel, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
MemberType : Method
Module : System.ServiceModel.dll
Source : System.ServiceModel
HResult : -2146232062
StackTrace :
at System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetSectionNoTrace(String sectionPath)
at System.ServiceModel.Configuration.DiagnosticSection.UnsafeGetSectionNoTrace()
at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
at System.ServiceModel.Diagnostics.TraceUtility..cctor()
Source : System.ServiceModel
HResult : -2146233036
StackTrace :
at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
at System.ServiceModel.ChannelFactory..ctor()
at System.ServiceModel.ChannelFactory`1..ctor(Type channelType)
at System.ServiceModel.ChannelFactory`1..ctor(Binding binding, EndpointAddress remoteAddress)
at Microsoft.ActiveDirectory.Management.AdwsConnection.InitializeChannel[TChannel](TChannel& channel, ChannelFactory`1& chFactory, String
endpointName, CommunicationException& commException)
at Microsoft.ActiveDirectory.Management.AdwsConnection.SearchAnObject(ADSearchRequest request)
at Microsoft.ActiveDirectory.Management.AdwsConnection.Search(ADSearchRequest request)
at Microsoft.ActiveDirectory.Management.ADWebServiceStoreAccess.Microsoft.ActiveDirectory.Management.IADSyncOperations.Search(ADSessionHandle
handle, ADSearchRequest request)
at Microsoft.ActiveDirectory.Management.ADObjectSearcher.GetRootDSE(ICollection`1 propertyList, Boolean propertyNamesOnly)
at Microsoft.ActiveDirectory.Management.ADObjectSearcher.GetRootDSE(ICollection`1 propertyList)
at Microsoft.ActiveDirectory.Management.Provider.ADProvider.GetRootDSE(ADSessionInfo sessionInfo, ICollection`1 propertiesToRetrieve)
at Microsoft.ActiveDirectory.Management.Provider.ADProvider.GetRootDSE(ADSessionInfo sessionInfo)
at Microsoft.ActiveDirectory.Management.Provider.ADProvider.InitializeDefaultDrives()
at System.Management.Automation.SessionStateInternal.InitializeProvider(CmdletProvider providerInstance, ProviderInfo provider,
CmdletProviderContext context)
HResult : -2146233087
TargetObject : Microsoft.ActiveDirectory.Management\ActiveDirectory
CategoryInfo : InvalidOperation: (Microsoft.ActiveDir…ent\ActiveDirectory:ProviderInfo) [Import-Module], ProviderInvocationException
FullyQualifiedErrorId : InitializeDefaultDrivesException,Microsoft.PowerShell.Commands.ImportModuleCommand
InvocationInfo :
MyCommand : Import-Module
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 1
Line : import-Module ActiveDirectory
PositionMessage : At line:1 char:1
+ import-Module ActiveDirectory
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : import-Module
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
Environment data
Name Value
---- -----
PSVersion 7.4.0-daily20230225.2
PSEdition Core
GitCommitId 7.4.0-daily20230225.2
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 16 (9 by maintainers)
I agree. Leaving it as is will break a lot of scripts.
For this particular issue, I guess we will have to lock the versions of the
System.ServiceModel.xxxxx
NuGet package to be 4.x.x. But supportingActiveDirectory
will be fragile in long term, as it may stop working due to a different change in .NET or the packages pwsh depends on.I think we should plan ahead. One option is that we lock the version of those packages in 7.4 to keep
ActiveDirectory
working in this LTS, but at the same time, we start to advertise via blog and other channels thatActiveDirectory
will stop working starting from 7.5 and up. It would be the best ifActiveDirectory
module can be updated to work on both Windows PowerShell and pwsh natively.Removed the “Resolution” label. We need to keep this issue open and verify if this is caused by moving to .NET 8. /cc @adityapatwardhan @TravisEz13 @SeeminglyScience
So I’ve just taken a stab at investigating this and here is what I’ve found.
The error occurs in
System.ServiceModel
and when using a tool like dnspy I put a breakpoint near the problem and found that different assemblies were being loaded. In pwsh 7.3 it loads it fromSystem.Private.ServiceModel.dll
but for the 7.4 preview it’s using a copy in the GAC. This GAC copy is relying on some configuration file which isn’t present and then causing an error when it tries to get an entry in that file.I’m not sure why it’s using the GAC
System.ServiceModel
as I can load theSystem.Private.ServiceModel.dll
in the pwsh dir just fine. I tried stepping through theResolve
method inCorePsAssemblyLoadContext
to figure out why this was happening but nothing relaly jumped out at me. I did notice thatResolve
was called withSystem.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
on the preview pwsh version when it loaded the AD cmdlet dll whereas on 7.3 it did not so something is suspicious there to me.Here is a trace of the assembly resolution when pwsh goes to load the AD cmdlets (top is 7.4 and bottom is 7.3).
I’m not sure what else to investigate but there is something going on with how assemblies are being loaded here.
This is a serious issue. Many organizations vested a lot of effort to migrate their environment from 5.1 to 7. The removal of support for AD module on future PS version would be, in my opinion, disastrous and would damage the PS ecosystem. I fully agree with @jborean93 that the solution needs to be found that makes sure that AD module is fully supported on future PS versions.
Even if it isn’t deemed to be a real regression I would very much argue that pwsh should solve this problem before 7.4 is actually released due to its popularity on Windows. Going back to the pre Server 2019 days where it used the implicit remoting module is going to break a lot of people’s scripts.
@jborean93 Thank you so much for the investigation!
The package
System.ServiceModel.Primitives
referenced inMicrosoft.PowerShell.SDK.csproj
was the version4.x.0
previously, and became6.0.0-preview1.23060.3
after moving to .NET 8.In the
4.x.0
versions, theSystem.ServiceModel.Primitives
package would pull in the facade assemblySystem.ServiceModel.dll
, so this assembly was available under$PSHome
.In the
6.0.0-preview1.23060.3
version, theSystem.ServiceModel.Primitives
package pulls inSystem.ServiceModel.Primitives.dll
instead, so no moreSystem.ServiceModel.dll
under$PSHome
. This is why you started to seeSystem.ServiceModel.dll
being loaded from GAC now.So, this regression is caused by the changes in the latest
System.ServiceModel.Primitives
preview NuGet packages. But I’m not sure if this deems to be a real regression becuase theActiveDirectory
module targets .NET Framework, not .NET, and thus it’s sort of by accident that it worked before.Looping in @SeeminglyScience and @SteveL-MSFT to share their thoughts.