Last active
August 29, 2015 14:02
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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