public/Get-GDDomainRecord.ps1
Set-StrictMode -Version Latest function Get-GDDomainRecord { [CmdletBinding(DefaultParameterSetName = 'Secure')] param( [parameter(ParameterSetName = 'Secure', Mandatory = $true)] [parameter(ParameterSetName = 'SecureNames', Mandatory = $true)] [parameter(ParameterSetName = 'SecureDomain', Mandatory = $true)] [parameter(ParameterSetName = 'SecureRecords', Mandatory = $true)] [string] $key, [parameter(ParameterSetName = 'Secure', Mandatory = $true)] [parameter(ParameterSetName = 'SecureNames', Mandatory = $true)] [parameter(ParameterSetName = 'SecureDomain', Mandatory = $true)] [parameter(ParameterSetName = 'SecureRecords', Mandatory = $true)] [securestring] $secret, [parameter(ParameterSetName = 'Credentials', Mandatory = $true)] [parameter(ParameterSetName = 'CredentialsNames', Mandatory = $true)] [parameter(ParameterSetName = 'CredentialsDomain', Mandatory = $true)] [parameter(ParameterSetName = 'CredentialsRecords', Mandatory = $true)] [System.Management.Automation.PSCredential] $credentials, [parameter(Mandatory = $true)] [parameter(ParameterSetName = 'SecureNames', Mandatory = $true)] [parameter(ParameterSetName = 'SecureDomain', Mandatory = $true)] [parameter(ParameterSetName = 'CredentialsNames', Mandatory = $true)] [parameter(ParameterSetName = 'CredentialsDomain', Mandatory = $true)] [string] $domain, [parameter(ParameterSetName = 'SecureNames', Mandatory = $true)] [parameter(ParameterSetName = 'CredentialsNames', Mandatory = $true)] [ValidateSet('A', 'AAAA', 'CNAME', 'MX', 'NS', 'SOA', 'SRV', 'TXT')] [string] $type, [parameter(ParameterSetName = 'SecureNames')] [parameter(ParameterSetName = 'CredentialsNames')] [string] $name ) Begin { } Process { if ($credentials) { $key = $credentials.UserName $PlainSecret = _convertSecureStringTo_PlainText -SecureString $credentials.Password } else { $PlainSecret = _convertSecureStringTo_PlainText -SecureString $secret } $sb = New-Object System.Text.StringBuilder $null = $sb.Append("https://api.godaddy.com/v1/domains/$domain/records") if($type -ne ''){ $null = $sb.Append("/$type") } if($name -ne ''){ $null = $sb.Append("/$name") } $Headers = @{accept = 'application/json'; Authorization = "sso-key $($key):$($PlainSecret)"} Invoke-RestMethod -Uri "$($sb.ToString())" -Headers $Headers -Method Get } End { } } |