Home > Mobile >  Installing Program remotely through Remote PowerShell
Installing Program remotely through Remote PowerShell

Time:12-08

I am trying to install ActivClient remotely onto some machines, I copy the file to the Public Downloads separately.

I am running into an issue where when I try to run this script, it runs locally on my machine. I need to run that Deploy-Application.PS1 file for this.

I also can't figure out how to Unblock the entire folder, there is a few sub folders and files I would like to unblock.

I can't remote into the computer through RDP because I need ActivClient installed to remote in. Remote PowerShell is the only method I can find to run this.

If I am missing information or need to provide more, please let me know.


$mypath = $MyInvocation.MyCommand.Path
$Path = Split-Path $mypath -Parent

[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$title = 'Computer Name'
$msg   = 'Enter the Computer Name you need to reinstall ActivClient on:'

$CName = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)

if (Test-Connection -ComputerName $CName -Count 1){

Write-Host "Entering Remote Powershell Session"

$PSSession = New-PSSession -Name $CName

Invoke-Command -Session $PSSession -ScriptBlock{

Get-ChildItem "C:\Users\Public\Downloads\SDC NIPR - ActivClient v7.2.x - 210811_18NOV" | Unblock-File

cd "C:\Users\Public\Downloads\SDC NIPR - ActivClient v7.2.x - 210811_18NOV" 

.\Deploy-Application.ps1 Install 'NonInteractive'

pause

}

CodePudding user response:

  • Use New-PSSession -ComputerName $CName, not New-PSSession -Name $CName.

    • -Name only gives the session being created a friendly name, it is unrelated to which computer you target. In the absence of a -ComputerName argument, the local machine is (somewhat uselessly) targeted, which is why the script ran on your local machine.

    • Note that if you're only calling Invoke-Command remotely once per remote computer, you needn't create a session explicitly and can instead use -ComputerName $CName directly with Invoke-Command:

      # No need for New-PSSession.
      Invoke-Command -ComputerName $CName -ScriptBlock { ... }
      
  • Add -Recurse -File to your Get-ChildItem call in order to unblock all files in the target folder recursively (all files in the target folder's subtree).

  • Related