32 lines
804 B
PowerShell
32 lines
804 B
PowerShell
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
|
|
}
|