simple services retreival and optional export
This commit is contained in:
31
CustomObject.psm1
Normal file
31
CustomObject.psm1
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user