-
Notifications
You must be signed in to change notification settings - Fork 11
/
Deploy-BgInfo-WS2012-R2.ps1
147 lines (108 loc) · 6.34 KB
/
Deploy-BgInfo-WS2012-R2.ps1
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<#
.SYNOPSIS
A script used to download, install and configure the latest BgInfo version on a Windows Server 2012 R2.
.DESCRIPTION
A script used to download, install and configure the latest BgInfo version (v4.28) on a Windows Server 2012 R2.
The BgInfo folder will be created on the C: drive if the folder does not already exist.
Then the latest BgInfo.zip file will be downloaded and extracted in the BgInfo folder.
The LogonBgi.zip file which holds the preferred settings will also be downloaded and extracted to the BgInfo folder.
After extraction both .zip files will be deleted.
A registry key (regkey) to AutoStart the BgInfo tool in combination with the logon.bgi config file will be created.
At the end of the script BgInfo will be started for the first time and the PowerShell window will be closed.
.NOTES
File Name: Deploy-BgInfo-WS2012-R2.ps1
Created: 17/09/2018
Last modified: 16/01/2022
Author: Wim Matthyssen
PowerShell: 4.0 or above
Requires: -RunAsAdministrator
OS: Windows Server 2012 R2
Version: 2.0
Action: Change variables were needed to fit your needs
Disclaimer: This script is provided "As Is" with no warranties.
.EXAMPLE
.\Deploy-BgInfo-WS2012-R2.ps1
.LINK
https://wmatthyssen.com/2019/09/11/powershell-bginfo-automation-script-for-windows-server-2012-r2/
#>
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Variables
$bgInfoFolder = "C:\BgInfo"
$bgInfoFolderContent = $bgInfoFolder + "\*"
$itemType = "Directory"
$bgInfoUrl = "https://download.sysinternals.com/files/BGInfo.zip"
$bgInfoZip = "C:\BgInfo\BgInfo.zip"
$bgInfoEula = "C:\BgInfo\Eula.txt"
$logonBgiUrl = "https://tinyurl.com/yxlxbgun"
$logonBgiZip = "C:\BgInfo\LogonBgi.zip"
$bgInfoRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$bgInfoRegkey = "BgInfo"
$bgInfoRegType = "String"
$bgInfoRegkeyValue = "C:\BgInfo\Bginfo.exe C:\BgInfo\logon.bgi /timer:0 /nolicprompt"
$regKeyExists = (Get-Item $bgInfoRegPath -EA Ignore).Property -contains $bgInfoRegkey
$foregroundColor1 = "Red"
$foregroundColor2 = "Yellow"
$writeEmptyLine = "`n"
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Start script execution
Write-Host ($writeEmptyLine + "# BgInfo deployment script started")`
-foregroundcolor $foregroundColor1 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Create BgInfo folder on C: if it not exists, else delete it's content
If (!(Test-Path -Path $bgInfoFolder))
{
New-Item -ItemType $itemType -Force -Path $bgInfoFolder
Write-Host ($writeEmptyLine + "# BgInfo folder created")`
-foregroundcolor $foregroundColor2 $writeEmptyLine
}
Else
{
Write-Host ($writeEmptyLine + "# BgInfo folder already exists")`
-foregroundcolor $foregroundColor2 $writeEmptyLine
Remove-Item $bgInfoFolderContent -Force -Recurse -ErrorAction SilentlyContinue
Write-Host ($writeEmptyLine + "# Content existing BgInfo folder deleted")`
-foregroundcolor $foregroundColor2 $writeEmptyLine
}
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Download, save and extract latest BgInfo software to C:\BgInfo
Import-Module BitsTransfer
Start-BitsTransfer -Source $bgInfoUrl -Destination $bgInfoZip
[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
[System.IO.Compression.ZipFile]::ExtractToDirectory($bgInfoZip, $bgInfoFolder)
Remove-Item $bgInfoZip
Remove-Item $bgInfoEula
Write-Host ($writeEmptyLine + "# bginfo.exe available")`
-foregroundcolor $foregroundColor2 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Download, save and extract logon.bgi file to C:\BgInfo
Invoke-WebRequest -Uri $logonBgiUrl -OutFile $logonBgiZip
[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
[System.IO.Compression.ZipFile]::ExtractToDirectory($logonBgiZip, $bgInfoFolder)
Remove-Item $logonBgiZip
Write-Host ($writeEmptyLine + "# logon.bgi available")`
-foregroundcolor $foregroundColor2 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Create BgInfo Registry Key to AutoStart
If ($regKeyExists -eq $True)
{
Write-Host ($writeEmptyLine + "# BgInfo regkey exists, script wil go on")`
-foregroundcolor $foregroundColor1 $writeEmptyLine
}
Else
{
New-ItemProperty -Path $bgInfoRegPath -Name $bgInfoRegkey -PropertyType $bgInfoRegType -Value $bgInfoRegkeyValue
Write-Host ($writeEmptyLine + "# BgInfo regkey added")`
-foregroundcolor $foregroundColor2 $writeEmptyLine
}
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Run BgInfo
C:\BgInfo\Bginfo.exe C:\BgInfo\logon.bgi /timer:0 /nolicprompt
Write-Host ($writeEmptyLine + "# BgInfo has ran for the first time")`
-foregroundcolor $foregroundColor2 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Exit PowerShell window 3 seconds after completion
Write-Host ($writeEmptyLine + "# Script completed, the PowerShell window will close in 3 seconds")`
-foregroundcolor $foregroundColor1 $writeEmptyLine
Start-Sleep 3
stop-process -Id $PID
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------