0

There seems to be something buggy with DSC and PowerShell Modules.

Resources that use the RemoteDesktop module randomly fail with the following error logged in DSC Operational event log

If I run the same configuration ten times on ten different machines it will fail about half the time. If I rerun it after it fails...it might fail again or it might succeed (meaning it won't run again)

The term 'Get-RDRemoteApp' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Sometimes instead of Get-RDRemoteApp, it logs Get-RDServer...even though I don't call Get-RDServer anywhere in my script. It seems like there is something messed up with how DSC uses PowerShell sessions to invoke resources. If I change the class below to actually launch the required commands by starting a new powershell.exe process, it always works...

[DSCResource()]
class zRemoteApp {
    $ErrorActionPreference = "Stop"

    [DscProperty(Key)]
    [string]$Name = "MyApp"

    [DscProperty()]
    [string]$Path

    [bool]$RemoteAppExists

    [zRemoteApp]Get() {
        Import-Module RemoteDesktop

        $this.RemoteAppExists = [boolean](Get-RDRemoteApp -Alias $this.Name)

        Return $this
    }

    [void]Set() {
        Import-Module RemoteDesktop
        $this.Get()

        Get-RDSessionCollection |% {
            New-RDRemoteApp -CollectionName $_.CollectionName -Alias $this.Name -DisplayName $this.Name -FilePath $Path
        }
    }

    [bool]Test() {    
        $this.Get()
        Return $this.RemoteAppExists
    }
}

Edit - If I use a ScriptBlock it consistently works:

    $job = Start-Job -ScriptBlock {
        param($Name)
        Import-Module RemoteDesktop
        [boolean](Get-RDRemoteApp -Alias $Name)
    } -ArgumentList $this.Name

    $this.RemoteAppExists = $job | Wait-Job | Receive-Job

    Remove-Job $job

    Return $this
Jeff
  • 35,755
  • 15
  • 108
  • 220
  • I cannot seem to reproduce the problem, but I moved the import-module into a constructor ([example](https://gist.github.com/TravisEz13/9e1a6307c334b0fef615048c933fb254)) to reduce the output. What OS are you using? – TravisEz13 May 05 '16 at 05:28
  • Server 2012 R2 - If I change to use Start-Job with a ScriptBlock it consistently works. – Jeff May 05 '16 at 13:21
  • Can you call "Get-SessionCollection" instead of "Get-RDSessionCollection" , "New-RemoteApp" instead of "New-RDRemoteApp" and "Get-RemoteApp" instead of "Get-RDRemoteApp" and try? – N.Gupta May 05 '16 at 17:23
  • what's the difference? – Jeff May 05 '16 at 20:06

0 Answers0