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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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