PSAutomator.psm1
#Get public and private function definition files. $Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue -Recurse ) $Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue -Recurse ) $Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\*.dll -ErrorAction SilentlyContinue -Recurse ) #Dot source the files Foreach ($Import in @($Public + $Private)) { Try { . $Import.fullname } Catch { Write-Error -Message "Failed to Import function $($Import.fullname): $_" } } Foreach ($Import in @($Assembly)) { Try { Add-Type -Path $Import.fullname } Catch { Write-Error -Message "Failed to Import DLL $($Import.fullname): $_" } } Export-ModuleMember -Function 'Action', 'Condition', 'Ignore', 'Service', 'Trigger' #Export-ModuleMember -Function '*' [string] $ManifestFile = '{0}.psd1' -f (Get-Item $PSCommandPath).BaseName; $ManifestPathAndFile = Join-Path -Path $PSScriptRoot -ChildPath $ManifestFile; if ( Test-Path -Path $ManifestPathAndFile) { $Manifest = (Get-Content -raw $ManifestPathAndFile) | iex; foreach ( $ScriptToProcess in $Manifest.ScriptsToProcess) { $ModuleToRemove = (Get-Item (Join-Path -Path $PSScriptRoot -ChildPath $ScriptToProcess)).BaseName; if (Get-Module $ModuleToRemove) { Remove-Module $ModuleToRemove; } } } |