Powershell: Powershell DSC does not work on OSX

Created on 12 Oct 2019  Â·  10Comments  Â·  Source: PowerShell/PowerShell

Anything related to DSC does not seem to work on OSX because of a dependency problem. Related to https://github.com/PowerShell/MMI/issues/33

It is not a problem with Publish-AzVMDscConfiguration, but this happens with anything DSC related.

Steps to reproduce

Publish-AzVMDscConfiguration ".\configuread.ps1" -OutputArchivePath ".\configuread.ps1.zip"

Expected behavior

No errors

Actual behavior

Publish-AzVMDscConfiguration : Configuration script '/Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1' contained parse errors:
At /Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1:1 char:15
+ Configuration NewADForest
+               ~~~~~~~~~~~
System.IO.DirectoryNotFoundException: Unable to find DSC schema store at /etc/opt/omi/conf/dsc/configuration. Please ensure PS DSC for Linux is installed.
   at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.Initialize(Collection`1 errors, List`1 modulePathList)
   at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.LoadDefaultCimKeywords(Dictionary`2 functionsToDefine, Collection`1 errors, List`1 modulePathList, Boolean cacheResourcesFromMultipleModuleVersions)
   at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.LoadDefaultCimKeywords(Collection`1 errors)
   at System.Management.Automation.Language.Parser.ConfigurationStatementRule(IEnumerable`1 customAttributes, Token configurationToken)
At /Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1:2 char:1
+ {
+ ~
Unexpected token '{' in expression or statement.
At /Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1:8 char:52
+         [System.Management.Automation.PSCredential]
+                                                    ~
Missing closing ')' in expression.
At /Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1:9 char:9
+         $Credential,
+         ~~~~~~~~~~~
Unexpected token '$Credential' in expression or statement.
At /Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1:18 char:5
+     )
+     ~
Unexpected token ')' in expression or statement.
At /Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1:63 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
At /Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1:6 char:9
+         [Parameter(Mandatory = $true)]
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected attribute 'Parameter'.
At /Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1:7 char:9
+         [ValidateNotNullOrEmpty()]
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected attribute 'ValidateNotNullOrEmpty'.
At /Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1:12 char:9
+         [Parameter(Mandatory = $true)]
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected attribute 'Parameter'.
At /Users/jhk/Workspace/tf-azure-dsc/dsc/configuread.ps1:13 char:9
+         [ValidateNotNullOrEmpty()]
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected attribute 'ValidateNotNullOrEmpty'.
At line:1 char:1
+ Publish-AzVMDscConfiguration ".\configuread.ps1" -OutputArchivePath " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ParserError: (:) [Publish-AzVMDscConfiguration], ParseException
+ FullyQualifiedErrorId : DscConfigurationParseError,Microsoft.Azure.Commands.Compute.Extension.DSC.PublishAzureVMDscConfigurationCommand

Environment data

I tried both the stable version and the preview.

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.4
PSEdition                      Core
GitCommitId                    7.0.0-preview.4
OS                             Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Area-DSC Issue-Question

Most helpful comment

Any update on this? Dsc on MacOS is unusable at this point.

All 10 comments

@amitsara Is this issue being investigated? Travis Plunk mentioned you were looking into this under https://github.com/PowerShell/MMI/issues/33 and while that issue was closed as OMI is obsolete, the issues still exist and make editing DSC configs on MacOS difficult.

Running into this in Azure Cloud Shell. How can I use DSC in the cloud shell then?

This is still an issue on the most recent RC.

image

image

Any update on this? Dsc on MacOS is unusable at this point.

@mgreenegit, @nitinbps, is this something you can help?

This is an issue for us as well. @mgreenegit @nitinbps

@PleaseStopAsking - the way the token errors are showing up makes me think this is more of a unix conversion issue. Have you tried running unix2dos or dos2unix on your .ps1 before running the Start-DscConfiguration? I've seen that the DSC configuration when using an ARM Template will error out with a vanilla configuration file developed on a Mac, but will work fine with one developed on a windows device. The extra line breaks in the configuration file might actually be the cause of the weird schema and parsing errors.

I didn't try it myself, I ended up just doing everything on a windows VM as a work around. This conversion issue sort of came to me after the fact.

same issue with me , updated Az modules and powershel7 as well. still no luck. My understanding is OMi is not used on Mac but for somereason it still expects it ,
System.IO.DirectoryNotFoundException: Unable to find DSC schema store at /etc/opt/omi/conf/dsc/configuration. Please ensure PS DSC for Linux is installed.
at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.Initialize(Collection1 errors, List1 modulePathList)
at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.LoadDefaultCimKeywords(Dictionary2 functionsToDefine, Collection1 errors, List1 modulePathList, Boolean cacheResourcesFromMultipleModuleVersions) at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.LoadDefaultCimKeywords(Collection1 errors)
at System.Management.Automation.Language.Parser.ConfigurationStatementRule(IEnumerable`1 customAttributes, Token configurationToken)PowerShell
Peek Problem (⌥F8)

