Versions Compared

Key

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

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

This will perform the following actions for each PowerShell module:

  • Remove the module from the current session if loaded
  • Update the module if installed and install the module if not
  • Uninstall any previous versions of the module
    Expand
    Info
    Note

    This step should only be completed in the prod (AUSTIN) domain.

    Run the following commands to verify the NuGet provider is installed:

    Code Block
    languagepowershell
    Find-PackageProvider -Name 'NuGet' -Force -ForceBootstrap

    Run the following commands to trust the PSGallery:

    Code Block
    languagepowershell
    Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted

    Run the following commands to define the names of the Graph PowerShell module collection and of any modules that are a dependency for other modules the collection:

    Code Block
    languagepowershell
    ForEach ($ModuleName in $PSModuleName) { 
    $Name$PowerShellModuleName = @{ Name'Microsoft.Graph'
    $DependsOnModuleNames = $ModuleName; ErrorAction = [System.Management.Automation.ActionPreference]::Stop}; 
    $Confirm = @{ Confirm = $false }; 
    'Microsoft.Graph.Authentication'

    Run the following commands to split the Graph PowerShell modules based upon the module dependencies:

    Code Block
    languagepowershell
    $Modules, $Dependencies = (Get-Module -ListAvailable | Where-Object { Name "$PowerShellModuleName.*").Where({$_.Name -innotin $PSModuleName }$DependsOnModuleNames},[System.Management.Automation.WhereOperatorSelectionMode]::Split)

    Run the following commands to unload the Graph PowerShell modules respecting the module dependencies:

    Code Block
    languagepowershell
    $Modules | RemoveForEach-Module @Confirm; 
    Try Object { 
    	UpdateRemove-Module @Name @Confirm
    } 
    Catch { 
    Try { 
    	Install-Module @Name -AcceptLicense @Confirm} Catch { Install-Module @Name @Confirm } 
    }
    
    $Module = Get-InstalledModule @Name; Get-InstalledModule @Name -AllVersions | Where-Name $_.Name -Force -Verbose }; $Dependencies | ForEach-Object { $_.Version -lt $Module.Version } | 
    
    Uninstall-Module @Confirm }
    
    ####
    
    $Modules = Get-Module Microsoft.Graph* -ListAvailable | Where {Remove-Module -Name $_.Name -ne "Microsoft.Graph.Authentication"} | Select-Object Name -Unique
    Foreach ($Module in $Modules)
    {
        $ModuleName = $Module.Name
        $Versions = Get-Module $ModuleName -ListAvailable
        Foreach ($Version in $Versions)
        {
            $ModuleVersion = $Version.Version
            Write-Host "Uninstall-Module $ModuleName $ModuleVersion"
            Uninstall-Module $ModuleName -RequiredVersion $ModuleVersion
        }
    }
    #Uninstall Microsoft.Graph.Authentication
    $ModuleName = "Microsoft.Graph.Authentication"
    $Versions = Get-Module $ModuleName -ListAvailable
    Foreach ($Version in $Versions)
    {
        $ModuleVersion = $Version.Version
        Write-Host "Uninstall-Module $ModuleName $ModuleVersion"
        Uninstall-Module $ModuleName -RequiredVersion $ModuleVersion
    }
    
    Force -Verbose }

    Run the following commands to remove the Graph PowerShell modules currently installed:

    Code Block
    languagepowershell
    Get-ChildItem -Path "$env:ProgramFiles\WindowsPowerShell\Modules" -Filter "$PowerShellModuleName*" | Remove-Item -Force -Recurse -Verbose

    Run the following commands to install the latest version of the Graph PowerShell modules from the PSGallery: 

    Code Block
    languagepowershell
    Save-Module -Path "$env:ProgramFiles\WindowsPowerShell\Modules" -Name $PowerShellModuleName -Force -Verbose