-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fc2433
commit 9f49ca3
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: $?" | ||
} |