Recently Added

Notes & Bookmarks

  1. Quasars; power and metrics beyond all comprehension. Staggeringly beautiful information... and very well written.
  2. "I'm sorry. I can't come in today. Religious holiday. The feast of...Maximum Occupancy."pic.twitter.com/mkgxPWfNj2
  3. Verifying myself: I am sgnls on Keybase.io. UJa01G4v3YRJYB1LFjDRSf1Nh0bh1sOykCbq / https://keybase.io/sgnls/sigs/UJa01G4v3YRJYB1LFjDRSf1Nh0bh1sOykCbq
  4. Be sure to take care of your own infrastructure(s); purge dumps, tunnel and lock-down egress transit, encrypt and permission CORRECTLY!
  5. It really doesn't matter what else gets released; Sikth's 'The Future in Whose Eyes?' is THE album of 2017. #albumoftheyear @SikthOfficialpic.twitter.com/P5houdf1yx

Remote Installation of Binary with Powershell & WMI v1

Updated : 15:27:39pm, 22nd Mar 2016

This needs a fair bit of tweaking, but I'm recording it here for legacy's sake (and as a reminder to iron out the creases).

Intention of this script was to deploy an AEM agent to remote workstations using -searchbase scopes, with logging. Progress notification (i.e. bar) and a more efficient foreach are on the cards, but this can be easily tweaked to allow deployment of any other silent binary.

## machine scope(s)
$comps_ind = "solo-workstation"
# $comps_all_ws = get-adcomputer -searchbase "dc=domain,dc=com" -filter {OperatingSystem -notlike "*Server*"} | select Name -expandproperty Name | sort-object -descending
$comps_all_ws = get-adcomputer -searchbase "dc=domain,dc=com" -filter {OperatingSystem -notlike "*Server*"} | select Name -expandproperty Name | sort-object -descending
$comps_all_srv = get-adcomputer -searchbase "dc=domain,dc=com" -filter {OperatingSystem -like "*Server*"} | select Name -expandproperty Name

## globals
$log_file = "c:\path_to\aem_install.txt"
$log_file_off = "c:\path_to\aem_install-offline.txt"
$aem_src = '\\server\aem$'
$aem_file = "AgentSetup_Domain+Group.exe"
$usr_dir = "c$\aem_temp"
$usr_dir_local = "c:\aem_temp"
$install_dir = "Program Files\CentraStage"
$install_dir_64 = "Program Files (x86)\CentraStage"
$proc_id = "setup"
$service = "CagService"

## install cycle
foreach($comp in $comps_all_ws){

	## check machine if online, else ignore
	if(test-connection $comp -count 1 -quiet){

		## check if application is already installed, else install
		$get_status = get-service -computername $comp | where {$_.Name -like "*$service*"} | select Status -expandproperty Status

		if($get_status -eq "Running"){

			write-host "AEM Agent is running on $comp `n"
			add-content "$log_file" "AEM agent is running on $comp`n"
		}
		else{
			
			if(!(test-path -path "\\$comp\$usr_dir\$aem_file")){
			
				write-host "Copying AEM installation files to $comp... `n"
				add-content "$log_file" "Copying AEM installation files to $comp... `n"
			
				## create target dir and copy installation file locally
				new-item "\\$comp\$usr_dir" -type directory -force | out-null
				copy-item "\\$aem_src\$aem_file" "\\$comp\$usr_dir\" | out-null
				
			}
			
			write-host "Preparing to install AEM agent on $comp..."
			add-content "$log_file" "Preparing to install AEM Agent on $comp...`n"	
	
			## perform installation on remote (local) machine
			$aem_install = "cmd.exe /c $usr_dir_local\$aem_file"
			([WMICLASS]"\\$comp\ROOT\CIMV2:win32_process").create($aem_install) | out-null 
			
			write-host "Preparing to start AEM agent on $comp..."
			add-content "$log_file" "Preparing to start AEM agent on $comp...`n"	
		
			get-service -computername $comp | where {$_.Name -like "*$service*"} | select Status -expandproperty Status | set-service -Status Running
			
			## give it time to start the service...
			start-sleep -s 10

			## check if agent is installed
			if(!(test-path -path "\\$comp\c$\$install_dir")){
			
				write-host "AEM agent is NOT installed on $comp `n"
				add-content "$log_file" "AEM agent is NOT installed on $comp`n"
				
			}
			else{
				if($get_status -ne "Running"){
				
					write-host "AEM agent is installed but NOT running on $comp `n"
					add-content "$log_file" "AEM agent is installed but NOT running on $comp`n"

				}
				else{

					write-host "AEM agent is running on $comp `n"
					add-content "$log_file" "AEM agent is running on $comp`n"

				}
			}

		}
		
	}
	else{	
		write-host "$comp is offline. `n"
		add-content "$log_file_off" "$comp is offline. `n"
	}

}

SGNLS.net © 2006-2017

Comments, submissions and errors to desk[at]sgnls.net.

Material and content adheres to the Creative Commons (NC-SA 4.0) license.

v12.01151