Another sample Powershell script to exporting “Running” and “Stopped” windows service to excel by using Powershell Array.
1 2 3 4 5 6 7 8 9 10 11 12 |
$location = “C:\sathiya.io”; $service = @(“Running”, “Stopped”); for ($i=0;$i -ne 2;$i++) { $text = $service[$i]; #Exporting the result to the text file # Append – This keyword is to update the file in the loop # Select – To export the field that you want to export Get-Service |?{$_.Status -eq “running”} | Select ServiceName, Status | Out-File $location\text1.txt -Append #Exporting the result to CSV Get-Service |?{$_.Status -eq $text} | Select ServiceName, Status | export-csv $location\file2.csv -Append } |
Cheers!