#using module .\build\Effectory.Dns\0.0.1\Effectory.Dns.psm1

# .\build.ps1

#Import-Module .\Output\Effectory.Dns\0.0.1\Effectory.Dns.psm1 -Force

Import-Module .\build\Effectory.Dns\0.0.1\Effectory.Dns.psm1 -Force

Start-Transcript -Path .\output.txt

Import-Module .\Effectory.Dns -Force

$connectionString = "DefaultEndpointsProtocol=https;AccountName=runbookseffectory;AccountKey=QGi10UPphKRVehtiBhxca0XLaWZeg5woa5cTckS93NLECF1i4ggmAoEQiirz6JRyyOmDMwzjuZuef+0TgixwfA==;EndpointSuffix=core.windows.net"

$subscriptions = Get-AzSubscription | Where-Object State -eq "Enabled"

[EffectoryDomainNameCheck[]]$effectoryResources = @()

foreach ($subscription in $subscriptions) 
{
    $items = Get-EffectoryDomainResources -subscriptionId $subscription.Id -effectoryDomainPattern "*.effectory.com"
    $effectoryResources = $effectoryResources + $items
}

#$effectoryResources = Get-EffectoryDomainResources -subscriptionId "a134faf1-7a89-4f2c-8389-06d00bd5e2a7" -effectoryDomainPattern "*.effectory.com"
$effectoryResourcesPrevious = Get-BlobEffectoryDomainResources -connectionString $connectionString
$result = VerifyEffectoryDomainResources  -effectoryDomainPattern "*.effectory.com" -effectoryResources $effectoryResources -effectoryResourcesPrevious $effectoryResourcesPrevious
Set-BlobEffectoryDomainResources -connectionString $connectionString -effectoryResources $effectoryResources

if ($result -eq $true) {
    Write-Error ("FOUND ERRORS!")
}

Stop-Transcript