mirror of
https://dev.azure.com/effectory/Survey%20Software/_git/Cloud%20Engineering
synced 2026-02-27 18:52:18 +01:00
- Added servicebus list script #117926 - Added scripts to list storage blobs and tables #115638 Related work items: #117926
112 lines
3.8 KiB
PowerShell
112 lines
3.8 KiB
PowerShell
class HostCheck {
|
|
[string] $HostName = ""
|
|
[string] $Fqdn = ""
|
|
[string] $CName = ""
|
|
[string] $IpAddress = ""
|
|
[string] $CNameChain = ""
|
|
[bool] $Exists = $false
|
|
[bool] $RegisteredInExternalDNS = $false
|
|
[string] $Owner = ""
|
|
[string] $Comment = ""
|
|
}
|
|
|
|
function HostExistsInExternal ([HostCheck] $hostCheck, [string] $ExternalDNSServer) {
|
|
try {
|
|
$CnameChain = resolve-dnsname -name $hostCheck.Fqdn -NoHostsFile -Server $ExternalDNSServer -ErrorAction Ignore
|
|
|
|
for ($i = 0; $i -lt $CnameChain.Count; $i++) {
|
|
$chainItem = $CnameChain[$i]
|
|
if ($chainItem.NameHost) {
|
|
$hostCheck.CNameChain = "$($hostCheck.CNameChain) -> $($chainItem.NameHost)"
|
|
if ($chainItem.NameHost -ieq $hostCheck.CName) {
|
|
$hostCheck.RegisteredInExternalDNS = $true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch {
|
|
$hostCheck.RegisteredInExternalDNS = $false
|
|
}
|
|
|
|
return $hostCheck
|
|
}
|
|
|
|
function GetIPAddress ([HostCheck] $hostCheck) {
|
|
try {
|
|
$hostAddresses = [System.Net.Dns]::GetHostAddresses($hostCheck.Fqdn)
|
|
$hostCheck.IpAddress = $hostAddresses.IPAddressToString
|
|
|
|
}
|
|
catch {
|
|
try {
|
|
$hostAddresses = [System.Net.Dns]::GetHostAddresses($hostCheck.HostName)
|
|
|
|
$hostCheck.IpAddress = $hostAddresses.IPAddressToString
|
|
}
|
|
catch {
|
|
$hostCheck.IpAddress = ""
|
|
}
|
|
|
|
}
|
|
return $hostCheck
|
|
}
|
|
|
|
function TestIPConnection ([HostCheck] $hostCheck) {
|
|
try {
|
|
if (Test-Connection -TargetName $hostCheck.IpAddress -Count 1 -Quiet) {
|
|
$hostCheck.Exists = $true
|
|
}
|
|
else {
|
|
$hostCheck.Exists = $false
|
|
}
|
|
}
|
|
catch {
|
|
$hostCheck.Exists = $false
|
|
}
|
|
return $hostCheck
|
|
}
|
|
|
|
function Effectory-DNSVerify-Csv ([string[]] $FileName, [string] $ExternalDNSServer = "8.8.8.8") {
|
|
Clear-DnsClientCache
|
|
|
|
$DNSRecords = import-csv $FileName
|
|
|
|
# HostName,Cname,Fqdn
|
|
# accept-authorization,authorization-web-api-accept.azurewebsites.net,accept-authorization.effectory.com
|
|
# accept-customer,test-customer-effectory-accept.azurewebsites.net,accept-customer.effectory.com
|
|
# accept-ecestore,test-ecestore-accept.azurewebsites.net,accept-ecestore.effectory.com
|
|
|
|
[HostCheck[]]$Result = @()
|
|
foreach ($DNSRecord in $DNSRecords) {
|
|
|
|
[HostCheck] $hostCheck = [HostCheck]::new()
|
|
$hostCheck.HostName = $DNSRecord.ExternalDNS
|
|
$hostCheck.CName = $DNSRecord.To
|
|
$hostCheck.Owner = $DNSRecord.Owner
|
|
$hostCheck.Comment = $DNSRecord.Comment
|
|
$hostCheck.Fqdn = "$($DNSRecord.ExternalDNS).effectory.com"
|
|
|
|
$hostCheck = HostExistsInExternal -hostCheck $hostCheck -ExternalDNSServer $ExternalDNSServer
|
|
$hostCheck = GetIPAddress -hostCheck $hostCheck
|
|
$hostCheck.Exists = $hostCheck.IpAddress -ne ""
|
|
|
|
$Result += $hostCheck
|
|
}
|
|
|
|
return $Result
|
|
}
|
|
|
|
|
|
#Connect-AzAccount
|
|
|
|
#Effectory-DNSVerify -ZoneName "effectory.com" -DNSServer "DC1.effectory.local" -ExternalDNSServer "8.8.8.8" | Export-Csv -Path ".\2021-06-01 DNS-effectory-com.csv"
|
|
#Effectory-DNSVerify -ZoneName "effectory.local" -DNSServer "DC1.effectory.local" -ExternalDNSServer "DC2.effectory.local" -DoIpCheck $true | Export-Csv -Path ".\2021-06-01 DNS-effectory-local.csv"
|
|
#Effectory-DNSVerify-Csv -FileName .\vip-effectory-com.csv -ExternalDNSServer "8.8.8.8" | Export-Csv -Path ".\2021-06-01 DNS-vip-effectory-com.csv"
|
|
#Effectory-GetAppServiceHostNames | Export-Csv -Path ".\2021-06-01 AppService Hosts.csv"
|
|
#Effectory-GetFrontDoorHostNames | Export-Csv -Path ".\2021-06-01 FrontDoor Hosts.csv"
|
|
|
|
# | Format-Table
|
|
# | Export-Csv -Path .\DNS-xxxx.csv
|
|
|
|
$foo = Effectory-DNSVerify-Csv -FileName "C:\tmp\Book3.csv"
|
|
$foo | Export-Csv -Path .\DNS.csv |