- Published on
Implement Management System
- Authors
- Name
- Jackson Chen
# Enforce to run as administrator
#Requires -RunAsAdministrator
cls
# Import modules
Import-Module -Name ServerManager, ActiveDirectory
# Variables
$Date = Get-Date -Format "yyyy-MM-dd"
$timestamp = Get-Date -UFormat "%d/%m/%Y %R"
$Computer = $env:COMPUTERNAME
$ReportPath = "D:\Logs" # Log and report directories
$ReportFile = "$ReportPath\$Computer-Jumpbox-Provisioning-Report-$Date.txt"
# List of Windows Features
# BitLocker Features
# It also requires Active Directory delegation to read Bitlocker info
$BitLockerRemoteTool = "RSAT-Feature-Tools-BitLocker-RemoteAdminTool"
$BitLockerPwdViewer = "RSAT-Feature-Tools-BitLocker-BdeAducExt"
# Group Policy Management
$GPOMgmt = "GPMC"
# Failover Clustering Tools
$FailoverClusterMgmt = "RSAT-Clustering-Mgmt"
$FailoverClusterPowerShell = "RSAT-Clustering-PowerShell"
# AD DS Tools
$ADDSTools = "RSAT-AD-Tools"
# DHCP and DNS Management Tools
$DHCPmgmt = "RSAT-DHCP"
$DNSmgmt = "RSAT-DNS-Server"
# Required Windows Features to be installed
$RequiredInstallFeatures = ($BitLockerRemoteTool,$BitLockerPwdViewer,$GPOMgmt,$ADDSTools,$DNSmgmt)
# List of software and tools
$Googlechrome = "C:\Software\GoogleChrome\googlechromestandaloneenterprise64.msi"
$WinSCP = "C:\Software\WinSCP\WinSCP-5.17.9-Setup.exe"
$putty = "C:\Software\Putty\putty-64bit-0.75-installer.msi"
$NotepadPlus = "C:\Software\Putty\npp.8.4.1.Installer.x64.exe"
# $CMTrace = "C:\Software\CMTrace.exe" # This will be used for log reading
$RequiredTools = ($Googlechrome,$WinSCP,$putty,$NotepadPlus)
# ***************************************************
# Update-Report
#
# Usage:
# Record the installation status
#
# Input:
# $InstallationStatus
# $Report
#
#***************************************************
Function Update-Report {
Param (
[Parameter (Mandatory=$true)] [String] $InstallationStatus,
[Parameter (Mandatory=$true)] [String] $Report
)
If ($InstallationStatus -like "*Success*") {
Write-Host "$InstallationStatus" -ForegroundColor Green
}
ElseIf ($InstallationStatus -like "*Failed*") {
Write-Host "$InstallationStatus" -ForegroundColor Red
}
# Update log file
"$InstallationStatus" | Add-Content $Report
}
# ***************************************************
# Install-Windows-Features
#
# Usage:
# Intall Required Windows Features
#
# Input:
# $RequiredFeatures
# $Report
#
#***************************************************
Function Install-Windows-Features {
Param (
[Parameter (Mandatory=$true)] [array] $RquiredFeatures,
[Parameter (Mandatory=$true)] [String] $Report
)
ForEach ($feature in $RquiredFeatures) {
Write-Host "Install Windows feature: $feature"
If (Get-WindowsFeature -Name $feature) {
# Install AD DS Tools and sub-features
If ($feature -like "*RSAT-AD-Tools*") {
Try {
# Install Features and Sub-Features and Management Tools
Install-WindowsFeature -Name $feature -IncludeAllSubFeature -IncludeManagementTools
$Message = "Success: AD DS Tools have been installed"
Update-Report $Message $Report
}
Catch {
$Message = "Failed: AD DS Tools have failed to be installed"
Update-Report $Message $Report }
}
Else {
Try {
# Install single feature
Install-WindowsFeature -Name $feature
$NewFeature = Get-WindowsFeature $feature
$FeatureName = $NewFeature.DisplayName
$Message = "Success: "$FeatureName has been successfully installed"
Update-Report $Message $Report
}
Catch {
$Message = "Failed: $FeatureName failed to be installed, please verify and try again."
Update-Report $Message $Report
}
}
}
Else {
Write-Host "Error: $feature is not a valid Windows feature, please verify and try again." -ForegroundColor Red
}
}
}
# ------------------------------------------------------
# Main
#
# ------------------------------------------------------
$Header = "************* Provisioning New Windows Management Jumpbox, and install requried Windows Features and tools *************"
"$Header" | Add-Content $ReportFile
$InstallTime = (Get-Date).ToString('MM/dd/yyyy hh:mm:ss tt')
"Installation at time: $InstallTime" | Add-Content $ReportFile
# Install Windows Features
Try {
# Install all the required Windows Features
Install-Windows-Features $RequiredInstallFeatures $ReportFile
}
Catch {
Write-Host "Error: Failed to install Windows Features" -ForegroundColor Red
}
# Verification
Get-WindowsFeature | ?{$_.InstallState -eq "Installed"} | Select-Object DisplayName, Name, InstallState
# Get-WindowsFeature | ?{($_.InstallState -eq "Installed") -and ($_.name -like "*bit*")} | Select-Object DisplayName, Name, InstallState
# Install Tools
"`n Install Software and Tools."
"" | | Add-Content $ReportFile
"Install requried software and tools." | Add-Content $ReportFile
ForEah ($tool in $RequiredTools) {
# Install Google Chrome
If ($tool -like "googlechrome") {
Try {
Start-Process msiexec.exe -Wait -ArgumentList "/I $Googlechrome /quiet"
$Message = "Success: Successfully install Google Chrome."
Update-Report $Message $ReportFile
}
Catch {
$Message = "Failed: Google Chrome failed to be installed."
Update-Report $Message $ReportFile
}
}
# Install Putty
ElseIf ($tool -like "*putty*") {
Try {
Start-Process msiexec.exe -Wait -ArgumentList "/I $putty /quiet"
$Message = "Success: Successfully install Putty."
Update-Report $Message $ReportFile
}
Catch {
$Message = "Failed: Putty failed to be installed."
Update-Report $Message $ReportFile
}
}
# Install WinSCP
ElseIf ($tool -like "*WinSCP*") {
Try {
$Arguments = "/verysilent /norestart /allusers"
Start-Process -FilePath $WinSCP -ArgumentList $Arguments -Wait
$Message = "Success: Successfully install WinSCP."
Update-Report $Message $ReportFile
}
Catch {
$Message = "Failed: WinSCP failed to be installed."
Update-Report $Message $ReportFile
}
}
# Install Notepad++
ElseIf ($tool -like "*npp*") {
Try {
$Arguments = "/verysilent /norestart /allusers"
Start-Process -FilePath $NotepadPlus -ArgumentList $Arguments -Wait
$Message = "Success: Successfully install Notepad++."
Update-Report $Message $ReportFile
}
Catch {
$Message = "Failed: Notepad++ failed to be installed."
Update-Report $Message $ReportFile
}
}
}