Public/Set-IdracIPv4.ps1
Function Set-IdracIPv4{ [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='None')] Param ( [Parameter(Mandatory = $true)] [string]$iDRACName, [string]$Address, [string]$Gateway, [string[]]$DNS, [System.Management.Automation.PSCredential]$Credential ) begin{ $commandArray = @() if ($PSBoundParameters.ContainsKey('Address')){ $commandArray += "racadm set idrac.IPv4.Address $Address" } if ($PSBoundParameters.ContainsKey('Gateway')){ $commandArray += "racadm set idrac.IPv4.Address $Gateway" } if ($PSBoundParameters.ContainsKey('DNS')){ $i = 1 foreach ($item in $DNSServer){ $commandArray += "racadm set iDRAC.IPv4.DNS$i $item" if ($i -ge 2){ break } $i++ } } $session = New-iDRACSession -iDRACName $iDRACName -Credential $Credential } process{ foreach ($line in $commandArray){ if($PSCmdlet.ShouldProcess( "Verbose Description !", "Set Resource " + "Caption")){ if($PSCmdlet.ShouldProcess( "Verbose Description !", "Set Resource " + "Caption")){ $result = Invoke-SshCommand -Command $line -SSHSession $session $msg = $result.Host.ToUpper() + " - " + $result.Output Write-Verbose -Message $msg } } } } End{ $session | Remove-SSHSession | Out-Null } } |