Skip to content

Commit

Permalink
✨ Automatic update checking
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Tainton <[email protected]>
  • Loading branch information
luketainton committed Aug 7, 2020
1 parent ab72c8c commit db150a3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ This module uses PowerShell, which is pre-installed on Windows. If you're not on
```
1. Run `Import-TeamsUsers -File <FILE>`, where `<FILE>` is the path to the CSV file. You can add the `-Create` flag if you want to create a new team first.

<details>
<summary>If you can't run non-signed scripts</summary>
If your policy requires scripts to be digitally signed, run
### If you can't run non-signed scripts
If your policy requires scripts to be digitally signed, run

```powershell
Set-ExecutionPolicy Bypass -Scope Process
```
then try running the command again. You may require administrative rights to change the Execution Policy.
</details>

# Need help?
If you need assistance, please try the following:
Expand Down
2 changes: 1 addition & 1 deletion TeamsUserEnroller.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# RootModule = ''

# Version number of this module.
ModuleVersion = '2.2.0'
ModuleVersion = '2.2.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
33 changes: 33 additions & 0 deletions TeamsUserEnroller.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,39 @@ Function Import-TeamsUsers {

Begin {
$ErrorActionPreference = 'Stop'

##### CHECK FOR NEW VERSION #####
Try {
# Get information from GitHub Releases
$releases = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/luketainton/TeamsUserEnroller/releases";
$rel = $releases[0];
$latest_version = $rel.tag_name -replace 'v', '';
$latest_version_changes = $rel.body;

# Get currently installed version
$current_version = (Get-Module TeamsUserEnroller | Select-Object Version).Version;

# Compare versions and alert user if newer version available
if ($current_version -lt $latest_version) {
Write-Host -ForegroundColor Yellow "A new version of TeamsUserEnroller has been released!";
Write-Host -ForegroundColor Yellow "Latest version: $latest_version";
Write-Host -ForegroundColor Yellow "Installed version: $current_version";
Write-Host -ForegroundColor Yellow "`n$latest_version_changes";
$Consent = Read-Host -Prompt "`nWould you like to update now? [y/N]"
If ($Consent -eq "y" -Or $Consent -eq "Y") {
Update-Module -Name TeamsUserEnroller -RequiredVersion "2.2.0";
$after_update_ver = (Get-Module TeamsUserEnroller | Select-Object Version).Version;
if ($after_update_ver -eq $latest_version) {
Write-Host -ForegroundColor Green "Update completed.";
} Else {
Write-Host -ForegroundColor Red "Update failed. Please update manually.";
}
}
}
} Catch {
Write-Host -ForegroundColor Red "An error occurred while checking for updates. Continuing.";
}

##### IMPORT CSV FILE #####
Try {
$ImportCmd = "Import-CSV $File"
Expand Down

0 comments on commit db150a3

Please sign in to comment.