##----------------------------------------------------------------------------------------------------------------------------------------------------
## Author: Wim Matthyssen
## Date: 23/01/19
## File Name: BGInfo_Automated_Windows_Server_2019.ps1
## Usage: BGInfo Automated Windows Server_2019
## Note: Change variables were needed for your preference
## Requires: PowerShell version 5.1
## Version: 1
## Updated: /
##----------------------------------------------------------------------------------------------------------------------------------------------------
#Requires -RunAsAdministrator
## Variables
$writeEmptyLine = "`n"
$writeSeperator = " - "
$global:currenttime = Set-PSBreakpoint -Variable currenttime -Mode Read -Action {$global:currenttime= Get-Date}
$foregroundColor1 = "Red"
$foregroundColor2 = "Yellow"
$bgInfoFolder = "C:\BGInfo"
$itemType = "Directory"
$bgInfoUrl = "https://download.sysinternals.com/files/BGInfo.zip"
$bgInfoZip = "C:\BGInfo\BGInfo.zip"
$bgInfoEula = "C:\BGInfo\Eula.txt"
$logonBgiUrl = "http://scug.be/wim/files/2017/02/LogonBgi.zip"
$logonBgiZip = "C:\BGInfo\LogonBgi.zip"
$bgInfoRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$bgInfoRegKey = "BGInfo"
$bgInfoRegType = "String"
$bgInfoRegKeyValue = "C:\BGInfo\Bginfo64.exe C:\BGInfo\logon.bgi /timer:0 /nolicprompt"
##----------------------------------------------------------------------------------------------------------------------------------------------------
## Write Download started
Write-Host ($writeEmptyLine + "# BGInfo download started" + $writeSeperator + $currenttime)`
-foregroundcolor $foregroundColor1 $writeEmptyLine
##----------------------------------------------------------------------------------------------------------------------------------------------------
## Create BGInfo folder on C: if not exists
If(!(Test-Path -Path $bgInfoFolder))
{
New-Item -ItemType $itemType -Force -Path $bgInfoFolder
Write-Host ($writeEmptyLine + "# BgInfo folder created" + $writeSeperator + $currenttime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
}
Else
{
Write-Host ($writeEmptyLine + "# BGInfo folder already exists" + $writeSeperator + $currenttime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
}
##----------------------------------------------------------------------------------------------------------------------------------------------------
## Download, save and extract latest BGInfo software to C:\BGInfo
Function Get-BginfoZip
{
Import-Module BitsTransfer
Start-BitsTransfer -Source $bgInfoUrl -Destination $bgInfoZip
Expand-Archive -LiteralPath $bgInfoZip -DestinationPath $bgInfoFolder -Force
Remove-Item $bgInfoZip
Remove-Item $bgInfoEula
Write-Host ($writeEmptyLine + "# bginfo.exe available" + $writeSeperator + $currenttime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
}
Get-BginfoZip
##----------------------------------------------------------------------------------------------------------------------------------------------------
## Download, save and extract logon.bgi file to C:\BGInfo
Function Get-LogonBgiZip
{
Invoke-WebRequest -Uri $logonBgiUrl -OutFile $logonBgiZip
Expand-Archive -LiteralPath $logonBgiZip -DestinationPath $bgInfoFolder -Force
Remove-Item $logonBgiZip
Write-Host ($writeEmptyLine + "# logon.bgi available" + $writeSeperator + $currenttime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
}
Get-LogonBgiZip
##----------------------------------------------------------------------------------------------------------------------------------------------------
## Create BGInfo Registry Key to AutoStart
Function Add-BginfoRegKey
{
New-ItemProperty -Path $bgInfoRegPath -Name $bgInfoRegKey -PropertyType $bgInfoRegType -Value $bgInfoRegKeyValue -Force
Write-Host ("# BGInfo regkey added" + $writeSeperator + $currenttime)`
-foregroundcolor $foregroundColor2
}
Add-BginfoRegKey
##----------------------------------------------------------------------------------------------------------------------------------------------------
## Run BGInfo
C:\BGInfo\Bginfo64.exe C:\BgInfo\logon.bgi /timer:0 /nolicprompt
Write-Host ($writeEmptyLine + "# BGInfo has run" + $writeSeperator + $currenttime)`
-foregroundcolor $foregroundColor1 $writeEmptyLine
##----------------------------------------------------------------------------------------------------------------------------------------------------
## Exit PowerShell window 3 seconds after completion
Write-Host ($writeEmptyLine + "# Script completed, the PowerShell window will close in 3 seconds" + $writeSeperator + $currenttime)`
-foregroundcolor $foregroundColor1 $writeEmptyLine
Start-Sleep 3
Stop-Process -Id $PID
##----------------------------------------------------------------------------------------------------------------------------------------------------
Nenhum comentário:
Postar um comentário
Observação: somente um membro deste blog pode postar um comentário.