Fixing Powershell Params (The input to an assignment operator must be an object that is able to accept assignments0

Mar 22, 2013 ssh github windows

Problem

Powershell errors with "The input to an assignment operator must be an object that is able to accept assignments".

Write-Host "Ahoy hoy!"
param(
    [Parameter(Mandatory=$true)][string]$path,
    [Parameter(Mandatory=$true)][string]$environment="example" # error here
)

Solution: You've got a problem with your params. In my case I had a statement before declaring the params section. Params should be at the start of the file, or at the start of a function.

param(
    [Parameter(Mandatory=$true)][string]$path,
    [Parameter(Mandatory=$true)][string]$environment="example" # error here
)
Write-Host "Ahoy hoy!"

Further reading