Fabric • Data gateway • Service User

Microsoft Graph PowerShell · Entra ID Admin

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“.

Connect-MgGraph Update-MgUser PowerShell

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.

PS C:\> Connect-MgGraph -Scopes „User.ReadWrite.All“ -UseDeviceCode
Welcome to Microsoft Graph!

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.

Typisches Praxisbeispiel: On-premises Data Gateway Typical real-world example: On-premises Data Gateway

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.

0
Vorhandene/beschädigte Module prüfen und bereinigen Check and clean up existing/broken modules

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).

1
Execution Policy freigeben Allow the execution policy
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“.

2
Lokalen Modul-Ordner anlegen (NICHT in OneDrive!) Create a local module folder (NOT in OneDrive!)
$localPath = "C:\PSModules"
New-Item -Path $localPath -ItemType Directory -Force

[Environment]::SetEnvironmentVariable("PSModulePath", "$localPath;" + [Environment]::GetEnvironmentVariable("PSModulePath", "User"), "User")

$env:PSModulePath = "$localPath;" + $env:PSModulePath
3
Benötigte Module installieren Install the required modules
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.

4
PowerShell neu starten Restart PowerShell

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.

5
Mit Microsoft Graph verbinden (mit Schreibrechten) Connect to Microsoft Graph (with write permissions)
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!“

6
Passwort auf „läuft nie ab“ setzen Set the password to „never expires“
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.

7
Kontrolle – hat es geklappt? Check — did it work?
Get-MgUser -UserId "user@domain.de" -Property PasswordPolicies | Select-Object PasswordPolicies

Erwartetes Ergebnis: PasswordPolicies = DisablePasswordExpiration

Expected result: PasswordPolicies = DisablePasswordExpiration

PS C:\> Get-MgUser -UserId „user@domain.de“ -Property PasswordPolicies | Select-Object PasswordPolicies
 
PasswordPolicies
—————–
DisablePasswordExpiration

Troubleshooting

Troubleshooting

ProblemLösung
„Connect-MgGraph nicht erkannt“ nach NeustartImport-Module C:\PSModules\Microsoft.Graph.Authentication und Import-Module C:\PSModules\Microsoft.Graph.Users manuell ausführen, dann Schritt 5 wiederholen.
„Insufficient privileges“ beim UpdateEigener Account braucht Admin-Rolle (z. B. User Administrator) im Tenant – bei IT/Admin anfragen.
FileNotFoundException / AggregateExceptionModule liegen evtl. in OneDrive und sind nicht vollständig synchronisiert – Umzug nach C:\PSModules (Schritt 2–3) löst das dauerhaft.
ProblemSolution
„Connect-MgGraph not recognized“ after restartRun Import-Module C:\PSModules\Microsoft.Graph.Authentication and Import-Module C:\PSModules\Microsoft.Graph.Users manually, then repeat step 5.
„Insufficient privileges“ during the updateYour own account needs an admin role (e.g. User Administrator) in the tenant — ask your IT/admin.
FileNotFoundException / AggregateExceptionModules 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.

Quellen

Sources

Fragen zu Microsoft Graph PowerShell oder Entra ID Admin-Skripten? Questions about Microsoft Graph PowerShell or Entra ID admin scripts?

Wir helfen bei Automatisierung, Modul-Setup und Governance-Skripten.

We help with automation, module setup and governance scripts.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert