A positional parameter cannot be found that accepts argument '[System.Convert]::ToBase64String'

Patel, Amit 20 Reputation points
2023-11-16T21:08:00.28+00:00

While I am running the below command, I am getting error "Get-Content: A positional parameter cannot be found that accepts argument '[System.Convert]::ToBase64String'."

What could be the issue?

# [Powershell]
# Get content of certificate as byte stream, and convert to base64 string and store in .txt
$fileContentBytes = get-content ‘certificate.pfx' -AsByteStream [System.Convert]::ToBase64String($fileContentBytes) | Out-File ‘pfx-encoded-bytes.txt’
Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,327 questions
Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,182 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,667 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,386 Reputation points
    2023-11-16T22:17:55.6166667+00:00

    Put the expression "[System.Convert]::ToBase64String($fileContentBytes)" within parentheses. I.e.

    ( [System.Convert]::ToBase64String($fileContentBytes) )
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.