In creating my script for WSUS I ran into an error I haven't seen before and spending way too much time trying to figure out why I get this error. In my IF(condition){commands} segment I get the following error:
At line:11 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
If I leave out the trailing '}' the script segment runs. Any ideas why I'm getting this error and why I can't "close" my IF statement with the trailing }? My rough code segment is as follows:
$WsusServer = "SUSServer"
$UseSSL = $false
$PortNumber = 8530
$TrialRun = $false
$SMTPServer = "relayserver here"
$MailFrom = "SUSServer@domain.local"
$MailTo = "myEmailAddress"
$MessageSubject = "Windows group patching"
Function SendEmailStatus($MessageSubject, $MessageBody)
{
$SMTPMessage = New-Object System.Net.Mail.MailMessage $MailFrom, $MailTo, $MessageSubject, $MessageBody
$SMTPMessage.IsBodyHTML = $true
#Send the message via the local SMTP Server
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SMTPServer
$SMTPClient.Send($SMTPMessage)
$SMTPMessage.Dispose()
rv SMTPClient
rv SMTPMessage
}
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
$WsusServerAdminProxy = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($WsusServer,$UseSSL,$PortNumber);
$Style = "<Style>BODY{font-size:11px;font-family:verdana,sans-serif;color:navy;font-weight:normal;}" + `
"TABLE{border-width:1px;cellpadding=10;border-style:solid;border-color:navy;border-collapse:collapse;}" + `
"TH{font-size:12px;border-width:1px;padding:10px;border-style:solid;border-color:blue;}" + `
"TD{font-size:10px;border-width:1px;padding:10px;border-style:solid;border-color:navy;}</Style>"
$itanium = $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined}
If ($itanium.Count -gt 0)
{
$MessageBody = $itanium | Select `
@{Name="Title";Expression={[string]$_.Title}},`
#@{Name="KB Article";Expression={[string]::join(' | ',$_.KnowledgebaseArticles)}},`
@{Name="Classification";Expression={[string]$_.UpdateClassificationTitle}},`
@{Name="Product Description";Expression={[string]::join(' | ',$_.Description)}},`
#@{Name="Product Family";Expression={[string]::join(' | ',$_.ProductFamilyTitles)}},`
@{Name="Uninstallation Supported";Expression={[string]$_.UninstallationBehavior.IsSupported}} | ConvertTo-HTML -head $Style}
SendEmailStatus $MessageSubject $MessageBody
- Saeldur