Friday, July 21, 2017

Automatically add entries to a SharePoint calendar

I created a pretty cool script today to prebook slots in a SharePoint calendar.

This could be handy if you want to use a SharePoint calendar for a booking system, like appointments or room bookings.


#################################################################
#
#
#     Sharepoint-AddCalendarBookings.ps1
#
#
#     This script will add a set of calendar entries to a sharepoint calendar
#     with a status of Free. The intention is to use this calendar as a booking system
#     for appointments
#
#     It will, by default, add it for next month. Change the addmonths variable to
#     a bigger number to affect a different month in the future (next month = this month + 1)
#
#     It will, by default, book 15 minute slots. Change the $a variable to increase this value
#
#################################################################

#Variables
$webURL = "http://sharepointwebsiteaddresshere" 
$listName = "ListNamehere" 

$addmonths = 3 # number of months to add to calculation

$a = 15 # duration of the appointment

$StartTime = "09:00:00" # time of first appointment
$NumAppt = "27" # number of appt for day (9-4 is 8 hours, 8*60/15 = 28, less one slot is 27) if you change length of appt you will need to change this value

# end of variables

# there should be no need to update the script beyond this point


#Add SharePoint PowerShell Snapin which adds SharePoint specific cmdlets 
Add-PSSnapin Microsoft.SharePoint.PowerShell
  
#Get the SPWeb object and save it to a variable 
$web = Get-SPWeb $webURL 

#Get the SPList object to retrieve the "Demo List" 
$list = $web.Lists[$listName]

# get today's date
$today = get-date

# get next month
$nextmonth = $today.AddMonths($addmonths)

# get the month and year value for next month
$month = ($nextmonth).Month
$year = ($nextmonth).Year


# now get the number of days in the month

$eom  = [datetime]::DaysInMonth($year,$month)


# now, lets loop through the number of days in the month
foreach ($n in 1..$eom) {

$date = get-date "$month/$n/$year $StartTime"

$day = ($date).DayOfWeek.value__

# make sure we don't book week-ends
if ($day -ne 0 -and $day -ne 6){

foreach ($q in 0..$NumAppt) {
   $i = $a*$q

$timeslot = (get-date $date).AddMinutes($i)


#Create a new item 
$newItem = $list.Items.Add() 
 
#Add properties to this list item 
$newItem["Title"] = "Appointment Open Slot"
$newItem["Category"] = "Appointment"
$newItem["Start Time"] = $timeslot
$newItem["End Time"] = ($timeslot).AddMinutes($a)
$newItem["Status"] = "Free"

 
#Update the object so it gets saved to the list 
$newItem.Update() 

write-host "Entry added for $timeslot"

}

}

}


I’ve been helping a customer build a booking system for one of their processes using Service Manager, Orchestrator and Sharepoint, which is why this script was born.

Friday, July 7, 2017

Orchestrator connector doesn’t sync in #SCSM

I ran into an issue today with an Orchestrator connector that just would not sync in Service Manager, and event 26319 being logged in the Operations Manager event log on the SCSM Management Server.

This is what the event looks like:

Capture-scsm1

All services were started, could open the Orchestrator web service URL from the SCSM server, and nothing seemed out of order.

Quick restart of the Microsoft Monitoring Agent on the SCSM MS fixed the issue.

Wednesday, June 28, 2017

Unsealed management pack backups

I have finally created an updated version of the old management pack backups script I created with a colleague in a previous life.

You can use this one to schedule your unsealed MP backups on a regular basis. Just update the location of the backup folder (highlighted), save as a .ps1 file and go.

Have tested on OpsMgr 2012 and OpsMgr 2016.

 

##############################################################################
#
#   SCOM-UnsealedMP-Backup.ps1
#
#    This script backs up all unsealed management packs to a folder with the backup date as folder name
#
##############################################################################

# Variables

$ReportDate = Get-Date -format "yyyy-M-dd"
$path = "c:\Backups\$ReportDate\"


# there should be no need to update the script beyond this point

# test if the folder exists, and, if not, create it

If (!(Test-Path $path)){
    New-Item -ItemType directory -Path $path
}

# Connect to Operations Manager

Import-module OperationsManager

