Craig Paulsen
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.ps 1 -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\M anual_Remo ve-PatchFi le_script. ps1:5 char:51
+ $Servers = Get-WsusComputer -ComputerTargetGroups "$Group"
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-WsusComputer], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nError,Mic rosoft.Upd ateService s.Commands .GetWsusCo mputerComm an
Script Details as follows:
Getting the below error
PS C:\XXXXXXXX\APFW\Scripts> .\Start-XXXSimplePatching_
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\M
+ $Servers = Get-WsusComputer -ComputerTargetGroups "$Group"
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-WsusComputer], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
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
}
}
}
ASKER
will modify this
ASKER
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:
Can you place the following right above that line:
Write-Host "Value of Group: $($Group)"
What gets printed out?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks, appreciate that Sam, it's looking alot better now, it's outputting the list to C:temp
Cool ... most welcome.
ASKER
thanks again mate
Open in new window
If it is a single group without spaces or special characters in the name, you can leave out the quotes:Open in new window