simple services retreival and optional export

This commit is contained in:
2026-03-29 22:42:14 +02:00
commit 49696eb0a1
4 changed files with 245 additions and 0 deletions

31
CustomObject.psm1 Normal file
View File

@@ -0,0 +1,31 @@
function Get-Services{
param(
[string]$searchName = "*",
[string]$status = "*",
[string]$export,
[string]$path
)
$results = @()
if ($export -and -not $path) {
throw "Wenn -export verwendet wird, muss auch -path angegeben werden."
}
Get-Service | ForEach-Object {
$results += [PSCustomObject]@{
Name = $_.Name
DisplayName = $_.DisplayName
Status = $_.Status
}
}
$results = $results | Where-Object { $_.DisplayName -like $searchName -and $_.Status -like $status }
switch ($export) {
json { $results | ConvertTo-Json | Out-File ".\services.json" }
csv { $results | Export-Csv -Path "services.csv" -NoTypeInformation }
}
return $results
}