#Write-Host "Load script files..." -ForegroundColor DarkGray $scriptFiles = Get-ChildItem "$PSScriptRoot\*.ps1" -Exclude "*.Tests.ps1" -Recurse foreach ($script in $scriptFiles) { #Write-Host "`tLoad script:" $script.Name -ForegroundColor DarkGray try { #TODO: Suppress $Error entry recorded after module loading completed(can't suppress inside psm1 module?) . $script.FullName } catch [Management.Automation.ScriptRequiresException] { $errorRecord = $_ $exception = $errorRecord.Exception switch ($errorRecord.FullyQualifiedErrorId) { "ScriptRequiresElevation"{ Write-Warning ("`tSkip Load script: {0,-30}(Require runas administrator)" -f $script.Name) } "ScriptRequiresMissingModules"{ Write-Warning ("`tSkip Load script: {0,-30}(Require missing modules: {1})" -f $script.Name, $exception.MissingPSSnapIns[0]) } "ScriptRequiresMissingPSSnapIns"{ Write-Warning ("`tSkip Load script: {0,-30}(Require PSSnapin: {1})" -f $script.Name, $exception.MissingPSSnapIns[0]) } "ScriptRequiresUnmatchedPSVersion"{ Write-Warning ("`tSkip Load script: {0,-30}(Require PowerShell version: {1})" -f $script.Name, $exception.RequiresPSVersion) } "RequiresShellIDInvalidForSingleShell"{ Write-Warning ("`tSkip Load script: {0,-30}(Require PowerShell host ShellID: {1})" -f $script.Name, $exception.RequiresShellId) } default{ throw } } } } #TODO:Export only public members that match specific criteria. #Export-ModuleMember -Function * -Alias * -Cmdlet * -Variable *