Copying across multiple remoting sessions

Richard Siddaway's Blog

I needed to copy the same file to multiple machines so I tried this:

$computers = ‘W16CN01’, ‘W16CN02’

$s = New-PSSession -ComputerName $computers

Copy-Item -Path ‘C:SourceWindows 2016 TP5Cumulative Update for Windows Server 2016 Technical Preview 5 (KB3163016)AMD64-all-windows10.0-kb3163016-x64_83d6e9bca94a64a5d9be3d81cdb182e540285848.msu’ -Destination C:Scripts -ToSession $s

Remove-PSSession –Session $s

It failed with:

Copy-Item : Cannot convert ‘System.Object[]’ to the type
‘System.Management.Automation.Runspaces.PSSession’ required by parameter
‘ToSession’. Specified method is not supported.
At line:5 char:236
+ … a5d9be3d81cdb182e540285848.msu’ -Destination C:Scripts -ToSession $s
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Copy-Item], ParameterBindi
ngException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Comma
nds.CopyItemCommand

If you look at the syntax

Get-Command Copy-Item -Syntax

Copy-Item [-Path] <string[]> [[-Destination] <string>] [-Container]
[-Force] [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>]
[-Recurse] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm]
[-UseTransaction] [-FromSession <PSSession>] [-ToSession <PSSession>]
[<CommonParameters>]

Copy-Item [[-Destination] <string>] -LiteralPath <string[]> [-Container]
[-Force] [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>]
[-Recurse] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm]
[-UseTransaction] [-FromSession <PSSession>] [-ToSession <PSSession>]
[<CommonParameters>]

the…

View original post 55 more words

Leave a comment