Systemmanagement optimieren BGInfo PowerShell-Bereitstellungsskript

Die wichtigsten Erkenntnisse

  • Automatisierte BGInfo-Bereitstellung: Das Skript bietet eine nahtlose, automatisierte Methode zur Bereitstellung von BGInfo auf mehreren Windows-Systemen.
  • Effizienz für IT-Fachleute: Spart Zeit und reduziert den manuellen Aufwand für IT-Experten und MSPs bei der Verwaltung von Systeminformationsanzeigen.
  • Anpassbare Konfiguration: Ermöglicht die Anpassung an unterschiedliche Umgebungen und Anforderungen durch einen konfigurierbaren Parameter.
  • Administrative Berechtigungen erforderlich: Das Skript muss mit Administratorrechten ausgeführt werden, um auf Systemverzeichnisse zugreifen und Einstellungen ändern zu können.
  • Fehlerbehandlung und Robustheit: Umfassende Fehlerbehandlung, die Zuverlässigkeit und klare Kommunikation während der Ausführung gewährleistet.
  • Sicherheitsbewusstsein: Es ist wichtig, sich der von BGInfo angezeigten Informationen bewusst zu sein, um die Preisgabe sensibler Daten zu vermeiden.
  • Skalierbarkeit und Konsistenz: Sorgt für eine einheitliche Anzeige der Systeminformationen auf allen Rechnern in einem Unternehmen.
  • Kompatibilität mit modernen Windows-Systemen: Unterstützt in erster Linie Windows 10 und Windows Server 2016 aufwärts.
  • Ergänzend zu umfassenden IT-Tools: Funktioniert gut in Verbindung mit umfassenderen IT-Verwaltungsplattformen wie NinjaOne für mehr Transparenz und Kontrolle.

In der sich ständig weiterentwickelnden Landschaft der Informationstechnologie sind die effiziente Verwaltung und Konfiguration von IT-Systemen von entscheidender Bedeutung. BGInfo, ein bekanntes Tool in der Windows-Umgebung, spielt in dieser Hinsicht eine wichtige Rolle. Dieses Tool zeigt wichtige Systeminformationen im Hintergrund des Desktops an und erweist sich damit als unschätzbar wertvoll für IT-Expert:innen und Managed Service Provider (MSPs). Heute stellen wir ein PowerShell-Skript vor, das für die nahtlose Installation und Konfiguration von BGInfo auf Windows-Systemen entwickelt wurde.

Hintergrund

BGInfo, Teil der Sysinternals Suite, ist seit Jahren ein fester Bestandteil in den Werkzeugkisten von IT-Experten. Es zeigt Systeminformationen wie IP-Adresse, Computername und Betriebssystemversion auf dem Desktop an und bietet einen schnellen Einblick in die Systemkonfiguration. In einer Welt, in der schneller Informationszugriff und Systemüberwachung von entscheidender Bedeutung sind, ist die Automatisierung der Bereitstellung von BGInfo mithilfe eines PowerShell-Skripts sowohl eine Zeitersparnis als auch eine Effizienzsteigerung, insbesondere für IT-Experten und MSPs, die mehrere Computer verwalten.

Das Skript:

#Requires -Version 2.0

<#
.SYNOPSIS
    Downloads, installs and sets up BGInfo to run for all users.
.DESCRIPTION
    Downloads, installs and sets up BGInfo to run for all users.
    Uses the default configuration if no .bgi file path or URL is specified.

    Note: Users that are already logged in will need to logout and login to have BGInfo update their desktop background.

.EXAMPLE
    (No Parameters)
    ## EXAMPLE OUTPUT WITHOUT PARAMS ##
    Create Directory: C:\WINDOWS\System32\SysInternals
    Downloading https://live.sysinternals.com/Bginfo.exe
    Created Shortcut: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\BGInfo.lnk

.EXAMPLE
    -Config C:\BGInfo\config.bgi
    Specifies the BGInfo configuration file to use.

PARAMETER: -Config C:\BGInfo\config.bgi
    ## EXAMPLE OUTPUT WITHOUT PARAMS ##
    Create Directory: C:\WINDOWS\System32\SysInternals
    Downloading https://live.sysinternals.com/Bginfo.exe
    Created Shortcut: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\BGInfo.lnk
.OUTPUTS
    None
