Open IzaacJ opened 4 years ago
Hello IzaacJ,
the chars [
, ]
, ?
, *
are interpreted as wildcards, see about_wildcards.
For cases where the path contains wildcards, many cmdlets are providing the -LiteralPath
parameter. -LiteralPath
takes the path as it is without any wildcard processing.
Look at this example:
PS C:\> Set-Location -Path Z:\[Scripts]
Set-Location : Cannot find path 'Z:\[Scripts]' because it does not exist.
At line:1 char:1
+ Set-Location -Path Z:\[Scripts]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Z:\[Scripts]:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
PS C:\> Set-Location -LiteralPath Z:\[Scripts]
PS Z:\[Scripts]>
Unfortunately Get-IniContent
does not provide such a parameter. I see this solutions:
Get-IniContent
(and other commands in this module) to support -LiteralPath
Get-Content -LiteralPath 'Z:\[Scripts]\[PS]\config.ini' | ConvertTo-IniContent
(and as versa ConvertTo-IniString
?)If @lipkau finds the 2nd or 3rd idea sensible, I can help to suggest an implementation via pull request.
Edit: The 3rd idea duplicates issue #47 (Abstract away the concept of converting to/from INI format from that of reading/writing an INI file)
Hello.
Writing a PS script and I seem to be unable to get it to load an ini file when the path to it contains [ ].
Ie, my PS script and the INI file lies in the path
Z:\[Scripts]\[PS]
.And my script:
I however get an error that the file wasn't found.
It then fails to do modifications on the file, and
$ini | Out-IniFile -FilePath $iniFile -Force
successfully writes an empty file, since it's empty.