在我的环境中使用某些Windows 10计算机,并希望制作一个快速的PowerShell脚本来编辑我们的IM程序的配置文件。
快速调整一下脚本可以使其对我的测试文件非常有用。这可能不是最合适的解决方案,但是它正在起作用,所以我决定给它开绿灯。只是为了发现Get-Content
找不到我的配置文件,因为它没有扩展名。
这是我的脚本:
(Get-Content "$env:USERPROFILE\AppData\Roaming\Config") | Foreach-Object {
$_ -replace '^autoawaytime = [0-9]+',("autoawaytime = 9")
} | Foreach-Object {
$_ -replace '^autoaxtime = [0-9]+',("autoaxtime = 99")
} | Set-Content ("$env:USERPROFILE\AppData\Roaming\Config")
和错误;
获取内容:找不到路径“ C:\ Users \\ AppData \ Roaming \ Config”,因为它 不存在。 在C:\ Users \\ Desktop \ textFileEdit.ps1:1 char:2 +(获取内容“ $ env:USERPROFILE \ AppData \ Roaming \ Config” |选择BaseN ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ + CategoryInfo:ObjectNotFound:(C:\ Users \ bretb \ AppData \ Roaming \ Config:String)[Get-Content],ItemNotFoundException + FullyQualifiedErrorId:PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
因此,我由此得出结论,问题在于我的配置文件缺少文件扩展名,Get-Content
并且不喜欢该扩展名。有人可以Get-Content
提出我的配置文件上的建议,还是为我提出一个更优雅的解决方案?
在这种情况下,看来配置文件的路径不正确。
通用路径应类似于
%userprofile%\ AppData \ Roaming \ Company \ Product \ ExecutableName.Config
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句