Skip to content

HostsFile Get-TargetResource returns an array for HostName if there is one or more spaces at the beginning of the line #526

Description

@cdhunt

Problem description

HostsFile Get-TargetResource returns an array for HostName if there is one or more spaces at the beginning of the line. This formatting appears to come from the PowerToys Hosts File Editor.

  127.0.0.1     argo.docker.internal
# Added by Docker Desktop
  192.168.1.160 host.docker.internal
  192.168.1.160 gateway.docker.internal
Invoke-DscResource -Name HostsFile -ModuleName NetworkingDsc -Method get -Property @{HostName='argo.docker.internal'}

Name                           Value
----                           -----
Ensure                         Present
IPAddress
HostName                       {127.0.0.1, argo.docker.internal}

Verbose logs

n/a

DSC configuration

n/a

Suggested solution

Run Trim before Split.

Operating system the target node is running

Windows 11

PowerShell version and build the target node is running

Name                           Value
    ----                           -----
    PSVersion                      7.4.2
    PSEdition                      Core
    GitCommitId                    7.4.2
    OS                             Microsoft Windows 10.0.22621
    Platform                       Win32NT
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0

NetworkingDsc version

Name          Version Path
    ----          ------- ----
    NetworkingDsc 9.0.0   C:\Users\[username]\Documents\PowerShell\Modules\NetworkingDsc\9.0.0\NetworkingDsc.psd1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThe issue is a bug.help wantedThe issue is up for grabs for anyone in the community.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions