Fabtools.psm1
<# .SYNOPSIS This script loads necessary modules, sources functions from .ps1 files, and sets aliases for PowerBI functions. .DESCRIPTION The script first tries to load the Az.Accounts and Az.Resources modules. If these modules are not available, it installs and imports them. It then gets all .ps1 files in the Functions folder, sources each function, and exports it as a module member. Finally, it sets an alias for the PowerBI login function. .EXAMPLE .\Fabtools.psm1 This command runs the script. .INPUTS None. You cannot pipe inputs to this script. .OUTPUTS None. This script does not return any output. .NOTES This script is part of the Fabtools module. #> $script:apiUrl = "https://api.fabric.microsoft.com/v1" $script:resourceUrl = "https://api.fabric.microsoft.com" $script:fabricToken = $null # Try to load necessary modules try { # Check if Az.Accounts module is available if (get-module -ListAvailable -name Az.Accounts) { # Import Az.Accounts module Import-Module Az.Accounts -erroraction silentlycontinue write-information "Az.Accounts module is loaded" } else { write-information "Az.Accounts module is not loaded. Loading it now..." # Install and import Az.Accounts module install-module -name Az.Accounts -force -scope allusers Import-Module Az.Accounts -erroraction silentlycontinue } # Check if Az.Resources module is available if (get-module -ListAvailable -name Az.Resources) { # Import Az.Resources module Import-Module Az.Resources -erroraction silentlycontinue write-information "Az.Resources module is loaded" } else { write-information "Az.Resources module is not loaded. Loading it now..." # Install and import Az.Resources module install-module -name Az.Resources -force -scope allusers Import-Module Az.Resources -erroraction silentlycontinue } } catch { # Handle any exceptions that occur during module loading write-information "Looks like the assemblies are allready loaded" } # Get all .ps1 files in the Functions folder $functions = Get-ChildItem -Path "$PSScriptRoot\Functions" -Filter *.ps1 # Loop over each function file foreach ($function in $functions) { # Dot-source the function . $function.fullname # Export the function as a module member Export-ModuleMember -Function $function.basename } # Set aliases for PowerBI functions Set-Alias -Name Login-Fabric -Value Login-PowerBI Export-ModuleMember -Alias Login-Fabric Set-Alias -Name Get-FabWorkspace -Value Get-FabricWorkspace Export-ModuleMember -Alias Get-FabDataset Set-Alias -Name Get-FabricDataset -Value Get-PowerBIDataset Export-ModuleMember -Alias Get-FabricDataset Set-Alias -Name Get-FabReport -Value Get-PowerBIReport Export-ModuleMember -Alias Get-FabReport Set-Alias -Name Get-FabricReport -Value Get-PowerBIReport Export-ModuleMember -Alias Get-FabricReport Set-Alias -Name Logout-Fabric -Value Logout-PowerBI Export-ModuleMember -Alias Logout-Fabric |