Automate!

Austrian Blog around optimizing datacenters with Powershell and Azure

PowerShell your ServiceManager & ITAM: Get Hardware Maintenance Expiry Information

No Comments »

Hi All !

There are millions of exampled out there to PowerShell your Service Manager and  i dont want to replicate them. So in this Blog Series i will focus on real world examples people have with Service Manager and Provance (2014 Standard or Enterprise).

The first one is about automatic notification of to-be-expired maintenance agreements.

Lets assume you have Provance 2014 and Hardware Maintenance Agreements with a Start  and End Date. Those agreements have related Assets linked to it and contracts managers defined.

You want to get notified periodically about contract expiration and want to know which assets are affected. The timespan  you want to look into the future is configurable and you have the choice to get a HTML Report as a file or an HTML E-Mail send to the agreement manager.

Below is a picture of the idea which agreements are selected.

Powershell your SCSM Blog

Yellow agreements are reported because they are inside the „DueDate“ timeframe

The script will collect those agreement find the linked computer assets and generate a report similar to  the one below.

MaintExpiryExampleReport

Example Report

Ok, now for the magic behind all this.

1.) The scheduler

As this is programmed in Powershell you can use SMA, SCSM Powershell Workflow or Orchestrator to fire it, i decided to use task scheduler on the workflow server. The reasons for this decision are that task scheduler is available on every Windows Server, its free and simple to configure. If you dont wat to use it, simply use yur favorite powershell integration tool.

2.) The script

As announced here it uses native scsm commandlets and the SCSMPX extension from Kirk Munroe. Use it, extend it as you need it and let me know if you find it useful. I think i have put enough comments into the code so you can understand what each part does. If you have questions let me know.

[codesyntax lang=“powershell“]

[/codesyntax]

With best regards /Roman

 

PowerShell your ServiceManager & ITAM: Get Discovered Computer Information

No Comments »

Hi all !

Lets focus on a simple problem, many Service Manager / ITAM customers probably have. A set of discovered computers by AD/SCCM is imported into the ServiceManager CMDB with more or less useful information. On the other hand there is unstructured ITAM data. So what those many people want is:

Create an Asset for every Computer CI in the CMDB !

Even if this is not best ITAM practice, it is a common question/demand, this blog addresses

The solution can be easily done with the ScsmPX Module on GitHub and a little piece of code. In the files available in the download section you will find the Powershell Script, and the Provance Import Template to allow the creation of Assets with Provance DMP.

[codesyntax lang=“powershell“ lines=“normal“ container=“pre“]

[/codesyntax]

The Import Template uses this CSV and loads the Data as Assets, depending on if its physical Computers or virtual machines. Below find a screenshot of the template:

Import-Template

Screenshot of the Import Template (Provance Data Management)

Finally if you load the data with the Provance DMP you get:

  • Physical Hardware Assets + Assigned User
  • Hardware Catalog Items for Physical Computers + related Vendor
  • Virtual Computer Assets + Assigned Users
  • All assets are linked to CI´s

Way to go and start importing/editing financial data for your assets

Update: Sept 2015: Script now uses Powershell v3 PSObject way of creating arrays

Cheers / Roman

Script and Import Template

PowerShell your ServiceManager & ITAM: Intro

No Comments »

Dear All !

Service Manager has a wide range of customers and many people deploy or use it in operations. All those know that Service Manager needs customization and sometimes also development to fulfill the needs of IT organizations.

This blog is the starting point of a series to manage Service Manager with Powershell.

BORING you might be forced to say – but wait – this series differs from all those tons of other blogs out in the wild by a couple of facts i will explain now.

  1. No SMLets – SMLets are still in Beta and the future is unclear
  2. Leverage ScsmPX Modules. Kirk Munroes´s (the Poshoholic :-))  ScsmPX Module is Open Source, is based on Microsofts SCSM-native Modules and extends them with the functions that are missing.
  3. No SMA, Orchestrator, or other SC products just native PowerShell. We know you can call anything from anywhere so automation is  limitless (SMA,SCOR,SCSM, …) but we want to focus on the basics.
  4. Examples will be based on Service Manager and Provance 2014 ITAM, from what i saw in the field but the examples are open so you will be able to adapt them to your needs.

The first entry will be posted soon, so stay tuned.

R.

Links:

https://kirkmunro.github.io/ScsmPx/

Update #1: I have attached a screenshot sample in PDF of „How to runa powershell script with parameters with task manager“ because the exampled following are based on that and so you have a easy reference for configuring Task Scheduler.

