Skip to content

Parse errors related to "Import-DSCResource -ModuleName <somemodule>" #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kapilmb opened this issue May 3, 2016 · 0 comments
Closed
Assignees
Milestone

Comments

@kapilmb
Copy link

kapilmb commented May 3, 2016

Consider a file named, test1.ps1, with the following content.

Configuration SomeNode
{    
    Import-DscResource -ModuleName xActiveDirectory
    Node "NodeName" {
        xADDomain "DomainController" 
        { 
            DomainName = "DomainName" 
            DomainAdministratorCredential = "Credential" 
            SafemodeAdministratorPassword = "password" 
        } 
    }
}
PS>Invoke-ScriptAnalyzer -Path c:\tmp\test1.ps1
Invoke-ScriptAnalyzer : Parse error in file c:\tmp\test1.ps1:  Could not find the module 'xActiveDirectory' at line 3 column 5.
At line:1 char:1
+ Invoke-ScriptAnalyzer -Path c:\tmp\test1.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (ModuleNotFoundDuringParse:String) [Invoke-ScriptAnalyzer], ParseException
    + FullyQualifiedErrorId : Parse error in file c:\tmp\test1.ps1:  Could not find the module 'xActiveDirectory' at line 3 column 5.,Microsoft.Windows.PowerShell.ScriptAna
   lyzer.Commands.InvokeScriptAnalyzerCommand

Invoke-ScriptAnalyzer : Parse error in file c:\tmp\test1.ps1:  Undefined DSC resource 'xADDomain'. Use Import-DSCResource to import the resource at line 5 column 9.
At line:1 char:1
+ Invoke-ScriptAnalyzer -Path c:\tmp\test1.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (ResourceNotDefined:String) [Invoke-ScriptAnalyzer], ParseException
    + FullyQualifiedErrorId : Parse error in file c:\tmp\test1.ps1:  Undefined DSC resource 'xADDomain'. Use Import-DSCResource to import the resource at line 5 column 9.,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand

This happens because powershell parser cannot find the relevant symbols. However, if the module xActiveDirectory were to be in PSModulePath, the parser wouldn't throw this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant