Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase
# ==============================================================================
# CONFIGURATION: ADD, REMOVE, OR MODIFY YOUR BLOCKS HERE
# ==============================================================================
$ReportCards = @(
@{
Title = "AWS Disk Info"
Description = "Get disk usage and storage details for AWS EC2 instances."
Script = "AWSDiskInfo.ps1"
Color = "#F5A623" # Orange Accent
BgColor = "#FFF8F0"
},
@{
Title = "Azure Disk Info"
Description = "Get disk usage and storage details for Azure VMs."
Script = "AzureDiskInfo.ps1"
Color = "#0078D4" # Blue Accent
BgColor = "#F0F7FF"
},
@{
Title = "MS SQL Disk Info"
Description = "Get disk usage and storage details for SQL Server instances."
Script = "MSSQLDiskInfo.ps1"
Color = "#D9534F" # Red Accent
BgColor = "#FFF0F0"
},
@{
Title = "SQL Backup Info"
Description = "Get backup details, status and history for SQL Server."
Script = "SQLBackupInfo.ps1"
Color = "#6F42C1" # Purple Accent
BgColor = "#F5F0FF"
},
@{
Title = "SQL Health Status"
Description = "Get overall health status of SQL Server instances and databases."
Script = "SQLHealthStatus.ps1"
Color = "#28A745" # Green Accent
BgColor = "#F0FFF4"
}
)
# Base Window XAML Template (Fully Compatible with Windows Server 2016)
[xml]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Server Report Center" Height="550" Width="1100"
WindowStartupLocation="CenterScreen"
WindowStyle="None" AllowsTransparency="False"
Background="#F8F9FA" Foreground="#212529"
FontFamily="Segoe UI" SnapsToDevicePixels="True">
<Window.Resources>
<!-- Style for Window Control Buttons (Min/Max/Close) -->
<Style x:Key="CaptionBtnStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Width" Value="45"/>
<Setter Property="Height" Value="40"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="border" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Background" Value="#106EBE"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- Specific Hover style for Close Button (Red) -->
<Style x:Key="CloseBtnStyle" TargetType="Button" BasedOn="{StaticResource CaptionBtnStyle}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#E81123"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<!-- Outer Border with Background and Border -->
<Border Background="#F8F9FA" BorderBrush="#0078D4" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"/> <!-- Header & Window Title Bar -->
<RowDefinition Height="250"/> <!-- Cards Area -->
<RowDefinition Height="*"/> <!-- Terminal / Status Log -->
</Grid.RowDefinitions>
<!-- Blue Top Header Bar -->
<Border Grid.Row="0" Background="#0078D4" x:Name="TitleBar">
<Grid>
<!-- App Title Text -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="Server Report Center" FontSize="20" FontWeight="Bold" Foreground="White"/>
</StackPanel>
<!-- Custom Window Control Buttons using XAML Path vector graphics -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top">
<Button x:Name="BtnMinimize" Style="{StaticResource CaptionBtnStyle}">
<Path Data="M0,8 L10,8" Stroke="White" StrokeThickness="1.5" />
</Button>
<Button x:Name="BtnMaximize" Style="{StaticResource CaptionBtnStyle}">
<Path Data="M0,0 L10,0 L10,10 L0,10 Z" Stroke="White" StrokeThickness="1" Fill="Transparent" />
</Button>
<Button x:Name="BtnClose" Style="{StaticResource CloseBtnStyle}">
<Path Data="M0,0 L10,10 M10,0 L0,10" Stroke="White" StrokeThickness="1.5" />
</Button>
</StackPanel>
</Grid>
</Border>
<!-- Dynamic Cards Grid Container -->
<Grid x:Name="CardGrid" Grid.Row="1" Margin="15,15,15,5">
<!-- Columns generated dynamically in PowerShell -->
</Grid>
<!-- Status & Console Log View -->
<Border Grid.Row="2" Background="#1E1E1E" CornerRadius="4" Margin="20,5,20,15" Padding="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Status Information" Foreground="#89B4FA" FontWeight="Bold" FontSize="12" Margin="0,0,0,5"/>
<TextBox x:Name="TxtLog" Grid.Row="1" Background="Transparent" Foreground="#DCDCDC" BorderThickness="0"
FontFamily="Consolas" FontSize="12" IsReadOnly="True" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"/>
</Grid>
</Border>
</Grid>
</Border>
</Window>
"@
# Read XML
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$window = [Windows.Markup.XamlReader]::Load($reader)
# Get Controls
$CardGrid = $window.FindName("CardGrid")
$TxtLog = $window.FindName("TxtLog")
$TitleBar = $window.FindName("TitleBar")
$BtnMinimize = $window.FindName("BtnMinimize")
$BtnMaximize = $window.FindName("BtnMaximize")
$BtnClose = $window.FindName("BtnClose")
# Enable Window Dragging on the Blue Header Bar
$TitleBar.Add_MouseLeftButtonDown({ $window.DragMove() })
# Handle Custom Window Buttons
$BtnMinimize.Add_Click({ $window.WindowState = [System.Windows.WindowState]::Minimized })
$BtnMaximize.Add_Click({
if ($window.WindowState -eq [System.Windows.WindowState]::Maximized) {
$window.WindowState = [System.Windows.WindowState]::Normal
} else {
$window.WindowState = [System.Windows.WindowState]::Maximized
}
})
$BtnClose.Add_Click({ $window.Close() })
# Output Logger Helper
function Write-Log {
param([string]$Message)
$TimeStamp = Get-Date -Format "HH:mm:ss"
$TxtLog.AppendText("[$TimeStamp] $Message`n")
$TxtLog.ScrollToEnd()
$window.Dispatcher.Invoke([Action]{}, [System.Windows.Threading.DispatcherPriority]::Background)
}
# Run Script Helper
function Execute-ReportScript {
param([string]$ScriptName, [string]$ReportTitle)
$ScriptPath = "C:\Test\PowerShellScripts\$ScriptName"
Write-Log "Initiating: $ReportTitle..."
if (Test-Path $ScriptPath) {
try {
$output = & $ScriptPath | Out-String
if ($output) { Write-Log $output.Trim() }
Write-Log "SUCCESS: $ReportTitle executed successfully."
} catch {
Write-Log "ERROR: Failed to run $ReportTitle.`n$_"
}
} else {
Write-Log "WARNING: Could not locate file at $ScriptPath"
}
}
# Dynamic Card Generation
for ($i = 0; $i -lt $ReportCards.Count; $i++) {
$card = $ReportCards[$i]
# Add Column Definition
$colDef = New-Object System.Windows.Controls.ColumnDefinition
$colDef.Width = New-Object System.Windows.GridLength(1, [System.Windows.GridUnitType]::Star)
$CardGrid.ColumnDefinitions.Add($colDef)
# Build Card XML Template Dynamically with Compatible Vector Button Icons
[xml]$cardXaml = @"
<Border xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Background="$($card.BgColor)" BorderBrush="$($card.Color)" BorderThickness="1.5" CornerRadius="6" Margin="5">
<Grid Margin="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" HorizontalAlignment="Center">
<TextBlock Text="$($card.Title)" FontSize="14" FontWeight="Bold" Foreground="#212529" HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap"/>
<Rectangle Height="3" Width="30" Fill="$($card.Color)" Margin="0,5,0,0"/>
</StackPanel>
<TextBlock Grid.Row="1" Text="$($card.Description)" TextWrapping="Wrap" TextAlignment="Center" FontSize="11" Foreground="#6C757D" VerticalAlignment="Center"/>
<Button Grid.Row="2" Foreground="White" FontWeight="Bold" FontSize="13" Height="36" Cursor="Hand" BorderThickness="0">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Background="$($card.Color)" CornerRadius="4">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Path Data="M0,0 L8,5 L0,10 Z" Fill="White" Margin="0,0,6,0" />
<TextBlock Text="Run Report" Foreground="White" FontWeight="Bold" FontSize="12"/>
</StackPanel>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</Border>
"@
$cardReader = (New-Object System.Xml.XmlNodeReader $cardXaml)
$borderElement = [Windows.Markup.XamlReader]::Load($cardReader)
[System.Windows.Controls.Grid]::SetColumn($borderElement, $i)
$btn = $borderElement.Child.Children[2]
$btn.Add_Click({
Execute-ReportScript -ScriptName $card.Script -ReportTitle $card.Title
}.GetNewClosure())
$CardGrid.Children.Add($borderElement) | Out-Null
}
Write-Log "System initialized with $($ReportCards.Count) report modules."
# Render Window
$window.ShowDialog() | Out-Null
Post a Comment