I’m trying to use the ActiveBatch ExecutePowerShellScript job step to convert a System.Byte[] to a string. The ActiveBatch job step has a property to specify the InputObjects, which I set to the output of the previous job step (this is just a field in the job steps editor, not PowerShell code). Then you apparently have access to a variable called $input in the PowerShell script..
With just $input I get a list of bytes converted to integers. With $input | gm I get:
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...
If I try [System.Text.Encoding]::Unicode.GetString($input) I get:
Exception taken executing PowerShell script: Cannot find an overload
for “GetString” and the argument count: “1”.
If I try [System.Text.Encoding]::Unicode.GetString(,$input) I get:
Exception taken executing PowerShell script: Missing ‘)’ in method
call.
If I try:
[byte[]]$bytes = $input
[System.Text.Encoding]::Unicode.GetString($bytes)
I get:
Exception taken executing PowerShell script: Cannot convert the
“System.Management.Automation.Runspaces.PipelineReader1+<GetReadEnumerator>d__0[System.Object]"1+d__0[[System.Object,
value of type
"System.Management.Automation.Runspaces.PipelineReader
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]]” to type “System.Byte[]”.
Any ideas?
Apparently you have to use
Select-Object, and the byte array was coming through as ASCII rather than unicode.