95 lines
2.9 KiB
PowerShell
95 lines
2.9 KiB
PowerShell
param(
|
|
[string]$CsvPath = "path_to_your_csv_file.csv",
|
|
[int]$RowLimit = -1, # -1 means process all rows
|
|
[string]$ApplicationName = ""
|
|
)
|
|
|
|
# Function to import CSV data with optional row limit
|
|
function Import-LimitedCsv {
|
|
param(
|
|
[string]$Path,
|
|
[int]$Limit = -1
|
|
)
|
|
|
|
$csv = Import-Csv -Path $Path
|
|
if ($Limit -gt 0) {
|
|
return $csv | Select-Object -First $Limit
|
|
}
|
|
return $csv
|
|
}
|
|
|
|
function Write-OutputBoth {
|
|
param(
|
|
[string]$Message,
|
|
[System.IO.StreamWriter]$Writer
|
|
)
|
|
Write-Host $Message
|
|
$Writer.WriteLine($Message)
|
|
}
|
|
|
|
$outputFileName = if ($ApplicationName) {
|
|
"$($ApplicationName.Replace(' ', '_').ToLower())_results.txt"
|
|
} else {
|
|
"all_applications_results.txt"
|
|
}
|
|
|
|
$outputDir = "output"
|
|
if (-not (Test-Path -Path $outputDir)) {
|
|
New-Item -ItemType Directory -Force -Path $outputDir
|
|
}
|
|
|
|
$outputFilePath = Join-Path $outputDir $outputFileName
|
|
|
|
# Import the CSV file with optional row limit
|
|
$csvData = Import-LimitedCsv -Path $CsvPath -Limit $RowLimit
|
|
|
|
# Define operations to ignore
|
|
$ignoredOperations = @("Resume Databases", "UpdateWebSite")
|
|
|
|
# Filter out items with "Started" status and group by "Event initiated by"
|
|
$groupedData = $csvData |
|
|
Where-Object { $_."Status" -ne "Started" -and $_."Operation name" -notin $ignoredOperations } |
|
|
Group-Object -Property "Event initiated by"
|
|
|
|
if ($ApplicationName) {
|
|
$groupedData = $groupedData | Where-Object { $_.Name -eq $ApplicationName }
|
|
}
|
|
|
|
$writer = [System.IO.StreamWriter]::new("$OutputFilePath.raw")
|
|
|
|
try {
|
|
# Process each group
|
|
foreach ($group in $groupedData) {
|
|
Write-Host "Application: $($group.Name)"
|
|
Write-Host "------------------------"
|
|
|
|
$resourceTypes = $group.Group |
|
|
Select-Object "Resource type", "Operation name" -Unique |
|
|
Group-Object -Property "Resource type"
|
|
|
|
foreach ($resourceType in $resourceTypes) {
|
|
Write-OutputBoth "$($resourceType.Name)" $writer
|
|
}
|
|
Write-Host ""
|
|
}
|
|
|
|
$totalRows = $csvData.Count
|
|
$processedRows = ($csvData | Where-Object { $_."Status" -ne "Started" -and $_."Operation name" -notin $ignoredOperations}).Count
|
|
if ($ApplicationName) {
|
|
$processedRows = ($groupedData | Where-Object { $_.Name -eq $ApplicationName }).Group.Count
|
|
}
|
|
$skippedRows = $totalRows - $processedRows
|
|
|
|
Write-Host "Total rows in CSV: $totalRows"
|
|
Write-Host "Rows processed: $processedRows"
|
|
Write-Host "Rows skipped (Started status, ignored operations, or non-matching application): $skippedRows"
|
|
Write-Host "Ignored operations: $($ignoredOperations -join ', ')"
|
|
if ($ApplicationName) {
|
|
Write-Host "Filtered by application: $ApplicationName"
|
|
}
|
|
Write-Host ""
|
|
Write-Host "Results have been saved to: $outputFileName"
|
|
}
|
|
finally {
|
|
$writer.Close()
|
|
} |