PowerShell script to automate BGInfo update without user input
# PowerShell script to automate BGInfo update without user input
# Variables
$sourcePath = "\\YourServer\SharedFolder"
$destinationPath = "C:\LocalFolder"
$bgInfoExecutable = "Bginfo.exe"
$configFile = "config.bgi"
$scheduledTime = "06:00" # Set your desired time in HH:mm format
# Function to copy files if they are updated
function Update-Files {
$sourceFiles = Get-ChildItem -Path $sourcePath
foreach ($file in $sourceFiles) {
$localFile = Join-Path -Path $destinationPath -ChildPath $file.Name
if (Test-Path $localFile) {
$localFileInfo = Get-Item $localFile
if ($localFileInfo.LastWriteTime -lt $file.LastWriteTime) {
Copy-Item -Path $file.FullName -Destination $localFile -Force
}
} else {
Copy-Item -Path $file.FullName -Destination $localFile
}
}
}
# Function to schedule BGInfo update
function Schedule-BGInfoUpdate {
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -WindowStyle Hidden -command `"$destinationPath\$bgInfoExecutable $destinationPath\$configFile /silent /nolicprompt /timer:0`""
$trigger = New-ScheduledTaskTrigger -At $scheduledTime -Daily
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "BGInfoUpdate" -Description "Updates BGInfo daily at $scheduledTime" -RunLevel Highest -User "SYSTEM"
}
# Check and copy files
Update-Files
# Schedule BGInfo update
Schedule-BGInfoUpdate
Comments