Skip to content

Commit

Permalink
Retrieving All Windows Services
Browse files Browse the repository at this point in the history
  • Loading branch information
harsharora94 authored Apr 25, 2020
1 parent 5fc2433 commit 9f49ca3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions List-All-Windows-Services.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# --------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Name : List-All-Windows-Services.ps1
# Author : Harsh Arora
# Description : This powershell script uses Get-WmiObject to retrieve all services, which are instances of the Win32_Service Class and export it to CSV format.
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------

$Logfile = "$env:SystemDrive\ListAllWindowsServices.log"
$ExportServicesCSV = "$env:SystemDrive\AvailableWindowsServices.csv"

function LogWrite([string]$logstring)
{
$DateTime = Get-Date -Format g
Add-content $Logfile -value "$DateTime $logstring"
}

$Return = Get-WMIObject Win32_Service | Select-Object DisplayName, Description, State, StartMode, StartName, PathName

If($? -eq $true)
{
Get-WMIObject Win32_Service | Select-Object DisplayName, Description, State, StartMode, StartName, PathName | Export-CSV -NoType $ExportServicesCSV
LogWrite "Exporting of all Windows Services using Get-WmiObject in CSV format at location: '$ExportServicesCSV' and returned: $?"
}
else
{
LogWrite "Failed to export all Windows Services using Get-WmiObject in CSV format at location: '$ExportServicesCSV' and returned: $?"
}

0 comments on commit 9f49ca3

Please sign in to comment.