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: List All Hyper-V Snapshots of All VMs in All Clusters in Domain

# listHyperVSnapshots.ps1 $clusterName='*' function listAllHyperVSnapshots([string[]]$clusterName){ function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709…

PowerShell: Enabling and Disabling Network Level Authentication (NLA)

NLA is Microsoft's answer to mitigate some DDoS attacks via remote desktop (RDP). It uses…

PowerShell: Set VM Dynamic Memory in Virtual Machine Manager

# setVmDynamicMemoryInVmm.ps1 # Optimize Dynamic RAM $minGb='16GB' $maxGb='32GB' $startupGb='2GB' $buffer=20 $memoryWeight=5000 $forcedRestart=$false $vmmServer='localhost' function getUnoptimizedMemoryVms{…