<# .SYNOPSIS A short one-line action-based description, e.g. 'Tests if a function is valid' .DESCRIPTION A longer description of the function, its purpose, common use cases, etc. .NOTES Information or caveats about the function e.g. 'This function is not supported in Linux' .LINK Specify a URI to a help page, this will show when Get-Help -Online is used. .EXAMPLE Test-MyTestFunction -Verbose Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines #> function New-ITDRandomPassword { [CmdletBinding()] Param ( [PSCredential] $Credential ) Begin { } Process { $InvokeRestMethodParams = @{ Method = 'Get'; Uri = 'https://itdpv.nd.gov/winapi/generatepassword/?PasswordGeneratorID=2'; ErrorAction = 'Stop'; } If ($PSBoundParameters.ContainsKey('Credential')){ $InvokeRestMethodParams += @{Credential = $Credential} } Else { $InvokeRestMethodParams += @{UseDefaultCredentials = $true} } $NewPassword = (Invoke-RestMethod @InvokeRestMethodParams).Password $Length = $NewPassword.Length While ($null -ne $NewPassword -and $Length -lt 20) { $NewPassword2 = (Invoke-RestMethod @InvokeRestMethodParams).Password $NewPassword += $NewPassword2.split('-')[1] $Length = $NewPassword.Length } If (!($NewPassword -match '\d')) { $NewPassword += (Get-Random -Minimum 0 -Maximum 9) } } End { return $NewPassword } }