PowerShell Server Baseline | Project Outline
The plan here is to create a history of running services on servers so that they can be compared over time for auditing purposes. This is to assure only required, approved services are running on the servers as well as following best practices.
​
​
0) Connect and Creat the SQL Database Table to Store the Computer and Windows Service Info.
​
1) The initial run will execute the Input Script adding the server names as well as all running services found on each system into a SQL database table.
​
2) You run script the Compare Script that will Compare the historical data in SQL to the current list of services Running from servers to a file called New_Services_Found_Running.txt
​
3) The Compare Script will also generate a report.txt of servers that were not entered into the SQL database table on the initial run. This will allow you to instantly recognize new servers not in this system yet.
​
4) The Refrsh Script will take the report.txt file as input to add the missing servers and running services to the SQL database table.
​
5) Finally we will have a Update Computer Script to allow a user to update the services for a server already listed in the system. This allows updates to the system, for example if IIS was installed; these running services will need added to the SQL Table for that server.
​
The execution of the Update Computer Script will simply delete all the service entries for the server and then add the current running services to the SQL Database table.
​
6. I will also create a One Off Script to allow input from user to pull a specific server 's data from SQL and export it. So one can get a single server to review services.
Required : PowerShell SQL Module
Online Installation
Install-Module -Name SqlServer
Common CMDlets
Instance Management: Get-SqlInstance Connect-SqlInstance Database Management: Get-SqlDatabase New-SqlDatabase Remove-SqlDatabase Backup-SqlDatabase Restore-SqlDatabase SQL Agent Management: Get-SqlAgentJob New-SqlAgentJob Remove-SqlAgentJob
Steps to Load SqlServer Module from File
-
Ensure you have the module files: Verify that you have the SqlServer module files on your local machine. The module folder should contain a .psd1 (module manifest) file and possibly other related files.
-
Determine the path to the module: Identify the directory where the module files are stored. For example, if the SqlServer module files are located in C:\Modules\SqlServer.
-
Import the module: Use the Import-Module cmdlet to load the module by specifying the path to the module manifest file.
​
Example Command
Assuming the SqlServer module is located at C:\Modules\SqlServer, you can import it using the following command:
Import-Module -Name "C:\Modules\SqlServer\SqlServer.psd1"