Public/Set-IdracUser.ps1
Function Set-IdracUser{ [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='None')] Param ( [Parameter(Mandatory = $true)] [string]$iDRACName, [Parameter(Mandatory = $true)] [ValidateRange(3,16)] [int]$Id, [string]$Name = $null, [System.Security.SecureString]$Password = $null, [ValidateSet("Administrator","Operator")] [string]$Priviledge, [System.Management.Automation.PSCredential]$Credential ) begin{ $commandArray = @() if ($PSBoundParameters.ContainsKey('Name')){ $commandArray += "racadm set idrac.users.$Id.username $Name" } if ($PSBoundParameters.ContainsKey('Password')){ $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) $commandArray += "racadm set idrac.users.$Id.Password $UnsecurePassword" } if ($PSBoundParameters.ContainsKey('Priviledge')){ $code = Get-IdracPriviledgeCode -PriviledgeName $Priviledge $commandArray += "racadm set idrac.users.$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 } } |