MG Graph Functions


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

Saved by @Bass2Jamm #powershell #mggrapg #devicemanagement

# 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