Using the PowerShell version 5 Preview OneGet Module with PowerShell Remoting

I'm picking up where I left off in my last blog article. Adobe Reader, ImgBurn, and WinRAR have been installed on a Windows 8.1 Enterprise edition computer named PC03. All of the examples shown in this blog article are being run from the PC03 computer.

I'll use a little trick I showed you a few blog articles ago and store the names of the installed packages in a variable and return them at the same time, all in a one-liner:

1($software = Get-Package | Select-Object -ExpandProperty Name)


I'll create a PSSession to the computers named PC04, PC05, and PC06, store them in a variable named $Session (technically, it's named Session) and return a list of the sessions all in a one-liner with the same trick I used in the previous command:

1($Session = New-PSSession -ComputerName pc04, pc05, pc06)


PC04, PC05, and PC06 all run Windows 8.1 Enterprise edition, have the preview version of PowerShell version 5 installed, their script execution policy is set to RemoteSigned, and PowerShell remoting has been enabled on them. One of the cmdlets from the OneGet module has also been previous run on them to trigger installing the NuGet Package Manager, although no packages have previously been installed on them.

Note: The one package source (Chocolatey) that's included by default with the preview version of PowerShell verison 5 isn't trusted:



This means that by default you'll be prompted as shown in the following example when installing software from that package source:

1Find-Package -Name AdobeReader, ImgBurn, WinRAR |


Since I'll be installing the software on the three remote computers using PowerShell remoting, I'll be unable to answer those interactive questions. There are two options to prevent being prompted, remove the Chocolatey package source and re-add it as a trusted package source, or simply use the -Force parameter with the Install-Package cmdlet.

I'll use the -Force parameter since it's the easier solution to this problem and it doesn't permanently make changes to the package source settings:

1Invoke-Command -Session $Session {Install-Package -Name $Using:software -Force}


In the previous command, I've taken advantage of the Using scope modifier that was introduced in PowerShell version 3. For more information about the Using scope modifier see the about_Scopes and about_Remote_Variables help topics in PowerShell.

Success! All three of the computers (PC04, PC05, and PC06) now have the same packages installed that are installed on PC03 (Adobe Reader, ImgBurn, and WinRAR):