powershell - 当我的用户名中有 \ 时,Powershell 脚本不运行
问题描述
我有以下 PowerShell 脚本,但它认为 DS 是一个模块。我从 Azure DevOps 变量中获取用户名。用户名的实际值为DS\TestUser 有人可以帮忙吗
$serviceName = "Test"
$username = $(UserName)
$secpasswd = ConvertTo-SecureString $(Password) -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential $username, $secpasswd
$binaryPath = "D:\Test\Test.exe"
New-Service -name $serviceName -binaryPathName $binaryPath -displayName $serviceName -startupType Automatic -credential $mycreds
我已经尝试将变量转换为 ToString()、Out-String 并将 \ 替换为 \
解决方案
正如 Mathias R. Jessen 在评论中提到的,更改$(UserName)
为"$(UserName)"
可以解决这个问题。
推荐阅读
- html - 花哨的盒子和网格显示问题。图片重叠
- sql - SQL 连接和将 1 列引入 2 列
- r - R中的热图失败
- r - 在 R 中:我可以将行号 =1 的数据框(例如 x)分配为另一个数据框(例如 y)的列标题吗?
- vb.net - 有人可以帮我理解 Visual Basic 中的数据表计算功能吗?
- firebase - 如何在 Flutter 中加入来自两个 Firestore 集合的数据?
- javascript - Firebase 在 for 循环中添加
- angular - Angular 9 按日期对项目进行分组
- casting - Python中的数据类型转换和映射对象错误,TypeError: a bytes-like object is required, not 'map'
- powershell - 如何修复此 Powershell FTP 上传错误