Re: Profilbilder rsp. User Account Pictures
Verfasst: 02.08.2024, 20:22
habe noch ein weiteres Script von ChatGPT gefordert:
funktioniert bei mir aber ebenfalls nicht. Bild (jpg) liegt in 448X448 vor.
funktioniert bei mir aber ebenfalls nicht. Bild (jpg) liegt in 448X448 vor.
Code: Alles auswählen
# Pfad zur neuen Bilddatei
$imagePath = "C:\Pfad\zum\Bild.jpg"
# Stelle sicher, dass das Bild existiert
if (-Not (Test-Path -Path $imagePath)) {
Write-Host "Das Bild wurde nicht gefunden. Bitte überprüfe den Pfad." -ForegroundColor Red
exit
}
# Funktionen und Variablen definieren
function Get-UserSID {
param(
[string]$userName
)
# Query WMI for user SID
$wmi = Get-WmiObject Win32_UserAccount -Filter "Name='$userName'"
return $wmi.SID
}
# Aktuellen Benutzer und dessen SID ermitteln
$currentUsername = $env:USERNAME
$userSid = Get-UserSID -userName $currentUsername
# Erforderliche Verzeichnisse
$publicAccountPicturesPath = "$env:PROGRAMDATA\Microsoft\User Account Pictures"
$userAccountPicturesPath = "$env:APPDATA\Microsoft\Windows\AccountPictures"
# Sicherstellen, dass das Verzeichnis existiert
if (-Not (Test-Path -Path $userAccountPicturesPath)) {
New-Item -ItemType Directory -Path $userAccountPicturesPath -Force | Out-Null
}
# Bild an alle relevanten Stellen kopieren
try {
# Kopiere Bild zu ProgramData-Verzeichnis
Copy-Item -Path $imagePath -Destination "$publicAccountPicturesPath\$userSid.jpg" -Force
# Kopiere Bild zu Benutzer-Verzeichnis
Copy-Item -Path $imagePath -Destination "$userAccountPicturesPath\$userSid.jpg" -Force
Write-Host "Das Benutzerprofilbild wurde erfolgreich geändert." -ForegroundColor Green
} catch {
Write-Host "Es ist ein Fehler beim Ändern des Benutzerprofilbilds aufgetreten: $_" -ForegroundColor Red
}