Skip to content

Commit

Permalink
Improved invocation method detection
Browse files Browse the repository at this point in the history
  • Loading branch information
HotCakeX committed Jan 12, 2024
1 parent f708a0e commit 6c6e1e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,14 @@ Function Protect-WindowsSecurity {

# Determining whether to use the files inside the module or download them from the GitHub repository
[System.Boolean]$IsLocally = $false
if ($PSCommandPath) {
if ((Split-Path -Path $PSCommandPath -Leaf) -eq 'Protect-WindowsSecurity.psm1') {
# Test for $null or '' or all-whitespace or any stringified value being ''
if (-NOT [System.String]::IsNullOrWhitespace($PSCommandPath)) {
try {
# Get the name of the file that called the function
[System.String]$PSCommandPathToProcess = Split-Path -Path $PSCommandPath -Leaf
}
catch {}
if ($PSCommandPathToProcess -eq 'Protect-WindowsSecurity.psm1') {
Write-Verbose -Message 'Running Protect-WindowsSecurity function as part of the Harden-Windows-Security module'

Write-Verbose -Message 'Importing the required sub-modules'
Expand Down
10 changes: 8 additions & 2 deletions Harden-Windows-Security.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,14 @@ Function Protect-WindowsSecurity {

# Determining whether to use the files inside the module or download them from the GitHub repository
[System.Boolean]$IsLocally = $false
if ($PSCommandPath) {
if ((Split-Path -Path $PSCommandPath -Leaf) -eq 'Protect-WindowsSecurity.psm1') {
# Test for $null or '' or all-whitespace or any stringified value being ''
if (-NOT [System.String]::IsNullOrWhitespace($PSCommandPath)) {
try {
# Get the name of the file that called the function
[System.String]$PSCommandPathToProcess = Split-Path -Path $PSCommandPath -Leaf
}
catch {}
if ($PSCommandPathToProcess -eq 'Protect-WindowsSecurity.psm1') {
Write-Verbose -Message 'Running Protect-WindowsSecurity function as part of the Harden-Windows-Security module'

Write-Verbose -Message 'Importing the required sub-modules'
Expand Down

0 comments on commit 6c6e1e9

Please sign in to comment.