dsccommunity / dsccommunity/NetworkingDsc

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

Open
#526 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted
Dominant language
PowerShell
Stars
235
Forks
93
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the HostsFile Get-TargetResource entry point and reproduce the issue with Invoke-DscResource using a hosts line with leading spaces. Ensure the returned HostName is a scalar hostname rather than an array containing the IP address, while preserving normal hosts-file parsing.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.