Passwort auf „läuft nie ab“ setzen mit Microsoft Graph PowerShell
Set a password to „never expire“ with Microsoft Graph PowerShell
Ein One-Pager für Connect-MgGraph und Update-MgUser: Module sauber installieren, verbinden und die Passwortrichtlinie eines Users dauerhaft auf „läuft nie ab“ setzen.
A one-pager for Connect-MgGraph and Update-MgUser: install the modules cleanly, connect, and permanently set a user’s password policy to „never expires“.
Ziel
Goal
Passwortablauf für einen einzelnen User dauerhaft deaktivieren.
Permanently disable password expiration for a single user.
Ablauf
Flow
Module installieren, verbinden, Attribut setzen, Ergebnis prüfen.
Install modules, connect, set the attribute, verify the result.
Output
Output
PasswordPolicies = DisablePasswordExpiration am User-Objekt.
PasswordPolicies = DisablePasswordExpiration on the user object.
Warum diese Anleitung?
Why this guide?
Das Microsoft Graph PowerShell SDK ersetzt die älteren MSOnline- und AzureAD-Module. Für eine einzelne, wiederkehrende Aufgabe wie das Deaktivieren des Passwortablaufs lohnt sich eine schlanke, lokal installierte Modul-Umgebung statt eines vollen Admin-Toolings – vor allem, wenn OneDrive-Sync bei der Modul-Installation sonst Probleme macht.
The Microsoft Graph PowerShell SDK replaces the older MSOnline and AzureAD modules. For a single, recurring task like disabling password expiration, a lean, locally installed module setup is worthwhile instead of full admin tooling — especially since OneDrive sync can otherwise cause problems during module installation.
Warum sollten wir es so machen?
Why should we do it this way?
Weder das Microsoft 365 Admin Center noch das Entra ID Portal bieten einen Schalter, um den Passwortablauf für einen einzelnen User zu deaktivieren. Die Passwortablauf-Richtlinie in der GUI wirkt immer tenant-weit – sie gilt für alle User gleichzeitig oder gar nicht. Das ist in den meisten Fällen nicht gewünscht, etwa wenn nur ein Service-Account oder ein einzelner Mitarbeiter ein nie ablaufendes Passwort benötigen soll.
Neither the Microsoft 365 Admin Center nor the Entra ID portal offer a toggle to disable password expiration for a single user. The password expiration policy in the GUI always applies tenant-wide — it’s either on for every user or off for every user. In most cases that’s not what you want, for example when only a service account or a single employee needs a password that never expires.
Das Attribut PasswordPolicies auf dem einzelnen User-Objekt lässt sich ausschließlich über die Microsoft Graph API bzw. das entsprechende PowerShell-Modul setzen – Update-MgUser ist aktuell der einzige unterstützte Weg, das gezielt für genau einen User zu tun, ohne die Richtlinie für den gesamten Tenant zu ändern.
The PasswordPolicies attribute on an individual user object can only be set via the Microsoft Graph API or its corresponding PowerShell module — Update-MgUser is currently the only supported way to do this for exactly one user, without changing the policy for the entire tenant.
Ein häufiger Anwendungsfall ist der Service-Account, mit dem ein On-premises Data Gateway (z. B. für Power BI) betrieben wird. Läuft das Passwort dieses Accounts turnusmäßig ab, meldet sich das Gateway irgendwann nicht mehr an – geplante Datenaktualisierungen brechen ab, oft ohne dass es sofort auffällt. Für genau solche Service-Accounts ist ein dauerhaft nicht ablaufendes Passwort sinnvoll, und diese Anleitung setzt es gezielt nur für diesen einen Account, statt die Richtlinie für den ganzen Tenant zu lockern.
A common use case is the service account that runs an On-premises Data Gateway (e.g. for Power BI). If that account’s password expires on schedule, the gateway eventually stops authenticating — scheduled data refreshes fail, often without anyone noticing right away. For exactly this kind of service account, a permanently non-expiring password makes sense, and this guide sets it just for that one account instead of relaxing the policy for the whole tenant.
Schritt-für-Schritt
Step by step
Ein normales PowerShell-Fenster genügt – Administratorrechte sind nicht zwingend erforderlich.
A regular PowerShell window is enough — administrator rights are not strictly required.
Nur nötig, falls bereits Module installiert sind, die Probleme machen.
Only needed if modules are already installed and causing problems.
Get-Module -ListAvailable Microsoft.Graph.Authentication Uninstall-Module Microsoft.Graph.Authentication -AllVersions -Force Uninstall-Module Microsoft.Graph.Users -AllVersions -Force
Falls der Uninstall selbst fehlschlägt (z. B. wegen OneDrive-Sync), Modul-Ordner manuell löschen, z. B. mit Remove-Item "<OneDrive-Pfad>\Documents\WindowsPowerShell\Modules\Microsoft.Graph.Authentication" -Recurse -Force (Pfad entsprechend anpassen).
If the uninstall itself fails (e.g. because of OneDrive sync), delete the module folder manually, e.g. with Remove-Item "<OneDrive path>\Documents\WindowsPowerShell\Modules\Microsoft.Graph.Authentication" -Recurse -Force (adjust the path accordingly).
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Sicherheitsabfrage mit „J“ (Ja) bestätigen. Nur einmalig pro Benutzerprofil/Rechner nötig – Kontrolle: Get-ExecutionPolicy -Scope CurrentUser sollte „RemoteSigned“ zeigen.
Confirm the security prompt with „Y“ (Yes). Only needed once per user profile/machine — check with Get-ExecutionPolicy -Scope CurrentUser, which should show „RemoteSigned“.
$localPath = "C:\PSModules"
New-Item -Path $localPath -ItemType Directory -Force
[Environment]::SetEnvironmentVariable("PSModulePath", "$localPath;" + [Environment]::GetEnvironmentVariable("PSModulePath", "User"), "User")
$env:PSModulePath = "$localPath;" + $env:PSModulePath
Save-Module Microsoft.Graph.Authentication -Path C:\PSModules -Repository PSGallery Save-Module Microsoft.Graph.Users -Path C:\PSModules -Repository PSGallery
Kontrolle: Get-ChildItem C:\PSModules → beide Modul-Ordner sollten erscheinen.
Check with Get-ChildItem C:\PSModules → both module folders should appear.
Fenster komplett schließen und neu öffnen, damit der neue PSModulePath aktiv ist.
Close the window completely and reopen it so the new PSModulePath becomes active.
Connect-MgGraph -Scopes "User.ReadWrite.All" -UseDeviceCode
Link im Browser öffnen, Code eingeben, anmelden und bestätigen. Falls zwei Codes erscheinen: beide bestätigen. Erfolg = „Welcome to Microsoft Graph!“
Open the link in the browser, enter the code, sign in and confirm. If two codes appear, confirm both. Success = „Welcome to Microsoft Graph!“
Update-MgUser -UserId "user@domain.de" -PasswordPolicies "DisablePasswordExpiration"
E-Mail-Adresse durch den tatsächlichen UPN des Users ersetzen.
Replace the email address with the user’s actual UPN.
Get-MgUser -UserId "user@domain.de" -Property PasswordPolicies | Select-Object PasswordPolicies
Erwartetes Ergebnis: PasswordPolicies = DisablePasswordExpiration
Expected result: PasswordPolicies = DisablePasswordExpiration
Troubleshooting
Troubleshooting
| Problem | Lösung |
|---|---|
| „Connect-MgGraph nicht erkannt“ nach Neustart | Import-Module C:\PSModules\Microsoft.Graph.Authentication und Import-Module C:\PSModules\Microsoft.Graph.Users manuell ausführen, dann Schritt 5 wiederholen. |
| „Insufficient privileges“ beim Update | Eigener Account braucht Admin-Rolle (z. B. User Administrator) im Tenant – bei IT/Admin anfragen. |
| FileNotFoundException / AggregateException | Module liegen evtl. in OneDrive und sind nicht vollständig synchronisiert – Umzug nach C:\PSModules (Schritt 2–3) löst das dauerhaft. |
| Problem | Solution |
|---|---|
| „Connect-MgGraph not recognized“ after restart | Run Import-Module C:\PSModules\Microsoft.Graph.Authentication and Import-Module C:\PSModules\Microsoft.Graph.Users manually, then repeat step 5. |
| „Insufficient privileges“ during the update | Your own account needs an admin role (e.g. User Administrator) in the tenant — ask your IT/admin. |
| FileNotFoundException / AggregateException | Modules may be located in OneDrive and not fully synced — moving to C:\PSModules (steps 2–3) permanently resolves this. |
Kurzreferenz für weitere User
Quick reference for further users
Nach der Ersteinrichtung reichen diese zwei Befehle für jeden weiteren User.
After the initial setup, these two commands are enough for every additional user.
Connect-MgGraph -Scopes "User.ReadWrite.All" -UseDeviceCode Update-MgUser -UserId "user@domain.de" -PasswordPolicies "DisablePasswordExpiration"
Schritte 1–4 (Execution Policy, Modul-Pfad, Installation) sind einmalig pro Rechner.
Steps 1–4 (execution policy, module path, installation) are one-time per machine.
Fazit
Summary
Mit einer sauberen, lokalen Modul-Umgebung und Connect-MgGraph lässt sich der Passwortablauf einzelner User schnell und zuverlässig deaktivieren – ganz ohne die Stolpersteine, die OneDrive-synchronisierte Modul-Ordner sonst verursachen.
With a clean, local module setup and Connect-MgGraph, disabling password expiration for individual users is fast and reliable — without the pitfalls that OneDrive-synced module folders otherwise cause.