Functions/Invoke-ResetClientAdmin.ps1
<#
.SYNOPSIS Resets the Client-Admin password .DESCRIPTION Generates a random password and sets it on the Client-Admin account .EXAMPLE Invoke-ResetClientAdmin Description ----------- Sets and returns a new Client-Admin Password #> function Invoke-ResetClientAdmin { [CmdletBinding()] [OutputType([String])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] Param() Begin { Import-Module -Name ActiveDirectory $Password = (Get-Random -Count 14 -InputObject (33..122 | ForEach-Object {([char]$_).ToString()}).ToCharArray()) -join '' } Process { try { Set-ADAccountPassword -Identity Client-Admin -NewPassword (ConvertTo-SecureString -AsPlainText -Force -String $Password) -Reset } catch { throw } return $Password } End { Remove-Variable Password } } |