diff --git a/Powershell/Lists/Azure/FrontDoorRoutes.ps1 b/Powershell/Lists/Azure/FrontDoorRoutes.ps1 new file mode 100644 index 0000000..278c19f --- /dev/null +++ b/Powershell/Lists/Azure/FrontDoorRoutes.ps1 @@ -0,0 +1,77 @@ +# .\FrontDoorRoutes.ps1 -SubscriptionId "4820b5d8-cc1d-49bd-93e5-0c7a656371b7" -ResourceGroupName "my-effectory-global" -FrontDoorName "my-effectory-frontDoor" + +param( + [Parameter(Mandatory=$false)] + [string]$SubscriptionId, + + [Parameter(Mandatory=$true)] + [string]$ResourceGroupName, + + [Parameter(Mandatory=$true)] + [string]$FrontDoorName +) + +[string] $date = Get-Date -Format "yyyy-MM-dd HHmm" +$fileName = ".\$date Front Door Routes ($FrontDoorName).csv" + +# Connect to Azure if not already connected +if (-not (Get-AzContext)) { + Connect-AzAccount +} + +# Select subscription if provided +if ($SubscriptionId) { + Select-AzSubscription -SubscriptionId $SubscriptionId + Write-Host "Selected subscription: $SubscriptionId" -ForegroundColor Yellow +} + +try { + # Get Front Door profile + $frontDoor = Get-AzFrontDoorCdnProfile -ResourceGroupName $ResourceGroupName -Name $FrontDoorName + + if (-not $frontDoor) { + Write-Error "Front Door '$FrontDoorName' not found in resource group '$ResourceGroupName'" + return + } + + # Get all endpoints + $endpoints = Get-AzFrontDoorCdnEndpoint -ResourceGroupName $ResourceGroupName -ProfileName $FrontDoorName + + $routeData = @() + + foreach ($endpoint in $endpoints) { + # Get routes for each endpoint + $routes = Get-AzFrontDoorCdnRoute -ResourceGroupName $ResourceGroupName -ProfileName $FrontDoorName -EndpointName $endpoint.Name + + foreach ($route in $routes) { + # Get origin group details + $originGroupId = $route.OriginGroupId + $originGroupName = ($originGroupId -split '/')[-1] + + $origins = Get-AzFrontDoorCdnOrigin -ResourceGroupName $ResourceGroupName -ProfileName $FrontDoorName -OriginGroupName $originGroupName + + foreach ($origin in $origins) { + $routeData += [PSCustomObject]@{ + FrontDoorName = $FrontDoorName + EndpointName = $endpoint.Name + RouteName = $route.Name + RoutePatterns = ($route.PatternsToMatch -join '; ') + RouteUrl = "https://$($endpoint.HostName)" + OriginGroupName = $originGroupName + OriginName = $origin.Name + OriginUrl = $origin.HostName + OriginEnabled = $origin.EnabledState + RouteEnabled = $route.EnabledState + } + } + } + } + + # Export to CSV + Write-Host "Exporting Front Door routes to: $fileName" -ForegroundColor Green + $routeData | Export-Csv -Path $fileName -NoTypeInformation -Force + + +} catch { + Write-Error "Error retrieving Front Door routes: $($_.Exception.Message)" +} \ No newline at end of file diff --git a/Powershell/Lists/DevOps/PullRequests.ps1 b/Powershell/Lists/DevOps/PullRequests.ps1 index fc4d1d6..9c6fa9e 100644 --- a/Powershell/Lists/DevOps/PullRequests.ps1 +++ b/Powershell/Lists/DevOps/PullRequests.ps1 @@ -26,7 +26,7 @@ $repos = az repos list --organization "https://dev.azure.com/effectory/" --proj foreach ($repo in $repos) { $prs = az repos pr list --project "survey software" --repository "$($repo.name)" --organization "https://dev.azure.com/effectory/" --status all | ConvertFrom-Json | Select-Object - + [PullRequest[]]$Result = @() foreach ($pr in $prs) diff --git a/SQL/GetDatabaseSizes.sql b/SQL/GetDatabaseSizes.sql new file mode 100644 index 0000000..e2ed550 --- /dev/null +++ b/SQL/GetDatabaseSizes.sql @@ -0,0 +1,80 @@ +IF OBJECT_ID('tempdb.dbo.#space') IS NOT NULL + DROP TABLE #space + +CREATE TABLE #space ( + database_id INT PRIMARY KEY + , data_used_size DECIMAL(18,2) + , log_used_size DECIMAL(18,2) +) + +DECLARE @SQL NVARCHAR(MAX) + +SELECT @SQL = STUFF(( + SELECT ' + USE [' + d.name + '] + INSERT INTO #space (database_id, data_used_size, log_used_size) + SELECT + DB_ID() + , SUM(CASE WHEN [type] = 0 THEN space_used END) + , SUM(CASE WHEN [type] = 1 THEN space_used END) + FROM ( + SELECT s.[type], space_used = SUM(FILEPROPERTY(s.name, ''SpaceUsed'') * 8. / 1024) + FROM sys.database_files s + GROUP BY s.[type] + ) t;' + FROM sys.databases d + WHERE d.[state] = 0 + FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 2, '') + +EXEC sys.sp_executesql @SQL + +SELECT + d.database_id + , d.name + , d.state_desc + , d.recovery_model_desc + , t.total_size + , t.data_size + , s.data_used_size + , t.log_size + , s.log_used_size + , bu.full_last_date + , bu.full_size + , bu.log_last_date + , bu.log_size +FROM ( + SELECT + database_id + , log_size = CAST(SUM(CASE WHEN [type] = 1 THEN size END) * 8. / 1024 AS DECIMAL(18,2)) + , data_size = CAST(SUM(CASE WHEN [type] = 0 THEN size END) * 8. / 1024 AS DECIMAL(18,2)) + , total_size = CAST(SUM(size) * 8. / 1024 AS DECIMAL(18,2)) + FROM sys.master_files + GROUP BY database_id +) t +JOIN sys.databases d ON d.database_id = t.database_id +LEFT JOIN #space s ON d.database_id = s.database_id +LEFT JOIN ( + SELECT + database_name + , full_last_date = MAX(CASE WHEN [type] = 'D' THEN backup_finish_date END) + , full_size = MAX(CASE WHEN [type] = 'D' THEN backup_size END) + , log_last_date = MAX(CASE WHEN [type] = 'L' THEN backup_finish_date END) + , log_size = MAX(CASE WHEN [type] = 'L' THEN backup_size END) + FROM ( + SELECT + s.database_name + , s.[type] + , s.backup_finish_date + , backup_size = + CAST(CASE WHEN s.backup_size = s.compressed_backup_size + THEN s.backup_size + ELSE s.compressed_backup_size + END / 1048576.0 AS DECIMAL(18,2)) + , RowNum = ROW_NUMBER() OVER (PARTITION BY s.database_name, s.[type] ORDER BY s.backup_finish_date DESC) + FROM msdb.dbo.backupset s + WHERE s.[type] IN ('D', 'L') + ) f + WHERE f.RowNum = 1 + GROUP BY f.database_name +) bu ON d.name = bu.database_name +ORDER BY t.total_size DESC \ No newline at end of file diff --git a/SQL/GetTableSizes.sql b/SQL/GetTableSizes.sql new file mode 100644 index 0000000..ebe1741 --- /dev/null +++ b/SQL/GetTableSizes.sql @@ -0,0 +1,28 @@ +SELECT + t.name AS TableName, + s.name AS SchemaName, + p.rows, + SUM(a.total_pages) * 8 AS TotalSpaceKB, + CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB, + SUM(a.used_pages) * 8 AS UsedSpaceKB, + CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, + (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB, + CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB +FROM + sys.tables t +INNER JOIN + sys.indexes i ON t.object_id = i.object_id +INNER JOIN + sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id +INNER JOIN + sys.allocation_units a ON p.partition_id = a.container_id +LEFT OUTER JOIN + sys.schemas s ON t.schema_id = s.schema_id +WHERE + t.name NOT LIKE 'dt%' + AND t.is_ms_shipped = 0 + AND i.object_id > 255 +GROUP BY + t.name, s.name, p.rows +ORDER BY + TotalSpaceMB DESC, t.name \ No newline at end of file