I'm getting this error message:
The variable '$server' cannot be retrieved because it has not been set.
The error occurs at the beginning of the switch statement below:
function Get-ServerName {
[Parameter(mandatory)] [TARGET_SERVER] $server
<#
.SYNOPSIS
Retrieves the name of the SFTP server running on on the user’s computer.
.PARAMETER server
The server type whose name we want.
.OUTPUTS
The folder (“Undefined” if null)
#>
switch ($server) {
local { $key = $LOCAL_HOST_NAME_KEY }
remote { $key = $REMOTE_HOST_NAME_KEY }
default { Deny-ServerType -server $server }
}
The data type TARGET_SERVER is defined like this:
enum TARGET_SERVER { # Server receiving the uploaded files
remote # The server hosting the public-facing Web site
local # An SFTP server running on the user’s computer. Used for testing.
}
The function is called like this:
$hostName = Get-ServerName -server $server
I’ve verified that $server IS set to “local,” so I can't understand what's causing the error.
How do I fix this?