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



Replace \\YourServer\SharedFolder with the UNC path to your shared folder, C:\LocalFolder with the path to the local folder where you want the files to be copied, and adjust $scheduledTime to the time you want BGInfo to update.

This script will:

Copy the updated files from the shared location to the local machine.
Schedule the BGInfo to run at the specified time every day without any user input.
To deploy this script:

Save the script as a .ps1 file.
Create a GPO that runs the script at startup or logon.
Link the GPO to the appropriate OU in your Active Directory.
Please ensure that the script is tested in a non-production environment before deployment to avoid any potential issues. Also, make sure that the necessary permissions are set for the script to access the shared location and write to the local directory. Remember to run the script with administrative privileges1234.

Learn more

1

zapier.com
2

medium.com
3

stackoverflow.com
4

latenode.com

Comments

Popular posts from this blog

Clearing DNS cache on vCenter Server Appliance

Repairing a virtual disk in Workstation (2019259)