Install Graph PowerShell module from PSGallery

Install Graph PowerShell module from PSGallery

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

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

Find-PackageProvider -Name 'NuGet' -Force -ForceBootstrap

Run the following commands to trust the PSGallery:

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:

$PowerShellModuleName = 'Microsoft.Graph' $DependsOnModuleNames = 'Microsoft.Graph.Authentication'

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

$Modules, $Dependencies = (Get-Module -Name "$PowerShellModuleName.*").Where({$_.Name -notin $DependsOnModuleNames},[System.Management.Automation.WhereOperatorSelectionMode]::Split)

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

$Modules | ForEach-Object { Remove-Module -Name $_.Name -Force -Verbose }; $Dependencies | ForEach-Object { Remove-Module -Name $_.Name -Force -Verbose }

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

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: 

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