Powershell Script Error

Craig Paulsen
Craig Paulsen used Ask the Experts™
on
Guys, I  need some help with the following PS script

Getting the below error
PS C:\XXXXXXXX\APFW\Scripts> .\Start-XXXSimplePatching_DEVONLY.ps1 -Group "Server XXXXXX Development Group" -EndTime 26/
02/2019 23:00
Get-WsusComputer : Cannot validate argument on parameter 'ComputerTargetGroups'. The argument is null or empty.
Provide an argument that is not null or empty, and then try the command again.
At C:\XXXXXXXX\APFW\Scripts\Manual_Remove-PatchFile_script.ps1:5 char:51
+ $Servers = Get-WsusComputer -ComputerTargetGroups "$Group"
+                                                   ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-WsusComputer], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.UpdateServices.Commands.GetWsusComputerComman


Script Details as follows:

Param(
[String]$Group,
[STRING]$EndTime,
[STRING]$EndDate
)

Import-Module PoshRSJob
Import-Module AutomatedPatching
$Group = "XXXXXXXX Servers Dev"
# Define log folder location

$LogFolder = "C:\XXXXXXX\APFW\Logs\$Group\"

If ((Test-Path -Path "$LogFolder") -eq $false) {
    New-Item -Path "$LogFolder" -ItemType Directory
    }

# Ensure all old log files are removed to allow fresh start

C:\XXXXXXX\APFW\Scripts\Manual_Remove-PatchFile_script(2).ps1 -List "C:\XXXXXXX\APFW\Manual_Lists\Dev_Servers.txt"

# Patch only Simple servers

$Servers = Get-Content -Path "C:\XXXXXXX\APFW\Manual_Lists\Dev_Servers.txt"
$Servers | Export-CSV -Path "C:\temp\$Group.csv" -notypeinformation


foreach ($Server in $Servers) {
        $SRV = $server.FullDomainName.TrimEnd("ds.acc.co.nz")
        Start-APFWPatching -computername $SRV -enddate $EndDate -endtime $EndTime -wait 15 -Verbose | Out-File "$LogFolder\$SRV.txt"
    }







Function Manual_Remove-PatchFile_script {
    Param(
    [String]$Group
    )

    $Servers = Get-WsusComputer -ComputerTargetGroups "$Group"
    
    foreach ($server in $servers.fulldomainname) {
        $server = $Server.TrimEnd(".ds.XXX.co.XX")
        $StatusFile = "\\$Server\C$\windows\temp\$Server.xml"

        If ((Test-Path -Path $StatusFile) -eq $true) {
            Remove-Item -Path $StatusFile -Force
        }
    }
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sam JacobsDirector of Technology Development, IPM

Commented:
That should be:
 $Servers = Get-WsusComputer -ComputerTargetGroups "$($Group)"

Open in new window

If it is a single group without spaces or special characters in the name, you can leave out the quotes:
 $Servers = Get-WsusComputer -ComputerTargetGroups $Group

Open in new window

Craig PaulsenSenior Systems Engineer

Author

Commented:
will modify this
Craig PaulsenSenior Systems Engineer

Author

Commented:
still the same error
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Sam JacobsDirector of Technology Development, IPM

Commented:
Is the error in the same place? Maybe the value is actually blank.
Can you place the following right above that line:
Write-Host  "Value of Group: $($Group)"

Open in new window

What gets printed out?
Director of Technology Development, IPM
Commented:
I think I see the problem ... While you are passing $Group to the script, you are not passing it to the function Manual_Remove-PatchFile_script.
Craig PaulsenSenior Systems Engineer

Author

Commented:
thanks, appreciate that Sam, it's looking alot better now, it's outputting the list to C:temp
Sam JacobsDirector of Technology Development, IPM

Commented:
Cool ... most welcome.
Craig PaulsenSenior Systems Engineer

Author

Commented:
thanks again mate

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial