powershell - 如何在PowerShell 1.0中使用STA模式?

标签 powershell sta powershell-1.0

我在PowerShell中非常笨拙,只能在家里用于Windows XP下无法完成PS2升级的简单任务。下一步测试表明,我的PowerShell 1.0默认使用MTA模式。

[threading.thread]::CurrentThread.GetApartmentState()

像...这样的电话
PowerShell.exe –STA c:\scripts\file.ps1

...总是因错误而失败:

Missing expression after unary operator '-'. At line:1 char:2 + -S <<<< TA c:\scripts\file.ps1



看来我的PS1无法识别–STA开关。我做错了什么?有没有办法在PS1的STA模式下运行我的脚本?

最佳答案

命令中STA前面的破折号是“–” Unicode U + 2013“En Dash”,其中应该是“-” Unicode U + 002D“连字符减号”。您可以在浏览器控制台(F12)中使用此JavaScript函数进行尝试:

function getHex(character) {
    return "0x" + character.charCodeAt(0).toString(16);
}

getHex('–'); // 0x2013
getHex('-'); // 0x2d

也许您已经从网页,PDF或Word文档中复制了它。尝试键入命令而不是复制/粘贴,它将起作用。

PowerShell的新版本将两个字符都识别为破折号。

关于powershell - 如何在PowerShell 1.0中使用STA模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14723705/

相关文章:

powershell - CloudFormation 和 PowerShell : Template format error: unsupported structure with

arrays - 传递字符串数组和foreach循环不起作用:没有数组,只有一个字符串?

c++ - 在 Windows 中删除文件时 CMD 和 PowerShell 有什么区别?

wcf - 在 IIS (7+) 托管的 WCF 服务中使用 STA COM 组件时,如何处理?

powershell - 如何使用powershell仅对第二列值求和?

powershell - 我可以使用 powershell 在一个命令中复制 s3 中的 "folder"吗?

f# - STATHREAD 作为 F# 中的异步工作流程

c# - 如何告诉线程池在 `STA` 线程上运行委托(delegate)?

powershell - 如何限制 Get-ChildItem 搜索的文件(或限制递归深度)?

powershell - Powershell将参数传递到功能链中