gpt4 book ai didi

.net - ActiveBatch ExecutePowerShellScript 将字节数组转换为字符串

转载 作者:行者123 更新时间:2023-12-04 05:45:26 25 4
gpt4 key购买 nike

我正在尝试使用 ActiveBatch 执行PowerShellScript 转换 System.Byte[] 的作业步骤到一个字符串。 ActiveBatch 作业步骤有一个属性来指定 InputObjects ,我将其设置为上一个作业步骤的输出(这只是作业步骤编辑器中的一个字段,而不是 PowerShell 代码)。然后你显然可以访问一个名为 $input 的变量。在 PowerShell 脚本中..

只需 $input我得到一个转换为整数的字节列表。与 $input | gm我得到:

There are 25 output objects generated by the Powershell script

TypeName: System.Byte[]

Name MemberType Definition
---- ---------- ----------
Count AliasProperty Count = Length
Address Method System.Byte&, mscorlib, Version=2.0.0.0, Culture...

如果我尝试 [System.Text.Encoding]::Unicode.GetString($input)我得到:

Exception taken executing PowerShell script: Cannot find an overload for "GetString" and the argument count: "1".



如果我尝试 [System.Text.Encoding]::Unicode.GetString(,$input)我得到:

Exception taken executing PowerShell script: Missing ')' in method call.



如果我尝试:
[byte[]]$bytes = $input
[System.Text.Encoding]::Unicode.GetString($bytes)

我得到:

Exception taken executing PowerShell script: Cannot convert the "System.Management.Automation.Runspaces.PipelineReader1+<GetReadEnumerator>d__0[System.Object]"
value of type
"System.Management.Automation.Runspaces.PipelineReader
1+d__0[[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" to type "System.Byte[]".



有任何想法吗?

最佳答案

$bytes = $input | Select-Object
[System.Text.Encoding]::ASCII.GetString($bytes)

显然你必须使用 Select-Object ,并且字节数组以 ASCII 而不是 unicode 的形式出现。

关于.net - ActiveBatch ExecutePowerShellScript 将字节数组转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10736646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com