.NOTES
    Minimum OS Architecture Supported: Windows 10, Windows Server 2016
    Release Notes: Renamed script and added Script Variable support
By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
    Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#>

[CmdletBinding()]
param (
    [Parameter()]
    [string]$Config
)

begin {
    if ($env:bginfoConfigFilePath -and $env:bginfoConfigFilePath -notlike "null") { $Config = $env:bginfoConfigFilePath }
    function Test-IsElevated {
        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $p = New-Object System.Security.Principal.WindowsPrincipal($id)
        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
    }

    function New-Shortcut {
        [CmdletBinding()]
        param(
            [Parameter()]
            [String]$Arguments,
            [Parameter()]
            [String]$IconPath,
            [Parameter(ValueFromPipeline = $True)]
            [String]$Path,
            [Parameter()]
            [String]$Target,
            [Parameter()]
            [String]$WorkingDir
        )
        process {
            Write-Host "Creating Shortcut at $Path"
            $ShellObject = New-Object -ComObject ("WScript.Shell")
            $Shortcut = $ShellObject.CreateShortcut($Path)
            $Shortcut.TargetPath = $Target
            if ($WorkingDir) { $Shortcut.WorkingDirectory = $WorkingDir }
            if ($Arguments) { $ShortCut.Arguments = $Arguments }
            if ($IconPath) { $Shortcut.IconLocation = $IconPath }
            $Shortcut.Save()

            if (!(Test-Path $Path -ErrorAction SilentlyContinue)) {
                Write-Error "Unable to create Shortcut at $Path"
                exit 1
            }
        }
    }
    # Utility function for downloading files.
    function Invoke-Download {
        param(
            [Parameter()]
            [String]$URL,
            [Parameter()]
            [String]$Path,
            [Parameter()]
            [int]$Attempts = 3,
            [Parameter()]
            [Switch]$SkipSleep
        )
        Write-Host "URL given, Downloading the file..."

        $SupportedTLSversions = [enum]::GetValues('Net.SecurityProtocolType')
        if ( ($SupportedTLSversions -contains 'Tls13') -and ($SupportedTLSversions -contains 'Tls12') ) {
            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol::Tls13 -bor [System.Net.SecurityProtocolType]::Tls12
        }
        elseif ( $SupportedTLSversions -contains 'Tls12' ) {
            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
        }
        else {
            # Not everything requires TLS 1.2, but we'll try anyway.
            Write-Warning "TLS 1.2 and or TLS 1.3 are not supported on this system. This download may fail!"
            if ($PSVersionTable.PSVersion.Major -lt 3) {
                Write-Warning "PowerShell 2 / .NET 2.0 doesn't support TLS 1.2."
            }
        }

        $i = 1
        While ($i -le $Attempts) {
            # Some cloud services have rate-limiting
            if (-not ($SkipSleep)) {
                $SleepTime = Get-Random -Minimum 3 -Maximum 15
                Write-Host "Waiting for $SleepTime seconds."
                Start-Sleep -Seconds $SleepTime
            }
        
            if ($i -ne 1) { Write-Host "" }
            Write-Host "Download Attempt $i"

            try {
                # Invoke-WebRequest is preferred because it supports links that redirect, e.g., https://t.ly
                if ($PSVersionTable.PSVersion.Major -lt 4) {
                    # Downloads the file
                    $WebClient = New-Object System.Net.WebClient
                    $WebClient.DownloadFile($URL, $Path)
                }
                else {
                    # Standard options
                    $WebRequestArgs = @{
                        Uri                = $URL
                        OutFile            = $Path
                        MaximumRedirection = 10
                        UseBasicParsing    = $true
                    }

                    # Downloads the file
                    Invoke-WebRequest @WebRequestArgs
                }

                $File = Test-Path -Path $Path -ErrorAction SilentlyContinue
            }
            catch {
                Write-Warning "An error has occurred while downloading!"
                Write-Warning $_.Exception.Message

                if (Test-Path -Path $Path -ErrorAction SilentlyContinue) {
                    Remove-Item $Path -Force -Confirm:$false -ErrorAction SilentlyContinue
                }

                $File = $False
            }

            if ($File) {
                $i = $Attempts
            }
            else {
                Write-Warning "File failed to download."
                Write-Host ""
            }

            $i++
        }

        if (-not (Test-Path $Path)) {
            throw "Failed to download file!"
        }
        else {
            Write-Host "Download Successful!"
        }
    }

    function Install-SysInternalsTool {
        [CmdletBinding()]
        param()
        # Target directory is %WinDir%C:\Windows\System32\SysInternals
        $TargetDir = Join-Path -Path $env:WinDir -ChildPath "System32\SysInternals"

        # Tools to be downloaded
        $Tools = @(
            [PSCustomObject]@{
                Name     = "Bginfo"
                FileName = "Bginfo.exe"
                URL      = "https://live.sysinternals.com/Bginfo.exe"
            }
        )

        # Create Directory
        if (-not $(Test-Path $TargetDir -ErrorAction SilentlyContinue)) {
            Write-Host "Create Directory: $TargetDir"
            New-Item -ItemType Directory -Path $TargetDir -Force -ErrorAction SilentlyContinue
        }

        # Download tools to target directory
        try {
            foreach ($Tool in $Tools) {
                $FilePath = Join-Path $TargetDir $Tool.FileName
                Write-Host "Downloading $($Tool.Name) to $FilePath"
                Invoke-Download -URL $Tool.URL -Path $FilePath
            }
        }
        catch {
            throw $_
        }
    }
    function Register-BGInfoStartup {
        [CmdletBinding()]
        param(
            [Parameter()][string]$Config
        )
        $ExePath = Join-Path -Path $env:WinDir -ChildPath "System32\SysInternals\BGInfo.exe"
        if (-not $(Test-Path -Path $ExePath -ErrorAction SilentlyContinue)) {
            throw "BGInfo.exe is not found at $ExePath"
        }

        # Register Startup command for All User
        try {
            $StartupPath = Join-Path -Path $env:ProgramData -ChildPath "Microsoft\Windows\Start Menu\Programs\StartUp\StartupBGInfo.lnk"
            
            if ($(Test-Path -Path $StartupPath -ErrorAction SilentlyContinue)) {
                Remove-Item -Path $StartupPath -ErrorAction SilentlyContinue
            }
            if ($Config -and $(Test-Path -Path $Config -ErrorAction SilentlyContinue)) {
                New-Shortcut -Path $StartupPath -Arguments "/iq `"$Config`" /accepteula /timer:0 /silent" -Target $ExePath
            }
            else {
                New-Shortcut -Path $StartupPath -Arguments "/accepteula /timer:0 /silent" -Target $ExePath
            }

            Write-Host "Created Startup: $StartupPath"
        }
        catch {
            throw "Unable to create shortcut for BGInfo.exe"
        }
    }
}
process {
    if (-not (Test-IsElevated)) {
        Write-Error -Message "Access Denied. Please run with Administrator privileges."
        exit 1
    }

    try {
        Install-SysInternalsTool

        if ($Config) {
            if (-not $(Test-Path -Path $Config -ErrorAction SilentlyContinue)) {
                try {
                    if (-not (Test-Path -Path "$Env:PROGRAMDATA\SysInternals" -ErrorAction SilentlyContinue)) {
                        New-Item -ItemType Directory -Path "$Env:PROGRAMDATA\SysInternals" -Force
                    }
                    Invoke-Download -URL $Config -Path $(Join-Path -Path $env:PROGRAMDATA -ChildPath "SysInternals\bginfoConfig.bgi")
                    $Config = $(Join-Path -Path $env:PROGRAMDATA -ChildPath "SysInternals\bginfoConfig.bgi")
                }
                catch {
                    Write-Error "Failed to download from provided Url or that the Path to the specified file does not exist."
                    Write-Error $_
                    exit 1
                }
            }
            Register-BGInfoStartup -Config $Config
        }
        else {
            Register-BGInfoStartup
        }
    }
    catch {
        Write-Error $_
        exit 1
    }

    Write-Host "Successfully installed and set up bginfo. Bginfo will start the next time the end user logs in or restarts."
    exit 0
}
end {
    
    
    
}

 

Zugriff auf über 300 Skripte im NinjaOne Dojo

Zugang erhalten

Detaillierte Aufschlüsselung

Das Skript arbeitet in mehreren Stufen:

  • Konfiguration der Parameter: Es beginnt damit, dass die Benutzer:innen über den Parameter $Config eine Konfigurationsdatei angeben kann. Wenn kein spezifischer Pfad für die Konfigurationsdatei angegeben wird, wird standardmäßig eine Standardkonfiguration verwendet.
  • Berechtigungsprüfung: Das Skript überprüft, ob es mit Administratorrechten ausgeführt wird, was entscheidend ist, um auf Systemverzeichnisse zuzugreifen und Starteinstellungen zu ändern.
  • Herunterladen und Installieren von BGInfo: Das Skript erstellt ein Verzeichnis unter C:\WINDOWS\System32\SysInternals und lädt BGInfo von der offiziellen Sysinternals-Live-Site herunter. Es behandelt mögliche Probleme beim Herunterladen, wie TLS-Inkompatibilität und Wiederholungslogik.
  • Einrichtender Startverknüpfung: Das Skript erstellt eine Verknüpfung im gemeinsamen Startordner. Dadurch wird sichergestellt, dass BGInfo bei der Anmeldung für alle Benutzer:innen ausgeführt wird. Es kann eine bestimmte Konfigurationsdatei oder Standardeinstellungen verwenden.
  • Fehlerbehandlung: Das gesamte Skript enthält eine robuste Fehlerbehandlung, die sicherstellt, dass alle Probleme der Benutzer:innen klar mitgeteilt werden.

Mögliche Anwendungsfälle

Stellen Sie sich ein Szenario vor, in dem ein MSP BGInfo für eine Flotte von Windows-Rechnern in einer Unternehmensumgebung bereitstellen muss. Dieses Skript automatisiert den Prozess, reduziert manuelle Eingriffe und gewährleistet eine einheitliche BGInfo-Konfiguration für alle Systeme.

Vergleiche

Traditionell würde die Bereitstellung von BGInfo eine manuelle Installation und Konfiguration auf jedem Rechner erfordern. Dieses Skript spart nicht nur Zeit, sondern verringert auch die Wahrscheinlichkeit von menschlichen Fehlern. Im Vergleich zur manuellen Bereitstellung ist dies ein skalierbarer und zuverlässiger Ansatz.

FAQs

  • Kann dieses Skript für verschiedene Konfigurationen angepasst werden?
    Ja, indem Sie den Parameter $Config ändern.
  • Funktioniert dieses Skript auf allen Windows-Versionen?
    Es unterstützt Windows 10, Windows Server 2016 und aufwärts.

Auswirkungen

Obwohl das Skript die Bereitstellung vereinfacht, ist es wichtig, sich über die Auswirkungen auf die Sicherheit im Klaren zu sein. Es muss sichergestellt werden, dass die BGInfo-Konfiguration nicht versehentlich sensible Informationen auf dem Desktop-Hintergrund preisgibt.

Empfehlungen

  • Testen Sie das Skript immer in einer kontrollierten Umgebung, bevor Sie es in großem Umfang einsetzen.
  • Aktualisieren Sie das Skript regelmäßig, um es an neue Windows-Updates und Sysinternals-Versionen anzupassen.
  • Seien Sie vorsichtig mit den von BGInfo angezeigten Informationen und berücksichtigen Sie dabei den Sicherheitskontext Ihrer Umgebung.

Abschließende Überlegungen

Im Rahmen der Systemverwaltung und -überwachung können Tools wie NinjaOne solche Skripte ergänzen, indem sie eineumfassende Plattform für das IT-Managementbieten. NinjaOne bietet eine Reihe von Funktionen, die mit den Erkenntnissen von BGInfo zusammenwirken und die Transparenz und Kontrolle der IT-Infrastruktur insgesamt verbessern.

Nächste Schritte

Der Aufbau eines effizienten und effektiven IT-Teams erfordert eine zentralisierte Lösung, die als vereintes Tool für die Bereitstellung von Dienstleistungen fungiert. NinjaOne ermöglicht es IT-Teams, all ihre Geräte zu überwachen, verwalten, sichern und zu unterstützen, unabhängig von ihrem Ort und komplexer Infrastruktur vor Ort.

Erfahren Sie mehr über NinjaOne Endpoint Management schauen Sie sich eine Live-Tour an oder starten Sie Ihre kostenlose Testversion der NinjaOne Plattform.

Kategorien:

Das könnte Sie auch interessieren

Demo ansehen×
×

Sehen Sie NinjaOne in Aktion!

Mit dem Absenden dieses Formulars akzeptiere ich die Datenschutzerklärung von NinjaOne.

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
  • Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
  • Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
  • Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).