Maintain good documentation (especially up-to-date) it’s a very important requirement in every workplace or project.
So why don’t we focus on this subject some of the automation tasks? Starting with a basic PowerShell script that will help us to save time and bring us value on a daily basis.
In this example Get-SimpleServerDoc we will store on a local folder all server and features installed on one or more windows server. More then an inventory will describe the requirements and the characteristics of our environment.
Looking at the example is easy to run that script on all servers in a specific OU / Domain or using a list from a file if desired.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
Import-Module ServerManager function Get-SimpleServerDoc{ <# .Synopsis Create a text file with the the roles and feature installed and export in a text file on a local folder. .Description Create a text file with the the roles and feature installed and export in a text file on a local folder. .Example Get-SimpleServerDoc -computername "lab-win-01" .Example get-adcomputer -searchbase ‘OU=server,dc=contoso,dc=com’ -filter * -property * | select name | Get-SimpleServerDoc .Notes Author: Paolo Frigo - https://www.scriptinglibrary.com #> Param( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [Alias('name')] [string[]]$ComputerName ) process{ Write-Output $ComputerName $path = "c:\doc\$ComputerName" New-Item -ItemType Directory -Force -Path $path (get-windowsfeature -computername "$ComputerName" | where {$_.installed} | select name).name | Out-File "$path\features_installed.txt" } } |
Every time I write documentation my aim is to keep it simple.
This script is just a starting point with a lot of possible improvements.
We can save them on a shared folder for example or run the script periodically as a scheduled task, so the documentation will be automatically generated.
If documentation consists of a simple text file or even an HTML ad if that folder is the website folder of IIS can be a simple webpage with this code:
1 |
(get-windowsfeature -computername "$ComputerName" | where {$_.installed} | select name).name | | ConvertTo-HTML | Out-File "$path\features_installed.txt" |
Text files can be used for re-deploy the server with this oneliner:
1 |
foreach ($feature in (get-content -Path "C:\installed-feature.txt")) {Install-WindowsFeature -ComputerName lab-win-test01 -IncludeAllSubFeature $feature} |
But you can also save other important files or configuration file as well or the services with the startup type automatic :
1 |
get-service | ? {$_.StartType -eq "Automatic"} | select name |