@@ -18,6 +18,10 @@ function Get-RandomName {
1818 return (' abcdefghijklmnopqrstuvwxyz' [$r ] -join ' ' )
1919}
2020
21+ function Test-IsAdmin {
22+ return ([Security.Principal.WindowsPrincipal ] [Security.Principal.WindowsIdentity ]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole ] " Administrator" )
23+ }
24+
2125
2226# #######################################################
2327#
@@ -79,11 +83,16 @@ Describe 'Get-ModifiableFile' {
7983
8084Describe ' Get-ServiceUnquoted' {
8185
86+ if (-not $ (Test-IsAdmin )) {
87+ Throw " 'Get-ServicePermission' Pester test needs local administrator privileges."
88+ }
89+
8290 It " Should not throw." {
8391 {Get-ServiceUnquoted } | Should Not Throw
8492 }
8593
8694 It ' Should return service with a space in an unquoted binPath.' {
95+
8796 $ServiceName = Get-RandomName
8897 $ServicePath = " C:\Program Files\service.exe"
8998
@@ -115,6 +124,10 @@ Describe 'Get-ServiceUnquoted' {
115124
116125Describe ' Get-ServiceFilePermission' {
117126
127+ if (-not $ (Test-IsAdmin )) {
128+ Throw " 'Get-ServiceFilePermission' Pester test needs local administrator privileges."
129+ }
130+
118131 It ' Should not throw.' {
119132 {Get-ServiceFilePermission } | Should Not Throw
120133 }
@@ -155,6 +168,10 @@ Describe 'Get-ServiceFilePermission' {
155168
156169Describe ' Get-ServicePermission' {
157170
171+ if (-not $ (Test-IsAdmin )) {
172+ Throw " 'Get-ServicePermission' Pester test needs local administrator privileges."
173+ }
174+
158175 It ' Should not throw.' {
159176 {Get-ServicePermission } | Should Not Throw
160177 }
@@ -193,7 +210,11 @@ Describe 'Get-ServiceDetail' {
193210# #######################################################
194211
195212Describe ' Invoke-ServiceAbuse' {
196-
213+
214+ if (-not $ (Test-IsAdmin )) {
215+ Throw " 'Invoke-ServiceAbuse' Pester test needs local administrator privileges."
216+ }
217+
197218 BeforeEach {
198219 $ServicePath = " $ ( Get-Location ) \$ ( [IO.Path ]::GetRandomFileName()) " + " .exe"
199220 $Null = sc.exe create " PowerUpService" binPath= $ServicePath
@@ -255,6 +276,10 @@ Describe 'Invoke-ServiceAbuse' {
255276
256277Describe ' Install-ServiceBinary' {
257278
279+ if (-not $ (Test-IsAdmin )) {
280+ Throw " 'Install-ServiceBinary' Pester test needs local administrator privileges."
281+ }
282+
258283 BeforeEach {
259284 $ServicePath = " $ ( Get-Location ) \powerup.exe"
260285 $Null | Out-File - FilePath $ServicePath - Force
@@ -363,6 +388,10 @@ Describe 'Find-DLLHijack' {
363388
364389Describe ' Find-PathHijack' {
365390
391+ if (-not $ (Test-IsAdmin )) {
392+ Throw " 'Find-PathHijack' Pester test needs local administrator privileges."
393+ }
394+
366395 It ' Should find a hijackable %PATH% folder.' {
367396
368397 New-Item - Path C:\PowerUpTest\ - ItemType directory - Force
@@ -422,6 +451,11 @@ Describe 'Get-RegAutoLogon' {
422451
423452
424453Describe ' Get-VulnAutoRun' {
454+
455+ if (-not $ (Test-IsAdmin )) {
456+ Throw " 'Get-VulnAutoRun' Pester test needs local administrator privileges."
457+ }
458+
425459 It ' Should not throw.' {
426460 {Get-VulnAutoRun } | Should Not Throw
427461 }
@@ -451,6 +485,11 @@ Describe 'Get-VulnAutoRun' {
451485# #######################################################
452486
453487Describe ' Get-VulnSchTask' {
488+
489+ if (-not $ (Test-IsAdmin )) {
490+ Throw " 'Get-VulnSchTask' Pester test needs local administrator privileges."
491+ }
492+
454493 It ' Should not throw.' {
455494 {Get-VulnSchTask } | Should Not Throw
456495 }
@@ -476,6 +515,11 @@ Describe 'Get-VulnSchTask' {
476515
477516
478517Describe ' Get-UnattendedInstallFile' {
518+
519+ if (-not $ (Test-IsAdmin )) {
520+ Throw " 'Get-UnattendedInstallFile' Pester test needs local administrator privileges."
521+ }
522+
479523 It ' Should not throw.' {
480524 {Get-UnattendedInstallFile } | Should Not Throw
481525 }
0 commit comments