Orbit.psm1
using module .\Class\Orbit.Enums.ps1 using module .\Class\Orbit.Classes.psm1 # Above needs to remain the first line to import Classes # remove the comment when using classes # Requirements #requires -Version 5 #Requires -Modules @{ ModuleName="MicrosoftTeams"; ModuleVersion="5.5.0" } #Requires -Modules @{ ModuleName="Microsoft.Graph"; ModuleVersion="2.6.1" } #Req#uires -Modules @{ ModuleName="Microsoft.PowerShell.PSResourceGet"; ModuleVersion="0.5.23" } #BODGE this does not yet work for pre-released versions it seems. To be fixed once it reaches v1.0? #Req#uires -Modules @{ ModuleName='Orbit.Authentication'; RequiredVersion = '0.0.0.0' } #Req#uires -Modules @{ ModuleName='Orbit.Groups'; RequiredVersion = '0.0.0.0' } #Req#uires -Modules @{ ModuleName='Orbit.Teams'; RequiredVersion = '0.0.0.0' } #Req#uires -Modules @{ ModuleName='Orbit.Tools'; RequiredVersion = '0.0.0.0' } #Req#uires -Modules @{ ModuleName='Orbit.Users'; RequiredVersion = '0.0.0.0' } <# Orbit - Module supplementing Microsoft.Graph and MicrosoftTeams Supporting Teams Administration, Voice Configuration for Tenant and Users User Configuration for Voice, Creation and connection of Resource Accounts, Licensing of Objects for Calling Plans & Direct Routing, Creation and Management of Call Queues and Auto Attendants by David Eberhardt Orbit-Module@outlook.com @MightyOrmus www.davideberhardt.at https://github.com/DEberhardt https://davideberhardt.wordpress.com/ Any and all technical advice, scripts, and documentation are provided as is with no guarantee. Always review any code and steps before applying to a production system to understand their full impact. .LINK https://github.com/DEberhardt/Orbit/tree/master/docs #> #region Functions #Get public and private function definition files. $Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse -ErrorAction SilentlyContinue ) $Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -Recurse -ErrorAction SilentlyContinue ) #Dot source the files Foreach ($Function in @($Public + $Private)) { Try { . $Function.Fullname } Catch { Write-Error -Message "Failed to import function $($Function.Fullname): $_" } } # Exporting Module Members (Functions) Export-ModuleMember -Function $Public.Basename #endregion #region Aliases # Query Aliases $Aliases = $null #$Aliases = Foreach ($Function in @($Public + $Private)) { $Aliases = Foreach ($Function in @($Public)) { if ( $($Function.Fullname) -match '.tests.ps1' ) { continue } $Content = $AliasBlocks = $null $Content = $Function | Get-Content $AliasBlocks = $Content -split "`n" | Select-String 'Alias\(' -Context 1, 1 $AliasBlocks | ForEach-Object { $Lines = $($_ -split "`n") if ( $Lines[0] -match 'CmdletBinding' -or $Lines[0] -match 'OutputType' -or $Lines[2] -match 'CmdletBinding' -or $Lines[2] -match 'OutputType' ) { if ( $($_ -split "`n")[1] -match "Alias\('(?<content>.*)'\)" ) { $($matches.content -split ',' -replace "'" -replace ' ') | ForEach-Object { if ( $_ -ne '' ) { $_ } } } } else { continue } } } # Manual definitions $ManualAliases = @() # Exporting Module Members (Aliases) $AliasesToExport = @($Aliases + $ManualAliases) Write-Verbose -Message "Aliases to Export - Count: $($Aliases.Count)" Write-Verbose -Message "Aliases to Export - List: $($Aliases -join ',')" if ( $AliasesToExport ) { Export-ModuleMember -Alias $AliasesToExport } #endregion #region Variables # Defining Help URL Base string: $global:OrbitHelpURLBase = 'https://github.com/DEberhardt/Orbit/blob/main/docs/' # Adding Testing Mocked Objects for all modules to draw from . ($PSScriptRoot + '\Tests\Testing-MockedObjects.ps1') #endregion #region Custom Module Functions # Addressing Limitations # Strict Mode function Get-StrictMode { # returns the currently set StrictMode version 1, 2, 3 or 0 if StrictMode is off. #NOTE Higher versions may be available but not able to test against them yet. Functionally v3 is the highest try { $xyz = @(1); $null = ($null -eq $xyz[2]) } catch { return 3 } try { 'Not-a-Date'.Year } catch { return 2 } try { $null = ($undefined -gt 1) } catch { return 1 } return 0 } if ((Get-StrictMode) -gt 0) { Write-Verbose 'Orbit: Strict Mode interferes with Script execution. Switching Strict Mode off' Set-StrictMode -Off } # Allows use of [ArgumentCompletions] block native to PowerShell 6 and later! #TEST whether using Register-ArgumentCompleter now makes this stop working on PowerShell 5... # May need to have [ArgumentCompletions()] re-instatated if we need it! #CHECK do we need to have v5 compatibility? if ($PSVersionTable.PSEdition -ne 'Core') { # This provides backwards compatibility to PowerShell 5 # add the attribute [ArgumentCompletions()]: $code = @' using System; using System.Collections.Generic; using System.Management.Automation; public class ArgumentCompletionsAttribute : ArgumentCompleterAttribute { private static ScriptBlock _createScriptBlock(params string[] completions) { string text = "\"" + string.Join("\",\"", completions) + "\""; string code = "param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams);@(" + text + ") -like \"*$WordToComplete*\" | Foreach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }"; return ScriptBlock.Create(code); } public ArgumentCompletionsAttribute(params string[] completions) : base(_createScriptBlock(completions)) { } } '@ try { $null = Add-Type -ErrorAction Stop -TypeDefinition $code *>&1 } catch { Write-Verbose -Message 'Type for ArgumentCompletions already added' } } #endregion |