SifHelper.psm1
#Requires -RunAsAdministrator #Requires -Modules PKI,WebAdministration Set-StrictMode -Version Latest # Pass verbose on if required $DestinationFolder = Split-Path $PSScriptRoot -Parent $filename = "SifHelper.{0:yyMMdd}" -f (Get-Date) $counter = 2 $fullPath = Join-Path $DestinationFolder "$filename.log" while (Test-Path $fullPath) { $fullPath = Join-Path $DestinationFolder "$filename ($($counter)).log" $counter++ } Start-Transcript -Path $fullpath -IncludeInvocationHeader try { $scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path ('Private' , 'Public') | ForEach-Object { $itemName = $_ $childItemPath = (Join-Path $scriptRoot $itemName) Write-Verbose "Evaluating path $($childItemPath)." $childItems = Get-ChildItem -Path $childItemPath -Include *.ps1,*.psm1 -Exclude *.Tests.ps1 -File -Recurse -ErrorAction SilentlyContinue $childItemsCount = 0 if ($childItems) { $childItemsCount = $childItems.Count } Write-Verbose "Found $childItemsCount items." $childItems | ForEach-Object { try { $fullName = $_.FullName Write-Verbose "Importing module $fullName" Import-Module $fullName -Force Write-Verbose "Dot Sourcing $fullName" . $fullName if ($itemName -eq 'Public') { Export-ModuleMember -Function $_.BaseName } } catch { Write-Warning $_.Exception.Message } } } } catch { Write-Error $_ throw } finally { Stop-Transcript } |