@thecherrytree I am actually not even getting to the point of executing them when I get the error. I am seeing the error when simply viewing my .ps1 files within VSCode. I don't currently execute them on MacOS, just develop them there and then execute on Windows boxes elsewhere.

Here's output when running a good ol fashioned 'Get-DscResource'.

MacOS Catalina (10.15.6) running PowerShell 7.0.3

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Darwin 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul  5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS> Get-DscResource

PSMessageDetails      :
Exception             : System.Management.Automation.MethodInvocationException: Exception calling "ImportCimKeywordsFromModule" with "5" argument(s): "Unable to load shared
                        library 'libmi' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable:
                        dlopen(liblibmi, 1): image not found"
                         ---> System.DllNotFoundException: Unable to load shared library 'libmi' or one of its dependencies. In order to help diagnose loading problems,
                        consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibmi, 1): image not found
                           at Microsoft.Management.Infrastructure.Native.NativeMethods.MI_Application_InitializeV1(UInt32 flags, String applicationID, IndirectPtr
                        extendedError, DirectPtr application)
                           at Microsoft.Management.Infrastructure.Native.MI_Application.Initialize(String applicationId, MI_Instance& extendedError, MI_Application& application)
                           at Microsoft.Management.Infrastructure.Internal.CimApplication.GetApplicationHandle()
                           at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
                        --- End of stack trace from previous location where exception was thrown ---
                           at System.Lazy`1.CreateValue()
                           at Microsoft.Management.Infrastructure.Internal.CimApplication.get_Handle()
                           at Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer..ctor()
                           at Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer.Create()
                           at Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser..ctor(OnClassNeeded onClassNeeded)
                           at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.ImportClasses(String path, Tuple`2 moduleInfo, Collection`1 errors, Boolean
                        importInBoxResourcesImplicitly)
                           at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.ImportCimKeywordsFromModule(PSModuleInfo module, String resourceName,
                        String& schemaFilePath, Dictionary`2 functionsToDefine, Collection`1 errors)
                           at CallSite.Target(Closure , CallSite , Type , Object , Object , PSReference , Object , Object )
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName,
                        Int32 numArgs, MemberInfo memberInfo)
                           at CallSite.Target(Closure , CallSite , Type , Object , Object , PSReference , Object , Object )
                           at ImportCimAndScriptKeywordsFromModule(Closure , FunctionContext )
TargetObject          :
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : DllNotFoundException
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at ImportCimAndScriptKeywordsFromModule, /usr/local/microsoft/powershell/7/Modules/PSDesiredStateConfiguration/PSDesiredStateConfiguration.psm1: line
                        2527
                        at Get-DscResource<Begin>, /usr/local/microsoft/powershell/7/Modules/PSDesiredStateConfiguration/PSDesiredStateConfiguration.psm1: line 3980
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

It would be great to be able to develop DSC Configurations for Windows on a Mac.

Was this page helpful?
0 / 5 - 0 ratings