PowerShell / PSDscResources

MIT License
129 stars 53 forks source link

PsDscRunAsCredential with empty password throws error "Object reference not set to an instance of an object." #189

Open mh185277 opened 4 years ago

mh185277 commented 4 years ago

I tried this script:

$cd = @{
    AllNodes = @(    
        @{  
            NodeName = "localhost"
            PsDscAllowPlainTextPassword = $true
        }
    ) 
}

$UserCredential = $(New-Object System.Management.Automation.PSCredential ("Administrator", (New-Object System.Security.SecureString)))

Configuration ConfigLocahost
{

    Import-DscResource -ModuleName PSDscResources

    Node localhost
    {
        Registry FeShowMenus 
        {
            Ensure = "Present"
            Key =  "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
            ValueName = "AlwaysShowMenus"
            ValueData = "1"
            ValueType = "Dword"
            Force = $true
            PsDscRunAsCredential = $UserCredential
        }
    }
}

ConfigLocahost -ConfigurationData $cd -Force
Start-DscConfiguration -Path .\ConfigLocahost -Wait -Verbose -Force

And result is: PowerShell DSC resource MSFT_RegistryResource failed to execute Test-TargetResource functionality with error message: Object reference not set to an instance of an object.

Versions:

PSVersion                      5.1.17763.1007
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.1007
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1