Link to home
Start Free TrialLog in
Avatar of Craig Paulsen
Craig PaulsenFlag for New Zealand

asked on

Powershell Script Error

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

Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

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

Avatar of Craig Paulsen

ASKER

will modify this
still the same error
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?
ASKER CERTIFIED SOLUTION
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks, appreciate that Sam, it's looking alot better now, it's outputting the list to C:temp
Cool ... most welcome.
thanks again mate