Public/Set-IdracUserDomain.ps1

Function Set-IdracUserDomain{
    [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='None')]
    Param (
        [Parameter(Mandatory = $true)]
        [string]$iDRACName,

        [Parameter(Mandatory = $true)]
        [string[]]$DomainName,

        [System.Management.Automation.PSCredential]$Credential
    )

    begin{
        $commandArray = @()

        $i = 1
        foreach ($item in $NTPServer){
            $commandArray += "racadm set idrac.userdomain.$i.Name $item $DomainName"
            if ($i -ge 41){ # Valid range is 1 to 40
                break
            }
            $i++
        }
        $session = New-iDRACSession -iDRACName $iDRACName -Credential $Credential
    }

    process{

        foreach ($line in $commandArray){
            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
    }
}