Powershell Base64 String to Bytes

I am trying to convert a File with Powershell to a Base64 encoded Byte Array which is required by a webservice. How can i do that?

My current approach is to :

$content = [System.IO.File]::ReadAllBytes("$scriptpath/dummy.txt")
$base64String =[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($content))

$proxy = New-WebServiceProxy -Uri _____.wsdl
//... set up proxy-objects


$namespace = $proxy.GetType().Namespace
$soapObject= new-object ("$namespace.customType") 
$soapObject.byteArray = base64String

The last line will not work, since base64String is not a byte array. Unfortunately I is required to be a byte-array and i have no access to the Server-Side.

Using the XML-Notation i simply can put the Base64Encoded String directly. But how to do with powershell?

<customType><byteArray>anyBase64String</byteArray></customType>
Jon Skeet
people
quotationmark

If soapObject.byteArray is expecting a byte array, I'd expect to just be able to give it the array - let the proxy perform the encoding in base64. So:

$soapObject.byteArray = content

No need for base64String at all.

people

See more on this question at Stackoverflow