Fre*_*ing 2 unicode powershell utf-8 punctuation
我试图接受用户名和密码作为Powershell脚本的参数,但是新的对象
$UserID="Name"
$SecurePassword=convertto-securestring -AsPlainText -Force -String $Password
New-object –TypeName System.Management.Automation.PSCredential –ArgumentList ($UserID,$SecurePassword)
Run Code Online (Sandbox Code Playgroud)
给出错误
新对象:找不到类型[ - TypeName System.Management.Automation.PSCredential - ArgumentList]:验证是否加载了包含此类型的as sembly.在C:\ ps\login.ps1:14 char:17 + ... rCredential = New-object - TypeName System.Management.Automation.PSCre ... + ~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidType: (:) [New-Object],PSArgumentException + FullyQualifiedErrorId:TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
任何人都有一些线索如何解决这个问题?
的–在前面TypeName和ArgumentList参数不是连字符,但EN破折号(U + 2013),并且该跳闸了解析器.用连字符(-)替换它们:
'New-object –TypeName System.Management.Automation.PSCredential –ArgumentList ($UserID,$SecurePassword)' -replace '\p{Pd}','-'
Run Code Online (Sandbox Code Playgroud)
\p{Pd}是" P unctuation,d ashes" 的unicode类
编者按:PowerShell中,也许令人惊讶,也没有与使用问题–,以代替常规的ASCII范围的(破折号)-("破折号",在技术上:连字符减号) -尝试Get-ChildItem –File,例如.
OP唯一的问题是字符编码问题,如果你转换为常规的"破折号" ,你碰巧就会绕过它.将Unicode en破折号转换为ASCII"破折号"只是一个权宜之计:它掩盖了OP保存文件的真正问题,该文件具有Windows PowerShell错误解释的编码.如果该文件包含非ASCII字符作为数据,它仍然会被破坏.
| 归档时间: |
|
| 查看次数: |
862 次 |
| 最近记录: |