Credential issue in Pull server script

This topic contains 1 reply, has 2 voices, and was last updated by  Dave Wyatt 2 years, 5 months ago.

  • Author
    Posts
  • #25495

    Aravinda Cat
    Participant

    Hi All,

    While configuring pull server when a script with credentials is executed , it shows PlainTextPassword error.
    Here is the script :

    $username = "MW\biswaa"
    $password = Read-Host -AsSecureString
    $cred = new-object -typename System.Management.Automation.PSCredential `
    -argumentlist $username, $password

    $content = Get-Content "D:\demo.json" | Out-String
    $parsejson = ConvertFrom-Json $content

    Configuration testconfig
    {
    param
    (
    [Parameter(Mandatory=$True)]
    [string[]] $node,

    [Parameter(Mandatory=$True)]
    [pscredential]$cred
    )

    Node $node
    {
    File Copyfile
    {
    Ensure = "Present"
    Type = "Directory"
    SourcePath ="xxxxxxxxxxxxx"
    DestinationPath = "xxxxxxxxxxxxx"
    credential = $cred
    }
    }
    }

    foreach ($sitecontent in $parsejson)
    {
    $content = $sitecontent.Sites
    $Node = $content.Server

    write-host "Generating GUIDs and creating MOF files..."
    $NewGUID = [guid]::NewGuid()
    $NewLine = "{0},{1}" -f $Node,$NewGUID
    $NewLine | add-content -path "$env:SystemDrive\Program Files\WindowsPowershell\DscService\Configuration\dscnodes.csv"

    $config = @{
    AllNodes = @(
    @{
    Nodename = $NewGUID
    PSDSCAllowPlainTextPassword = $true
    }
    )
    }
    TestConfig -node $NewGUID -cred $cred -ConfigurationData $config
    Write-Host "Found Node – " +$Node
    }

    Error ::

    ConvertTo-MOFInstance : System.InvalidOperationException error processing property 'Credential' OF TYPE 'Script': Converting and storing encrypted passwords as plain text is not
    recommended. For more information on securing credentials in MOF file, please refer to MSDN blog: http://go.microsoft.com/fwlink/?LinkId=393729

    When I am giving Node name , it works fine, but the issue occurs if GUID is involved in it.

  • #25508

    Dave Wyatt
    Moderator

    It might be because you're assigning a GUID object to the Nodename property in your configuration data, rather than an string (which would be $NewGUID.Guid). In any case, it's simpler to just use NodeName='*', and not worry about that:

    $config = @{
        AllNodes = @(
            @{
                Nodename = '*'
                PSDSCAllowPlainTextPassword = $true
            }
        )
    }
    

You must be logged in to reply to this topic.