News for hackers. Stuff that matters.
Re:PowerShell 7.0 by bluedino on Thursday March 05, 2020 @09:28AM (#22493732)
Coming from a bash background, PowerShell is consistently annoying. Here's an example, passing an XML file to a cmdlet:

    Some-Command -Param1 -FileData .\foobar.xml
Cannot process argument transformation on parameter 'FileData'. Cannot convert value ".\foo.xml" to type "System.Byte[]". Error: "Cannot convert value ".\foo.xml" to type "System.Byte". Error: "Input string was not in a correct format.""

In bash you would just do:

    somecommand < foobar.xml
Instead you have to create an object and, do a conversion:

    [Byte[]]$Data = Get-Content -Path ".\foobar.xml" -Encoding Byte -ReadCount 0
Then, run the same command using that object instead of the file:

    Some-Command -Param1 -FileData $Data

There are no comments on this comment yet.