Product: PowerShell Universal
Version: 3.7.9
Hi,
Im building a PoC for managing DNS records using a PSU dashboard, but im facing 2 minor issues.
The first one:
The bottom UD grid, should only appear once the top selection have been done. I understand that the code dosent work and it shouldnt, but i cant figure out how to make it work - any suggestions?
The second one:
On line 35 of the script, i use the -Property Recordata - but it actually have to be RecordData.IPv4Address.IPAddressToString , since the value is a subproperty.
I tried different methods (manipulating the members of the array, inserting it into another array, etc) - but none of it works - any idea?
$PermittedDomains = @("dnssample.com")
$Zones = $(Get-DnsServerZone -ComputerName $(Get-ADDomain).RIDMaster | Where-Object {$_.ZoneName -in $PermittedDomains}).ZoneName
New-UDGrid -Container -Content {
New-UDGrid -item -SmallSize 6 -Content {
New-UDCard -Title 'Select DNS zone' -Content {
New-UDStack -Direction 'column' -Content {
New-UDSelect -Option {
foreach ($DNSZone in $Zones) {
New-UDSelectOption -Name $DNSZone -Value $DNSZone
}
} -OnChange {
Show-UDToast -Message $EventData
Sync-UDElement -Id 'table'
$Session:ZoneName = $EventData
}
}
}
}
}
New-UDGrid -Container -Content {
New-UDGrid -item -SmallSize 6 -Content {
New-UDCard -Title "Select record in $($Session:ZoneName)" -Content {
New-UDStack -Direction 'column' -Content {
New-UDDynamic -Id 'table' -Content {
New-UDButton -Text 'Refresh' -OnClick {
Sync-UDElement -Id 'table'
} -Icon (New-UDIcon -Icon 'Sync') -Color info
$ZoneData = Get-DnsServerResourceRecord -ZoneName $Session:ZoneName -ComputerName $(Get-ADDomain).RIDMaster | Where-Object { $_.RecordType -eq "A" -or $_.RecordType -eq "CNAME" } | Select-Object Hostname, RecordType, RecordData
$Columns = @(
New-UDTableColumn -Property Hostname -Title "Hostname" -Filter
New-UDTableColumn -Property RecordData -Title "Record Data" -Filter
New-UDTableColumn -Property RecordType -Title "Record Type" -Filter
)
New-UDTable -Id 'DNSRecordSelection' -Data $ZoneData -Columns $Columns -ShowPagination -PageSize 15 -ShowExport -ShowSort -ShowSelection
New-UDButton -Text "Delete record" -OnClick {
$Value = Get-UDElement -Id "DNSRecordSelection"
Show-UDToast -Message "Deleting $($Value.SelectedRows.Hostname)" -Duration 3000
Try {
Remove-DnsServerResourceRecord -ZoneName $Session:ZoneName -Name $Value.SelectedRows.Hostname -ComputerName $(Get-ADDomain).RIDMaster -RRType $Value.SelectedRows.RecordType -ErrorAction stop -Confirm:$false -force
Show-UDToast -Message "Deleted $($Value.SelectedRows.Hostname)" -Duration 3000 -MessageColor green -Persistent
}
catch {
Show-UDToast -Message "Failed to delete $($Value.SelectedRows.Hostname) - $($_.Exception.Message)" -Duration 3000 -Persistent
}
} -ShowLoading
}
}
}
}
}