Skip to content

Instantly share code, notes, and snippets.

@mortenya
Last active August 29, 2015 14:02
Show Gist options
  • Save mortenya/3867b1347ba592435df7 to your computer and use it in GitHub Desktop.
Save mortenya/3867b1347ba592435df7 to your computer and use it in GitHub Desktop.
Originally written by Boe Prox, when loading a custom module this will source any scripts in the $ModulePath\Scripts folder, as well as check if you've loaded PowerShell as an Administrator.
#Validate user is an Administrator
Write-Verbose "Checking Administrator credentials"
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "You are not running this as an Administrator!`nPlease re-run module with an Administrator Account."
Break
}
#Load Functions
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
Try {
Get-ChildItem "$ScriptPath\Scripts" | Select -Expand FullName | ForEach {
$Function = Split-Path $_ -Leaf
. $_
}
} Catch {
Write-Warning ("{0}: {1}" -f $Function,$_.Exception.Message)
Continue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment