0

I have a Python script to convert the CSV file to base64.

import base64
file = open("D:\test.csv", 'rb')
base64_csv = base64.b64encode(file.read()).decode('utf-8')

I need to write a Powershell to do the same thing due to company recruitment. I tried this module but doesn't work:

$csv = Import-Csv -Path "D:\test.csv"
base64_csv = [System.Convert]::ToBase64String([char[]]$csv)

Cannot convert the "@{My CSV File content}" value of type 
"System.Management.Automation.PSCustomObject" to type "System.Char[]".

I am very new to Powershell, any help is appreciated!

1 Answer 1

2

The fact the file is CSV isn't part of the processing needed to converting it to base64 representation. You should be able to simply convert the file as raw data to a base64 string:

$base64_csv = [Convert]::ToBase64String([IO.File]::ReadAllBytes("D:\test.csv"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.