Created A Powershell Script for Client remote Install

I am troubleshooting with support my issues with installing clients to remote workstations via the client deploy tool in all forms. In the mean time I created a powershell script that will take a csv file that you copy entries from the Unmanaged Assets pane and install the client. This has worked great for my deployment so far until we figure out what is going on with my instance. Hope this is helpful to someone.

Paste that into notepad

image

Save and then run the below powershell.

Below is the powershell.

$ErrorActionPreference = 'Stop'

#Import the CSV file you created
$targets = Import-Csv -Delimiter "`t" -Path "<Path to your CSV File>"

#Get user to use for the installation Task.  
#Must have Admin privileges to the Target Machine. 
#Domain credentials are best entered as user@fqdn and local credentials can just be the user.
$user = Read-Host -Prompt "Enter Username to use for Install"

#Get password to use for the installation task.
$password = Read-Host -Prompt "Enter Password"

$PWord = ConvertTo-SecureString $password -AsPlainText -Force

#Create a Powershell Credential Object for use
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $PWord

#Path to your BES Installers folder containing the ClientMSI Folder
$MSIPath = "<Path>\BigFix Enterprise\BES Installers"

#Loop Through each imported csv record.
foreach($targetprops in $targets){
    #Sets the target as the IP Address from the Unmanaged Assets Export.
    $target = $targetprops."IP Address"
    Write-Host "===================================================================================================="
    Write-Host "Starting Install Process On $target"
    Write-Host "===================================================================================================="
    try{
        Write-Host "Connecting Remote Installation Drive...."
        #Creates a Installation Drive Connection.
        New-PSDrive -Name "TargetWS" -PSProvider FileSystem -Root "\\$target\c$" -Credential $cred | Out-Null
        Write-Host "Remote Installation Drive Connected...."
        try{
            #Checks to see if ClientMSI Folder Exists.
            if(Test-Path "TargetWS:\Temp\ClientMSI\"){
                Write-Host "Folder Exists...."
            }else{
                Write-Host "Folder does not exist.  Creating Folder...."
                #If ClientMSI Folder does not exist in C:\Temp folder of the target machine then creat the Folder structure.
                New-Item -Path "TargetWS:\Temp\" -Type Directory -Force | Out-Null
                New-Item -Path "TargetWS:\Temp\ClientMSI\" -Type Directory -Force | Out-Null
                Write-Host "New Folders Created...."
            }
            try{
                Write-Host "Copy Starting....."
                #Start Copying the installation files needed to the target machine.
                copy -Path "$MSIPath\ClientMSI\*" -Destination "TargetWS:\Temp\ClientMSI\" -Recurse -Force
                Write-Host "Copy Complete....."
                try{
                    Write-Host "Starting Remote Installation...."
                    #Start the installation process on the remote machine and waits for the install to finish before moving on.
                    start-process wmic -ArgumentList "/node:$target /user:`"$user`" /password:`"$password`" product call install true, `"`", `"c:\TEMP\ClientMSI\BigFixAgent.msi`"" -NoNewWindow -Wait
                    Write-Host "Remote Installation Complete...."                    
                    Write-Host "Removing Install Files and Folders...."
                    #Remove all Installation Files from Target Machine.
                    Remove-Item "TargetWS:\Temp\ClientMSI" -Recurse -Force
                    #Disconnect installation drive mapped by Powershell.
                    Write-Host "Disconnecting Install Drive...."
                    Remove-PSDrive -Name TargetWS
                }catch{ 
                    Write-Host "Error Starting Install Process: $_"
                }
            }catch{
                Write-Host "Error Copying Files to destination: $_"
            }
        }catch{
            Write-Host "Error createing directory: $_"
        }
    }catch{
        Write-Host "Error Mapping Drive: $_"
    }
}
4 Likes