Posted On July 12, 2022

PowerShell: Running Commands on Remote Computers

kimconnect 0 comments
blog.KimConnect.com >> Codes , Windows >> PowerShell: Running Commands on Remote Computers
# runCommandsOnRemoteComputers.ps1

# User defined variables
$computernames=@(
'SERVER001',
'SERVER002'
)
$expectedExecutable='racadm.exe'
$expectedInstallPath='C:\program files\Dell\SysMgt\iDRACTools\racadm'

# Execution
foreach($computername in $computernames){
	invoke-command -computername $computername -scriptblock{
	param($expectedInstallPath,$expectedExecutable)
		$commandAvailable=try{get-command $expectedExecutable -EA Ignore}catch{$false}
		$proceed=if(!$commandAvailable){
			$environmentalPathExists=$env:path -like "*$expectedInstallPath*"
			if(!$environmentalPathExists){
				$env:path+=";$expectedInstallPath"			
			}
			$null=RefreshEnv
			$commandNowAvailable=try{get-command $expectedExecutable -EA Ignore}catch{$false}
			if($commandNowAvailable){$true}else{$false}
		}
		if($proceed){
			write-host "Configuring iDrac on $env:computername"
			racadm set iDRAC.NIC.DNSRacName ($env:computername).tolower()
			racadm set iDRAC.NIC.DNSRegister 0
			racadm set iDRAC.IPv4.DHCPEnable 1
			racadm set iDRAC.IPv4.DNSFromDHCP 1
			racadm set iDRAC.NIC.DNSDomainFromDHCP 1
			racadm set iDRAC.NIC.VLanEnable 0
		}
	} -Args $expectedInstallPath,$expectedExecutable
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Download and Apply Windows Patch KB

The following snippet assumes that a Windows machine has access to download Microsoft patches directly…

PowerShell: Detect Windows Version

This little snippet is reusable on many occasions where Windows version targeting is required. function…

Great GPL Windows Admin Tools

1. Wireshark 2. amanda.org (backup server) 3. mailarchiva.com (mail backup) 4. http://rbac.codeplex.com (remote admin for Exchange servers) 5. Core Configurator, ,…