Public/Set-IdracActiveDirectoryGroup.ps1

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

        [Parameter(Mandatory = $true)]
        [ValidateRange(1,15)]
        [int]$Id,

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

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

        [Parameter(Mandatory = $true)]
        [ValidateSet("Administrator","Operator")]
        [string]$Priviledge,

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

    begin{
        $commandArray = @()
        $commandArray += "racadm set idrac.adGroup.$Id.Domain $DomainName"
        $commandArray += "racadm set idrac.adGroup.$Id.Name $GroupName"

        $code = Get-IdracPriviledgeCode -PriviledgeName $Priviledge
        $commandArray += "racadm set idrac.adGroup.$Id.Privilege $code"

        $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
    }
}