Run a Powershell Script with Paramaters with task Scheduler

Create CSV out of Powershell Data

No Comments »

Hi All !

Recently i had the situation, where there was no SCCM Agent in an environement for specific
reasons, but the customer wanted to use this data to fill up his SCSM Database (Provance Assets in that case). So we had more ore less empty CI´s in the SCSM Database and wanted to fill this up with directly scanned WMI Data.

The result should have a format to be directly used by an SCSM Import Tool.

The Powershell Script queries all Virtual machines in the SCSM Database and gets information from online machines via WMI. This data is then written to a CSV File. Use and have fun.

 # Script to query Online Virtual Machines based on SCSM Data to get Serial Numbers
import-module smlets
$Computers = Get-SCSMCLass Microsoft.windows.Computer$
$VMList = @(Get-SCSMObject $Computers -Filter „IsVirtualMachine -eq ‚true'“)
$Arr = @()
foreach ($VM in $VMList)
    {
        $data = new-object psobject # New Object
        $data | add-member -membertype NoteProperty -Name ComputerName -Value $VM.NetBiosComputerName
        $data | add-Member -membertype NoteProperty -Name SerialNumber -Value (Get-WMIObject -Class „Win32_BIOS“ -Computername $VM.NetBiosComputerName).SerialNumber
        $data | add-Member -membertype NoteProperty -Name OSName -Value (Get-WMIObject -Class „Win32_OperatingSystem“ -Computername $VM.NetBiosComputerName).Caption
        $data | add-Member -membertype NoteProperty -Name Manufacturer -Value (Get-WMIObject -Class „Win32_ComputerSystem“ -Computername $VM.NetBiosComputerName).Manufacturer
        $data | add-Member -membertype NoteProperty -Name Model -Value (Get-WMIObject -Class „Win32_ComputerSystem“ -Computername $VM.NetBiosComputerName).Model
        $Arr += $data
     }
$arr | select -property ComputerName,SerialNumber,OSName,Manufacturer,Model | export-csv -notypeinformation .\Documents\VMSerials.csv
Remove-Module Smlets

The result is a CSV file like this.

„ComputerName“,“SerialNumber“,“OSName“,“Manufacturer“,“Model“
„Server1″,“1111-1111-1111-5431-2407-9700-21″,“Microsoft Windows Server 2012 R2 Standard“,“Microsoft Corporation“,“Virtual Machine“
„Server2″,“2222-2222-2222-7060-4845-5504-27″,“Microsoft Windows Server 2012 R2 Standard“,“Microsoft Corporation“,“Virtual Machine“
„Serern“,“3333-3333-3333-9977-7669-1954-03″,“Microsoft Windows Server 2012 R2 Standard“,“Microsoft Corporation“,“Virtual Machine“
 

Regards / Roman

 

SCSM: Send IncidentInfo by Mail

No Comments »

In our projects to deploy ServiceManager, we often run into the problem that customers want to get Information
from tickets and store it for i.e. searching. Unfortunately, closed Tickets dont show  much information, you cant
get access to attachments neither ActionLog entries.

Reopening them via Powershell/Orchestrator might fire workflows and notifications which causes chaos, so thats
no way to go. What we built here is a solution to get a ticketinformation from a closed ticket by task.

It delivers title/description, ActionLog entries and attachments to a common mailbox, triggerd by a console-task.

SendTicketInfo-Console

The resulting E-Mail:

STI-Result

How to build it

You need:

  • SCSM 2012
  • Orchestrator
  • A central accessible fileshare
  • The Orchestrator Remote Tools installed on a central share
  • Powershell

1.) Enable Powershell remoting on SCOR and SCSM Server

On both machines, open a PS Session as Administrator and enter

and walk through the wizard.

2.) Enable CredSSP authentication on both machines (Client/Server)

This alone helps executing commands remotely, but it runs under the system account,
which cannot access fileshares. To make this possible you have to anable remote
authentication via CrepSSP. More on this here.

Now we can use -Authentication CredSSP in Powershell between this two machines.

 3.) Prepare the promptless script (no password prompt)

Now with Remoting and CredSSP you will still be prompted for a password
which makes no sense in a SCOR script. The solutuion is found here.

First we create a file with an encrypted password.

!!! Importtant !!! You have to create the File with the Orchestrator ServiceAccount Credentials,
so start a powershell session with the Service account and. Otherwiese the file will not
be usable in the .Net Script.