# get all the unsealed management packs and create array

$MPS = Get-SCOMManagementPack | where {$_.Sealed -eq $false}

# step through the management packs and export them to the folder specified
foreach($mp in $mps)
{
export-SCOMmanagementpack -managementpack $mp -path $path
}

Wednesday, February 15, 2017

Quickfix: OpsMgr console crash with System.IO.FileNotFoundException error

Ran into an issue at a customer site today and I want to remember how to resolve it next time Smile

Installed the OpsMgr 2012 console by running the OMConsole.msi file instead of launching the installation from the splash screen, and then launched the console. The console will attempt to load, and then fail with a .Net error. The following event will be logged in the Application Event Log:

image

EventID: 1026
Source: .NET Runtime

Event message:

Application: Microsoft.EnterpriseManagement.Monitoring.Console.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
   at Microsoft.EnterpriseManagement.Mom.Internal.UI.Console.ConsoleJobExceptionHandler.ExecuteJob(System.ComponentModel.IComponent, System.EventHandler`1<Microsoft.EnterpriseManagement.ConsoleFramework.ConsoleJobEventArgs>, System.Object, Microsoft.EnterpriseManagement.ConsoleFramework.ConsoleJobEventArgs)
   at Microsoft.EnterpriseManagement.ConsoleFramework.ConsoleJobsService.JobThread(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Issue is caused by missing prerequisite files, particularly the ReportViewer prereq. Download and install SQL CLR types and ReportViewer, and relaunch the console, and hey Presto!

Wednesday, January 18, 2017

Quick agent health check script

A long long time ago in a life far far away, I wrote a quick and dirty agent health check script that allowed me to keep an eye on the unhealthy agents in my environments. I updated it over the years, but always kept it as VBScript, which is obviously now a little out of date, since everyone wants to use the far more posh PowerShell. So, here is a PS version.

Update the highlighted bits, save as a ps1 file and be sure to test in your lab before using in production. Script provided without guarantees.

##############################################################################
#
#   SCOM-Agent-healthCheckscript.ps1
#
#    This script retrieves all unhealthy agents from OpsMgr, and pings them.
#
##############################################################################

# Variables

$FromEmail = "<from email address>"
$ToEmail = "<recipient email address>"
$MailServer = "<mail server>"

$ReportDate = Get-Date -format "yyyy-M-dd"

# there should be no need to update the script beyond this point

# Open the content
#$body = @()

$body = "<table><tr><td><b>Server Name</b></td><td><b>Ping Response</b></td></tr>"

# Connect to Operations Manager

Import-module OperationsManager

# Fetch the agent information
$AgentClass = get-SCOMClass -name "Microsoft.SystemCenter.Agent"
$Agents = Get-SCOMMonitoringObject -class:$AgentClass | where {$_.IsAvailable -ne "Success"}

# Set the counters to Zero
$n = 0
$i = 0

# Loop through the unhealthy agents and ping them
foreach ($Agent in $Agents) {
$n = $n+1

   if (test-Connection -ComputerName $Agent -Count 2 -Quiet )
        {
    $Status = "Responds"
         }
         else
         {
      $Status = "Unreachable"
      $i = $i+1
         }

# Status update
Write-Host "$Agent checked"

# Write to the report
$ReportOutput = "<tr><td>$Agent</td><td>$Status</td></tr>"
$body += $ReportOutput
}

$body += "</table>"

# Write-Host "There are $n agents in total and $i not pinging"

$mbody = "<p>There are <b>$n</b> agents in total and <b>$i</b> not pinging</p> $body"


Write-Host “Sending Email”

#Creating a Mail object
     $msg = new-object Net.Mail.MailMessage
    
#Creating SMTP server object
     $smtp = new-object Net.Mail.SmtpClient($mailserver)

#Email structure
$Subject = "SCOM Agent Health Check - $ReportDate"

     $msg.From = $FromEmail
     $msg.ReplyTo = $FromEmail
     $msg.To.Add($ToEmail)
     $msg.subject = $Subject
     $msg.IsBodyHtml = $true
     $msg.body = $mbody

  #Sending email
    $smtp.Send($msg)

#write-host "Email sent"

Related Posts with Thumbnails