Automatos.Common.psm1
# Module name $S = get-date $moduleName = "Automatos.Common" # Get Directory Path $moduleData = (Get-Module -ListAvailable $moduleName) $moduleDirectory = $ModuleData.ModuleBase New-Variable -Name "PS_$($moduleName)_Directory" -Scope Global -Value $moduleDirectory -Force # Dependency Check [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") # Dot Source Commands Into Session $functionFiles = (Get-ChildItem -Path "$moduleDirectory\Functions" -File -Recurse | where extension -like ".ps1") if ($functionFiles) { $existingFunctions = (($moduleData.ExportedCommands.Keys | sort) -join ', ') $functionsToAdd = foreach ($File in $FunctionFiles) { . "$($File.FullName)" ($File.Name -split "\.")[0] } $functionsToAddString = (($functionsToAdd | sort) -join ', ') if ($functionsToAddString -ne $existingFunctions) { Update-ModuleManifest -Path "$moduleDirectory\$moduleName.psd1" -FunctionsToExport $functionsToAdd } } # Recover From Manifest Erasure Bug $Manifest = get-item "$moduledirectory/$modulename.psd1" if($manifest.Length -eq 0){Copy-Item -Path "$($manifest.FullName).bak" -Destination "$($manifest.FullName)"} # Variable/Credential Establishment if(!$Global:PS_ProfileAutoload) { $DynamicModuleScope = switch -Wildcard ($MyInvocation.MyCommand.Path){"*$env:USERNAME*"{"User"};"*\Program Files\*"{"Program"};"*\System32\*"{"Global"}} New-PSProfile -ModulePrefix (Read-Host -Prompt "Custom Module Name Prefix?") -ModuleCompany (Read-Host -Prompt "Custom Module Company Name") -ModuleScope $DynamicModuleScope Import-PSProfile } #$Global:PS_CredentialMetadata = Import-CredentialMetadata # End Timing $E = get-date $D = [math]::Round(($E-$S).TotalSeconds,2) Write-Host "Module $Modulename Loaded in $D seconds" -ForegroundColor Cyan |