Skip to content

Commit

Permalink
Improved updating of ps modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjantzen committed Jan 21, 2023
1 parent 4f5a148 commit bebd826
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
29 changes: 21 additions & 8 deletions User Audit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if (($CheckEmail -and $EmailType -eq "O365") -or ($CheckAD -and $ADType -eq "Azu
If (Get-Module -ListAvailable -Name "MSAL.PS") {
Import-Module MSAL.PS
} else {
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-Module -Name MSAL.PS
}
}
Expand Down Expand Up @@ -111,6 +112,15 @@ if ($Version.Major -lt 2 -or $Version.Minor -lt 1) {
Install-Module -Name ITGlueAPI
Import-Module ITGlueAPI -Force
}

$Version = (Get-Module -ListAvailable -Name "ImportExcel").Version
if ($Version.Major -lt 7 -or $Version.Minor -lt 8 -or $Version.Build -lt 4) {
Remove-Module ImportExcel
Uninstall-Module ImportExcel
Install-Module -Name ImportExcel
Import-Module ImportExcel -Force
}

If (Get-Module -ListAvailable -Name "ImportExcel") {Import-module ImportExcel} Else { install-module ImportExcel -Force; import-module ImportExcel}

# Settings IT-Glue logon information
Expand Down Expand Up @@ -267,24 +277,27 @@ if ($CheckEmail) {
# Connect to the mail service (it works better doing this first thing)
if ($EmailType -eq "O365") {
Write-Host "Connecting to Office 365..."
# If using a version under 3, upgrade
$Version = (Get-Module -ListAvailable -Name "ExchangeOnlineManagement").Version
if ($Version -and $Version.Count -gt 1) {
$Version = $Version | Sort-Object -Property Major -Descending | Select-Object -First 1
}
if ($Version -and $Version.Major -lt 3) {
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Update-Module -Name ExchangeOnlineManagement -Force
}
If (Get-Module -ListAvailable -Name "ExchangeOnlineManagement") {
Import-Module ExchangeOnlineManagement
} else {
Install-Module PowerShellGet -Force
Install-Module -Name ExchangeOnlineManagement
Install-Module -Name ExchangeOnlineManagement -Confirm:$false
}

if ($O365UnattendedLogin -and $O365UnattendedLogin.AppId) {
Connect-ExchangeOnline -CertificateThumbprint $O365UnattendedLogin.CertificateThumbprint -AppID $O365UnattendedLogin.AppID -Organization $O365UnattendedLogin.Organization -ShowProgress $true -ShowBanner:$false
} else {
Connect-ExchangeOnline -UserPrincipalName $O365LoginUser -ShowProgress $true -ShowBanner:$false
}

# If using a version under 1.0.1, upgrade
$Version = (Get-Module ExchangeOnlineManagement).Version
if ($Version.Major -lt 1 -or $Version.Built -lt 1) {
Update-Module -Name ExchangeOnlineManagement
Import-Module ExchangeOnlineManagement -Force
}
} else {
If (Get-Module -ListAvailable -Name "CredentialManager") {
Import-Module CredentialManager
Expand Down
23 changes: 14 additions & 9 deletions User_Billing_Update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if (($CheckEmail -and $EmailType -eq "O365") -or ($CheckAD -and $ADType -eq "Azu
If (Get-Module -ListAvailable -Name "MSAL.PS") {
Import-Module MSAL.PS
} else {
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-Module -Name MSAL.PS
}
}
Expand Down Expand Up @@ -254,24 +255,27 @@ if ($CheckEmail) {
# Connect to the mail service (it works better doing this first thing)
if ($EmailType -eq "O365") {
Write-Host "Connecting to Office 365..."
# If using a version under 3, upgrade
$Version = (Get-Module -ListAvailable -Name "ExchangeOnlineManagement").Version
if ($Version -and $Version.Count -gt 1) {
$Version = $Version | Sort-Object -Property Major -Descending | Select-Object -First 1
}
if ($Version -and $Version.Major -lt 3) {
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Update-Module -Name ExchangeOnlineManagement -Force
}
If (Get-Module -ListAvailable -Name "ExchangeOnlineManagement") {
Import-Module ExchangeOnlineManagement
} else {
Install-Module PowerShellGet -Force
Install-Module -Name ExchangeOnlineManagement
Install-Module -Name ExchangeOnlineManagement -Confirm:$false
}

if ($O365UnattendedLogin -and $O365UnattendedLogin.AppId) {
Connect-ExchangeOnline -CertificateThumbprint $O365UnattendedLogin.CertificateThumbprint -AppID $O365UnattendedLogin.AppID -Organization $O365UnattendedLogin.Organization -ShowProgress $true -ShowBanner:$false
} else {
Connect-ExchangeOnline -UserPrincipalName $O365LoginUser -ShowProgress $true -ShowBanner:$false
}

# If using a version under 1.0.1, upgrade
$Version = (Get-Module ExchangeOnlineManagement).Version
if ($Version.Major -lt 1 -or $Version.Built -lt 1) {
Update-Module -Name ExchangeOnlineManagement
Import-Module ExchangeOnlineManagement -Force
}
Write-PSFMessage -Level Verbose -Message "Imported O365 related modules."
} elseif ($EmailType -eq "Exchange") {
If (Get-Module -ListAvailable -Name "CredentialManager") {
Expand Down Expand Up @@ -1587,7 +1591,6 @@ if ($UserAudit) {
################
if ($BillingUpdate) {
Write-PSFMessage -Level Verbose -Message "Starting Billing Update."
If (Get-Module -ListAvailable -Name "ImportExcel") {Import-module ImportExcel} Else { install-module ImportExcel -Force; import-module ImportExcel}

$Version = (Get-Module -ListAvailable -Name "ImportExcel").Version
if ($Version.Major -lt 7 -or $Version.Minor -lt 8 -or $Version.Build -lt 4) {
Expand All @@ -1596,6 +1599,8 @@ if ($BillingUpdate) {
Install-Module -Name ImportExcel
Import-Module ImportExcel -Force
}

If (Get-Module -ListAvailable -Name "ImportExcel") {Import-module ImportExcel} Else { install-module ImportExcel -Force; import-module ImportExcel}

# Get a fresh list of contacts from IT Glue
$FullContactList = @()
Expand Down
2 changes: 1 addition & 1 deletion currentversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.15.1
2.15.2

0 comments on commit bebd826

Please sign in to comment.