I'm working through a powershell book and am trying to write a simple function which is:
Function Install-Software {
[cmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateSet('1','2')]
[string]$Version,
[Parameter(Mandatory)]
[string]$ComputerName
)
Write-Host "I installed software version $Version on $ComputerName. Yay!"
}
It is written in powershell ISE (i know not supported, but it worked fine before i added the computername parameter).
In powershell i first typed the location of the script as i did before: C:\Install-Software.ps1
then called the function with the parameters:
Install-Software -Version 2 -ComputerName SRV1
I received an error that states "Install-Software : A parameter cannot be found that matches parameter name 'ComputerName'.
At line: 1 char: 29
I'm not sure whats wrong, the code works fine even if I don't include this parameter when calling the function. For example, if I type:
Install-Software -Version 2
Then the console outputs as it should "I installed software version 2. Yay!"
Not sure why it says the parameter computername can't be found, I have copied the exact code from the book I'm going through. Please help, Thanks!