Please feel free to provide feedback or file bugs here.

Bug: Here string - When using invoke-command when here string starts with [

Using a here string to create an LCM file using a Hyper-V VM and invoke-command.
If the here string starts with [ the file created is blank if viewing with get-content. Viewing the file with PSEdit, the file is full of squares.

Code used to generate this:

$lcmscript = @'
[DSCLocalConfigurationManager()]
configuration LCMPush
{
Node $AllNodes.Where{$_.Role -eq "Primary DC"}.Nodename
{
Settings
{
RebootNodeIfNeeded = $true
ActionAfterReboot = 'ContinueConfiguration'
ConfigurationMode = 'ApplyAndAutoCorrect'
CertificateID = "REPLACEWITHFRESHLYCREATEDTHUMBPRINT"
}
}
}

# Create the computer.meta.mof in folder
LCMPush -configurationData c:\dsc\dscconfigdata.psd1 `
-OutputPath c:\dsc\LCM
'@

Invoke-Command -VMName $vmname -Credential $cred -ScriptBlock { New-Item c:\dsc\lcm -ItemType Directory; new-item c:\dsc\lcm\dsclcm.ps1 -ItemType File -Value $USING:lcmscript -Force }

Sometimes using this method works correctly. Mostly it produces an empty file though.

I used this same method for other types of here strings in the same script and they work fine.

Workaround for me was to use the here string as in the code below:
$lcmscript | out-file $env:TEMP\dsclcm.ps1
Copy-VMFile -VMName $vmname -SourcePath "$env:Temp\dsclcm.ps1" -DestinationPath 'c:\dsc\lcm\dsclcm.ps1' -CreateFullPath -FileSource Host -Force
start-sleep -seconds 2

Not sure if the file takes too long to be created. I put it before two other here strings that worked correctly and it still failed.

1 vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Tim HaintzTim Haintz shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base