-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathInstall-Update-MicrosoftGraphPS-Microsoft.Graph.ps1
More file actions
83 lines (69 loc) · 3.11 KB
/
Install-Update-MicrosoftGraphPS-Microsoft.Graph.ps1
File metadata and controls
83 lines (69 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
##########################################################################################
# Pre-req script for getting environment ready with Microsoft.Graph and MicrosoftGraphPS
##########################################################################################
<#
.SYNOPSIS
Install and Update MicrosoftGraphPS module
Version management of Microsoft.Graph PS modules
.DESCRIPTION
MicrosoftGraphPS:
Install latest version of MicrosoftGraphPS, if not found
Updates to latest version of MicrosoftGraphPS, if switch ($AutoUpdate) is set to $True
Microsoft.Graph:
Installing latest version of Microsoft.Graph, if not found
Shows older installed versions of Microsoft.Graph
Checks if newer version if available from PSGallery of Microsoft.Graph
Automatic clean-up old versions of Microsoft.Graph
Update to latest version from PSGallery of Microsoft.Graph
.AUTHOR
Morten Knudsen, Microsoft MVP - https://mortenknudsen.net
.LINK
https://github.com/KnudsenMorten/MicrosoftGraphPS
#>
# Variables
$Scope = "AllUsers" # Valid parameters: AllUsers, CurrentUser
$AutoUpdate = $True
# Check if MicrosoftGraphPS is installed
$ModuleCheck = Get-Module -Name MicrosoftGraphPS -ListAvailable -ErrorAction SilentlyContinue
If (!($ModuleCheck)) # MicrosoftGraphPS is NOT installed
{
# check for NuGet package provider
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-host ""
Write-host "Checking Powershell PackageProvider NuGet ... Please Wait !"
if (Get-PackageProvider -ListAvailable -Name NuGet -ErrorAction SilentlyContinue -WarningAction SilentlyContinue)
{
Write-host ""
Write-Host "OK - PackageProvider NuGet is installed"
}
else
{
try
{
Write-host ""
Write-Host "Installing NuGet package provider .. Please Wait !"
Install-PackageProvider -Name NuGet -Scope $Scope -Confirm:$false -Force
}
catch [Exception] {
$_.message
exit
}
}
Write-host "Powershell module MicrosoftGraphPS was not found !"
Write-Host ""
Write-host "Installing latest version from PsGallery in scope $Scope .... Please Wait !"
Write-Host ""
Install-module -Name MicrosoftGraphPS -Repository PSGallery -Force -Scope $Scope
import-module -Name MicrosoftGraphPS -Global -force -DisableNameChecking -WarningAction SilentlyContinue
}
##########################################################################################
# Install/Update/Cleanup Microsoft.Graph and MicrosoftGraphPS
##########################################################################################
If ($AutoUpdate)
{
Manage-Version-Microsoft.Graph -InstallLatestMicrosoftGraph -CleanupOldMicrosoftGraphVersions -Scope $Scope
}
Else
{
Manage-Version-Microsoft.Graph -Scope $Scope
}