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 RandomPassword Function

function randomPassword{    # return a reasonably randomized password that starts with "KimConnect:" plus 25…

HPE Smart Update Manager 8.4.0

Step 1: Download ISO onto a Centralized Network Share Step 2: Connect to Remote Server…

How to Use the ‘Advanced Find’ Feature in Dynamics 365

Step 1: Login and click on Le Button Access your CRM portal with a valid…