microsoft / Microsoft365DSC

Manages, configures, extracts and monitors Microsoft 365 tenant configurations
https://aka.ms/M365DSC
MIT License
1.64k stars 504 forks source link

Issues while using Start-DscConfiguration #1562

Closed headcra6 closed 2 years ago

headcra6 commented 3 years ago

Hi, I'm working on a new resource implementation and facing an issue with final tests of how the exported resource can be applied with use of Start-DscConfiguration My initial setup:

  1. Install original Microsoft365DSC module in my user folder %USERPROFILE%\Documents\PowerShell\Modules\
  2. Copied my new resource to \DSCResources\
  3. Successfully exported resources with Export-M365DSCConfiguration
  4. Successfully generated mof for resource
  5. Failed. Start-DscConfiguration "" -Wait -Verbose -Force

What was observed: Issue#1 Once started failed with InvalidOperation: The PowerShell DSC resource MSFT_<ResourceName> from module <Microsoft365DSC,1.21.1110.1> does not exist at the PowerShell module path nor is it registered as a WMI DSC resource. It was partially solved but in not that obvious way. I Installed the module here "%ProgramFiles%\WindowsPowerShell\Modules\" and copied my resource here. The issue with "resource not found" disappeared, but other issues appeared. However, it worth mentioning that even if I start this cmdlet from PS7 console it detects resource only if it located in per-machine PS 5 module path. Looks like it was hardcoded somehow Issue#2 After resource was detected the following errors appeared:

ObjectNotFound: The 'Add-M365DSCTelemetryEvent' command was found in the module 'Microsoft365DSC', but the module could not be loaded. For more information, run 'Import-Module Microsoft365DSC'.
ObjectNotFound: The 'New-M365DSCConnection' command was found in the module 'Microsoft365DSC', but the module could not be loaded. For more information, run 'Import-Module Microsoft365DSC'.
ObjectNotFound: The 'Add-M365DSCTelemetryEvent' command was found in the module 'Microsoft365DSC', but the module could not be loaded. For more information, run 'Import-Module Microsoft365DSC'.
ObjectNotFound: The 'Convert-M365DscHashtableToString' command was found in the module 'Microsoft365DSC', but the module could not be loaded. For more information, run 'Import-Module Microsoft365DSC'.
ObjectNotFound: The 'Convert-M365DscHashtableToString' command was found in the module 'Microsoft365DSC', but the module could not be loaded. For more information, run 'Import-Module Microsoft365DSC'.
ObjectNotFound: The 'Test-M365DSCParameterState' command was found in the module 'Microsoft365DSC', but the module could not be loaded. For more information, run 'Import-Module Microsoft365DSC'.
InvalidOperation: The PowerShell DSC resource '[<resource>]<id>' with SourceInfo '<path to generated ps1>::33::9::<resource>' threw one or more non-terminating errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
CimException: The SendConfigurationApply function did not succeed.

Direct call of mentioned cmdlets works, at least asking for params

Could you please advise on above?

Thanks

RuudGijsbers commented 3 years ago

Hi @headcra6 , what happens when you import the module as the error message states? If that doesn't work, you can try to install the modules again, but then in the device context. Install-Module Microsoft365DSC -Force. After that you can try again.

headcra6 commented 3 years ago

Unfortunately, it doesn't help. The command Install-Module Microsoft365DSC -Force installed everything in my profile it is the default behavior I used Install-Module Microsoft365DSC -Force -Scope AllUsers. It installs in PS7 Modules since I'm using it in development.. And the curious thing here it fails. I find a workaround finally but it looks like some hardcodes are in place. What have I done:

  1. Remove Microsoft365DSC module and its dependencies from all module folder both in PS7 and PS5 folders and in user folders as well.
  2. Installed Microsoft365DSC from the scratch to the AllUsers scope
  3. Since I used PS7 I MOVED all modules from PS7 Modules folder to PS5 folder After that, it starts working in PS7. Really weird why it skips all other locations except this "%ProgramFiles%\WindowsPowerShell\Modules", this is a topic for discussions I guess
NikCharlebois commented 2 years ago

It really depends on how environment variables are configured. It shouldn't matter if you are using PS5 or PS7, when running:

Get-Module Microsoft365DSC -ListAvailable

You should only ever get one entry back.

gabriel-rech commented 10 months ago

Hi! It must have something to do with the localhost node when running Start-DSCConfig, no?

I realized it runs PS5.1 in localhost, even if you execute the cmdlet in PS7.