MSDN script not quite right?

Welcome Forums DSC (Desired State Configuration) MSDN script not quite right?

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
3 years, 10 months ago.

  • Author
    Posts
  • #20898

    Participant
    Points: 0
    Rank: Member

    Hello folks!

    I was exploring the compliance server and came across this nugget http://blogs.technet.com/b/privatecloud/archive/2014/08/08/desired-state-configuration-dsc-nodes-deployment-and-conformance-reporting-series-part-3-working-with-the-conformance-endpoint.aspx

    Full script in question:

    Function Get-DscConformanceReport {
        param (
            $Uri = 'http://localhost:9080/PSDSCComplianceServer.svc/Status'
        )
        $response = Invoke-RestMethod -Uri $uri -UseDefaultCredentials -Method Get -Headers @{Accept="application/json"}
        $NodeStatus = $response.value | 
                      Select @{Name='TargetName';Expression={[System.Net.Dns]::GetHostByAddress($_.TargetName).HostName}}, ConfigurationId, NodeCompliant, @{Name='Status';Expression={$statusCode[$_.StatusCode]}}
        
        #Construct HTML 
        $HtmlBody = "'
        $TableContent="TargetNameConfigurationIdNodeComplaintStatus'
        foreach ($Node in $NodeStatus) {
            if (-not ([bool]$Node.NodeCompliant)) {
                $TableContent += "'
            } else {
                $TableContent += "'
            }
            $TableContent += "$($Node.TargetName)$($Node.ConfigurationId)$($Node.NodeCompliant)$($Node.Status)"        
        } 
        $TableContent += ""
        $HtmlBody += $TableContent + ""
    
        #Generate HTML file
        $HtmlBody | Out-File "$env:Temp\DscReport.HTML" -Force
        Start-Process -FilePath iexplore.exe -ArgumentList "$env:Temp\DscReport.HTML"
    }

    I bring the script about modifying the HTML to my ISE and it highlights this section as being erroneous:

        #Construct HTML 
        $HtmlBody = "'
        $TableContent="TargetNameConfigurationIdNodeComplaintStatus'
        foreach ($Node in $NodeStatus) {
            if (-not ([bool]$Node.NodeCompliant)) {
                $TableContent += "'
            } else {
                $TableContent += "'
            }

    Running the above generates this powershell error:

    Function Get-DscConformanceReport {
        param (
            $Uri = 'http://localhost:9080/PSDSCComplianceServer.svc/Status'
        )
        $response = Invoke-RestMethod -Uri $uri -UseDefaultCredentials -Method Get -Headers @{Accept="application/json"}
        $NodeStatus = $response.value | 
                      Select @{Name='TargetName';Expression={[System.Net.Dns]::GetHostByAddress($_.TargetName).HostName}}, ConfigurationId, NodeCompliant, @{Name='Status';Expression={$statusCode[$_.StatusCode]}}
        
        #Construct HTML 
        $HtmlBody = "'
        $TableContent="TargetNameConfigurationIdNodeComplaintStatus'
        foreach ($Node in $NodeStatus) {
            if (-not ([bool]$Node.NodeCompliant)) {
                $TableContent += "'
            } else {
                $TableContent += "'
            }
            $TableContent += "$($Node.TargetName)$($Node.ConfigurationId)$($Node.NodeCompliant)$($Node.Status)"        
        } 
        $TableContent += ""
        $HtmlBody += $TableContent + ""
    
        #Generate HTML file
        $HtmlBody | Out-File "$env:Temp\DscReport.HTML" -Force
        Start-Process -FilePath iexplore.exe -ArgumentList "$env:Temp\DscReport.HTML"
    }
    At line:11 char:20
    +     $TableContent="Target ...
    +                    ~
    The '< ' operator is reserved for future use.
    At line:11 char:31
    +     $TableContent="Target ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Unexpected token 'style='color: #fff; background: black;'>TargetNameConfigurationIdNodeComplaintStatus'
        foreach ($Node in $NodeStatus) {
            if (-not ([bool]$Node.NodeCompliant)) {
                $TableContent += "
    

    I tried messing around with it but couldn't find the culprit. Any clues?

  • #20950

    Keymaster
    Points: 1
    Rank: Member

    First, you might try asking the original poster of the content. Also, these formatting problems can be difficult to catch here in the forums. This is definitely a typo, I think.

        $HtmlBody = "'
        $TableContent="TargetNameConfigurationIdNodeComplaintStatus'
    

    In both cases, it appears to me that a double quote is opening the string literal, but a single quote is closing it. That's not legal. It's possible the formatting was off when you copied the script from MSDN, but you'll need to run through and check it all.

The topic ‘MSDN script not quite right?’ is closed to new replies.