David Williams Technical


Endpoint Management & Deployment – MDM Management – Scripting – Cyber Security Engineering – Application Configuration & Deployment

How to Remotely Deploy Installation Files and Install Software using PowerShell

Please note that this works well with scripts that are simple, using basic command prompt switches. I have tested this using more complex scripts that utilise Auto_It and Java scripts but for this document I will keep it simple.

Please note that in this tutorial I refer to sessions using %destination and $deployment. This is referring to the same computer but a different aspect of the installation process.


Firstly, I will start with deploying and installing on a single PC.

To copy the files to the PC you first need to run PowerShell as an administrator and start a New PSSession using the command:

$destination = New-PSSession -ComputerName %PC NAME%

Once this starts you can then use the Copy-Item command to send the files over the targeted computer.

Copy-Item -Path %Path to Files% -Destination “C:\” -ToSession $destination -Recurse

Note: -Recurse allows the contents of a folder to be copied: C:\%InstallFiles%\ – This will copy the directory and all its contents.

Finally, use the: Remove-PSSession $destination to close the session.


Once the files have been copied to the target computer you can then install them remotely.

To start the installation process you need to start a new PSSession using the command:

$deployment = New-PSSession -ComputerName %PC NAME%

Once the PSSession has been initiated you can install the software you can then install the software using the Invoke-Command:

Invoke-Command -Session $deployment -ScriptBlock {Start-Process %Path to Installer% -ArgumentList ‘/passive etc…’}

Note: The $deployment in the session name must be exactly the same as the initial session name. This process is not instant, it takes a few minutes for the process to complete so be patient. 

Note: You can test this process live on a Virtual Machine. A user can be logged in when this is performed and view the process as it happens.

Finally, use the: Remove-PSSession $deployment to close the session.


How to Remotely Copy Files and Install Software to Multiple Computers

Secondly, I will deploy to multiple PCs. The PC names should be contained in a .txt file.

This process is similar to deploying to single PCs but the initial command initialises multiple PSSessions.

To get the PC names from a text document use the command:

($computer = Get-Content -Path %Path to PCs.txt%)

Note: The brackets allow PowerShell to display what PCs are contained in the text file.

Initialise the PSSession using the command:

$sessions = New-PSSession -ComputerName $computer

This command initialises multiple PSSessions on multiple PCs called $destination.

Once this starts you can then use the Copy-Item command to send the files over the targeted computer. This command essentially targets each individual PSSession and copies the files to each one separately.

foreach ($session in $sessions) {

Copy-Item -Path  %Path to File% -Destination “C:\” -ToSession $session

}

Note: -Recurse allows the contents of a folder to be copied: C:\%InstallFiles%\ – This will copy the directory and all its contents.

Finally, use the: Remove-PSSession $session to close the session.


Once the files have been copied to the target computer you can then install them remotely.

To get the PC names from a text document use the command:

($computer = Get-Content -Path %Path to PCs.txt%)

To start the installation process you need to start a new PSSession using the command:

$deployment = New-PSSession -ComputerName $computer

Once the PSSession has been initiated you can install the software using the Invoke-Command:

Invoke-Command -Session $deployment -ScriptBlock {Start-Process %Path to Installer% -ArgumentList ‘/passive etc…’}

This should complete the installation process on all of the PCs in the .txt file. 

It should be noted that it might be worth running the command: 

Get-Content -Path %Path to Text File% | Restart-Computer

Once you have completed the installation, log on and check a few random machines if you are in an enterprise environment to check the software is working correctly especially if the software is using licence servers etc…