FeaturedPower ShellScripts

SCCM Primary Site Missing Boundaries – Alert

Use this script to create a task schedule to alert when there is new boundaries discovered in SCCM Primary site.

 

      $from="email address"
    $to="email address"
      $subject="Found a new Missing Boundary from Boundary Group"
      $body="The $boundaryname is missing "
      $SmtpServer = "mailhost.domainname.com"

      $html=""
      $actualbody = "<html>

      <style>
      BODY{font-family: Arial; font-size: 12pt;}
      H1{font-size: 26px;}
      H2{font-size: 24px;}
      H3{font-size: 08px;}
      </style>
      <body>
      <h1 align=""center"">Found Missing Boundary</h1>
      <h2 align=""center"">$body</h2>

      <p>Test email</p><br/>" + $html
      #$testattachment="C:\PowerShell Wild cards.docx"



$boundary = Get-CMBoundary | where-object {($_.groupcount -eq 0 ) -and ($_.displayname -match 'domain.com*')-and ($_.BoundaryType -eq 3) } 
#$boundary | gm

if ($boundary) {
      $boundary  | select displayname, boundaryID, GroupCount, value, BoundaryType, DefaultSiteCode | ft -AutoSize

       #Send-MailMessage -From 'email address' -To 'email address' -Subject "Found A missing Boundary In SCCM" -Body "Please find below Boundaries are missing from Boundary Group" –SmtpServer 'mailhost.domain.com'
      $boundaryname = ($boundary).DisplayName
      $body="The $boundaryname is missing from Boundary Group "
        Write-Host "The body of the email will be" $body
    
     Send-MailMessage -From $from -to $to -Subject $subject -SmtpServer $SmtpServer -Body $actualbody -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8)
      Write-Host "Email Sent"

  }else {
  write-host "there is no boundary missing"
  }

 

Show More

Related Articles

Back to top button