#Required running with elevated right. if (-not([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Warning "You need to have Administrator rights to run this script!`nPlease re-run this script as an Administrator in an elevated powershell prompt!" break } Write-host "`nPreparing the system to running the script..." #Configure Execution Policy if ((Get-ExecutionPolicy) -notmatch "RemoteSigned") { Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force } #Update the NuGet Provider if needed. $nuGetPath = "C:\Program Files\PackageManagement\ProviderAssemblies\nuget\*\Microsoft.PackageManagement.NuGetProvider.dll" $testPath = Test-Path -Path $nuGetPath if ($testPath -match 'false') { Write-Host "`nInstalling NuGet Provider..." Install-PackageProvider -Name NuGet -Force | Out-Null } #Update the PowerShellGet if needed. $PSGetCurrentVersion = (Get-PackageProvider -Name 'PowerShellGet').Version $PSGetLatestVersion = (Find-Module PowerShellGet).Version if ($PSGetCurrentVersion -lt $PSGetLatestVersion) { Write-Host "`nUpdating PowerShellGet Module from $PSGetCurrentVersion to $PSGetLatestVersion..." Install-Module -Name 'PowerShellGet' -Force } #We're installing from the PowerShell Gallery so make sure that it's trusted. $InstallationPolicy = (Get-PSRepository -Name PSGallery).InstallationPolicy if ($InstallationPolicy -match "Untrusted") { Write-host "`nConfiguring the PowerShell Gallery Repository..." Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted } $graphCurrentVersion = (Get-InstalledModule Microsoft.Graph -ErrorAction SilentlyContinue).Version $graphLatestVerison = (Find-Module Microsoft.Graph).Version #Checking the Microsoft Graph module for installation if($graphCurrentVersion -eq $null){ Write-host "`nInstalling Microsoft Graph module version $graphLatestVerison..." Install-Module Microsoft.Graph -Scope CurrentUser -AllowClobber -Force Write-host "Microsoft Graph module version $graphLatestVerison is installed in the machine successfully" -ForegroundColor Green }else { Write-Host "`nThe Microsoft Graph module version $graphCurrentVersion has been installed on this computer." -ForegroundColor Green } #Update to Microsoft Graph PowerShell SDK v2 if (($currentVersion -ne $null) -and ($graphCurrentVersion -lt $graphLatestVerison)) { Write-host "`nUpdating Microsoft Graph module from $graphCurrentVersion to $graphLatestVerison..." Update-Module Microsoft.Graph -Force } #Checking the Microsoft Graph Beta module for installation $MsGraphBetaModule = Get-Module Microsoft.Graph.Beta -ListAvailable if($MsGraphBetaModule -eq $null){ Write-host "`nInstalling Microsoft Graph Beta module ..." Install-Module Microsoft.Graph.Beta -Scope CurrentUser -AllowClobber -Force Write-host "Microsoft Graph Beta module is installed in the machine successfully" -ForegroundColor Green }else { Write-Host "The Microsoft Graph Beta module has been installed on this computer." -ForegroundColor Green } Clear-Host