When I run next command in powershell:
$test = New-PSSession -ComputerName localhost,localhost
it runs fine and create two new sessions.
Here under, you can find the script code I have that keeps sending me errors.
function New-TempDirectory {
[CmdletBinding(DefaultParameterSetName = 'ComputerName')]
param (
[Parameter( ValueFromPipeline,
ParameterSetName = "ComputerName",
Position = 0
)]
[string[]]
$ComputerName = 'localhost',
[Parameter( Mandatory,
ValueFromPipeline,
ParameterSetName = 'PSSession',
Position = 0
)]
[System.Management.Automation.Runspaces.PSSession]
$PSSession
)
begin {
Write-Verbose "[BEGIN ] Starting: $($MyInvocation.Mycommand)"
}
process {
if ($PSCmdlet.ParameterSetName -eq 'ComputerName') {
Write-Verbose "ComputerName = $ComputerName"
$PSSession = New-PSSession -ComputerName $ComputerName
} # if ParameterSetName
# Execution logic to write
} # process
end {
Write-Verbose "[END ] Ending: $($MyInvocation.Mycommand)"
}
}
New-TempDirectory -ComputerName localhost, localhost -Verbose
And here is the output I keep getting (with said error message):
VERBOSE: [BEGIN ] Starting: New-PBPTempDirectory
VERBOSE: ComputerName = localhost localhost
MetadataError: P:\PowerShell\Modules\PBPInstallSoftware\PBPInstallTestScript.ps1:27:13
Line |
27 | $PSSession = New-PSSession $ComputerName
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot convert the "System.Object[]" value of type "System.Object[]" to type
| "System.Management.Automation.Runspaces.PSSession".
VERBOSE: [END ] Ending: New-PBPTempDirectory
Any help would be much appreciated.
Karsten