Furthermore the script will only run in a usercontext of the SCOR Service Account
– so forget runbook-testing that part, bcs this will be with the logged on-account
where the username doesnt fit to the Service Account-password file.

read-host -assecurestring | convertfrom-securestring
| out-file \\server\share\password.txt

having this we can use username and password in any authentication mechanism in a powershell script using:

4.)  GetFileAttachments

Anders Bengston has written a Powershell Script which i used to extract file attachments from Incidents.
The original script can be found here. Download it and store it in a location
where everybody has at least read access \\server\share\dir\Get-Fileattachment.ps1

5.) Create a runbook which gets Incident Data

I actually created 2 runbooks, one for getting the incindet data, one for sending the E-Mail.
The runbook is attached as file.

The runbook gets information of the Ticket (Title, Description and AnalystComments) and
stores this as e-Mail BodyText in a temporary Textfile, which is then read to publish it to
the Send-E-Mail Runbook.

STI-Runbook1

This Runbook gets Data from the other runbook and sends out an e-Mail.

STI-Runbook2

6.) Insert the .Net Script

So the script uses the SCOR Service Account, creates a credential Info and then starts a remote-PS Session
(Invoke-Command) to the Service Manager Server to get the file-attachments. They are stored in the ArchiveRootPath.

7.) Start the Runbook remotely

The Orchestrator Remote Tools can start Runbooks by commandline.

After configuring the tools according to the attached documentation, your commandline would be something like this:

The Launcher starts a runbook (read ORT-Doc) according to the preconfigured XML file and passes 2
parameters (ID and Usermail), which come from the „Initialize Data“ Activity.

8.) Create a SCSM Task

The only thing you have to take care here is to paste the Incident ID in the commandline.

STI-Task3

STI-Task2

STI-Task1
Thats basically it. Have fun.

Runbook Files can be found here: SendTicketInfoRunbooks

Roman

Service Request to add user2group with dynamic group manager approval

No Comments »

Hi All !

Since a couple of weeks i wanted to create a Service Request where:

  • The user can add himself to a group
  • The Manager of the group in AD is the approver of the action.

Basically there are solutions out there, but not with up-to-date products and some
workarounds like a seperate database.

One is at http://contoso.se/blog/?p=2872, but as said with Opalis and a Database in the background.

I tried to do everything with native tools (SCSM, SCOR) but had to use 1 little powershell script,

which was inspired by

http://social.technet.microsoft.com/Forums/en-US/systemcenterservicemanager/thread/d31d7fe4-4dee-4345-a2b2-6bcea9a9e1d2

To make this possible, its important that the Runbook Server, executing the Powershell Script hat the
Remote Execution environement in place which i explained here.

Find the appripriate files in the AddUser2Group Files.

So here´s the video Part 1, enjoy and i hope you can use it in your environement as well.

Part 2 of the Video can be found here.

All the best trying this in your environement – Roman
Roman Stadlmair
 

Prepare local and remote Powershell environement for Service Manager 2012

No Comments »

Hi All !

SMLets and Powershell are an important part of a flexible Service Manager Environement.
With the ability to fire Powershell scripts remotely, it makes sense to install Powershell on all
management servers and on the Orchestrator Server as well.

There are a couple of How-To´s on the web, especially this one but no actual one for SCSM2012
and SMLets Beta4, which are the current releases.

Here is the Stp-by-step guide how to do this.

Lets assume you want to prepare your DWH Management Server for SMlets

1.) Download SMLets from the link here.

2.) Install the SMLets. The install Location is: C:\Program Files\Common Files\SMLets

3.) Open a Powershell Command Interface as Administrator and set the Execution-Policy to „Unrestricted“

4.) Copy 2 DLL´s from \\%SCSMMGMTServername%\c$\Program Files\Microsoft System Center 2012\
Service Manager\SDK Binaries to a local folder on the DWH Server i.e c:\transfer

5.) Open a CMD Command shell with Administrator rights and and enter the following command

6.) Change the file SMLets.psm1 in c:\Program Files\Common Files\SMLets
(be  aware that the 2010 in the reg-Key is no typo !!)

This script shows the beginning of the files with the changes in RED.

If the scripts fails to execute, add a global variable

at the beginning

7.) Now run the script, i.e. in the Powershell ISE Windows

8.) Start getting access to your SCSM Server by trying out:

import-module SMLets Get-SCSMWhoAmI Get-SCSMIncident

Have fun ! Roman