This is what i have so far:
#Laufende Dienste
$Service = Get-Service | where{$_.Status -eq "Running"}
foreach($x in $Service){
Write-Host $x.ServiceName
}
#Standard Dienste importieren
$csvfile = Import-CSV -Path "K:\Example\Example.csv"
Foreach ($x in $csvfile) {
Write-Host $x.Name
}
#Vergleichen
Compare-Object -IncludeEqual -ExcludeDifferent $csvfil $ServiceName
The bottom part that should compare the two lists of processes doesnt seem to work tho
CodePudding user response:
To compare the property servicename retrieved by get-service with the property name of the objects from the csv file you can do:
Compare-Object -ReferenceObject (get-service).servicename -DifferenceObject (import-csv [path]).name -ExcludeDifferent -IncludeEqual
CodePudding user response:
$servicesList1 = Get-Service | Where-Object {$_.Status -eq "Running"} | Select -ExpandProperty Name
$servicesList1 | Out-File 'S:\temp1';
Stop-Service -Name 'AppleChargerSrv'
$servicesListOld = Get-Content 'S:\temp1'
$servicesListNow = Get-Service | Where-Object {$_.Status -eq "Running"} | Select -ExpandProperty Name
$servicesListDiff = Compare-Object -ReferenceObject $servicesListOld -DifferenceObject $servicesListNow
InputObject SideIndicator
----------- -------------
AppleChargerSrv <=