Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Run the code blocks in one of the following sections to update or install the latest version of the Microsoft Graph PowerShell modules from the PSGallery: 

  • Update modules:

    Expand


    Info

    This will perform the following actions for each PowerShell module:

    • Remove the modules from the current session if loaded
    • Update the module if installed and install the module if not

    Unload Graph PowerShell modules respecting dependency on Microsoft.Graph.Authentication 

    Code Block
    languagepowershell
    # get loaded Graph modules
    $MgAuthn, $MgGraph = (Get-Module -Name Microsoft.Graph*).Where({$_.Name -eq 'Microsoft.Graph.Authentication'},[System.Management.Automation.WhereOperatorSelectionMode]::Split)
    # unload Graph modules with Authn last
    $MgGraph | ForEach-Object { Remove-Module -Name $_.Name -Force }; $MgAuthn | ForEach-Object { Remove-Module -Name $_.Name -Force }
    

    Update Graph PowerShell modules

    Code Block
    languagepowershell
    Update-Module -Name Microsoft.Graph
    



  • Reinstall modules 

    Expand


    Info

    This will perform the following actions for each PowerShell module:

    • Remove the modules from the current session if loaded
    • Remove the module files from the AllUsers scope
    • Install the modules from the PowerShell gallery

    Unload Graph PowerShell modules respecting dependency on Microsoft.Graph.Authentication 

    Code Block
    languagepowershell
    # get loaded Graph modules
    $MgAuthn, $MgGraph = (Get-Module -Name 'Microsoft.Graph*').Where({$_.Name -eq 'Microsoft.Graph.Authentication'},[System.Management.Automation.WhereOperatorSelectionMode]::Split)
    # unload Graph modules with Authn last
    $MgGraph | ForEach-Object { Remove-Module -Name $_.Name -Force }; $MgAuthn | ForEach-Object { Remove-Module -Name $_.Name -Force }
    

    Remove Graph PowerShell modules 

    Code Block
    languagepowershell
    Get-ChildItem -Path "$env:ProgramFiles\WindowsPowerShell\Modules" -Filter 'Microsoft.Graph*' | Remove-Item -Recurse -Force

    Install Graph PowerShell modules

    Code Block
    languagepowershell
    Save-Module -Path "$env:ProgramFiles\WindowsPowerShell\Modules" -Name Microsoft.Graph -Force



...