Snippets Collections
# Ms Graph Functions

# Connect to MG Graph with Read-only permissions.
function Connect-ToMSGraph-ReadOnlyPerms {
    Connect-MgGraph "User.Read.All", "DeviceManagementRBAC.Read.All", "DeviceManagementServiceConfig.Read.All", "DeviceManagementConfiguration.Read.All", "DeviceManagementManagedDevices.Read.All"

# Grab basic user information to work with.
function Get-BasicUserinfo {
    Get-MGUser -All -Property Id, DisplayName, UserPrincipalName, AssignedLicenses | Select Id, DisplayName, UserPrincipalName, AssignedLicenses

# Grab a password report of all users.
Function Get-UserPWreport {
    Get-MgUser -All -Property UserPrincipalName, DisplayName, Id, LastPasswordChangeDateTime,PasswordPolicies | Select-Object UserPrincipalName, DisplayName, LastPasswordChangeDateTime,PasswordPolicies, @{l='PasswordAgeDays';e={ (New-TimeSpan -Start $_.LastPasswordChangeDateTime -End (get-date) ).TotalDays -as [int] }} | Sort-Object PasswordAgeDays 

# Grab all avaialble properties for a specific user.
function Get-SpecifcUserFullInfo {
        HelpMessage="Enter the user ID of the user you want to collect information on.")]
    Get-MGUser -UserId $UserID | Format-List

Fri Apr 14 2023 21:31:04 GMT+0000 (Coordinated Universal Time)

#powershell #mggrapg #devicemanagement

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension