This PowerShell script is designed to retrieve information about services running on a system, specifically those not signed by Microsoft, and output the results either to a GridView or an Excel file.
The script begins by defining two parameters: $ComputerName and $Filename. $ComputerName is an array of strings that defaults to the name of the current computer if no other value is provided. $Filename is a string that represents the name of an Excel file where the results will be stored.
The script then validates the $Filename parameter. If a filename is provided, the script checks if it ends with ‘.xlsx’. If it doesn’t, a warning is issued and the script exits. If the filename is valid, the script checks if the file already exists. If it doesn’t, the script attempts to create a new file at the specified path and then immediately deletes it. This is done to verify that the path is accessible and that a file can be created there. If the file already exists, a warning is issued stating that data will be appended to it.
Next, the script checks if the ImportExcel module is installed on the system. If it’s not, the script attempts to install it. If the installation fails, a warning is issued and the script exits. If the module is already installed or the installation is successful, the script continues.
The script then retrieves information about the services running on the system. For each service, the script checks if it’s signed by Microsoft. If it’s not, the script creates a custom object with information about the service and adds it to the $total array.
Finally, the script checks if any non-Microsoft signed services were found. If they were, the script outputs the results either to a GridView or an Excel file, depending on whether a filename was provided. If no non-Microsoft signed services were found, the script issues a message stating this.