PSOL: Get-SNMPDevices

Quick and easy way to get a list of all OpsMgr monitored SNMP devices

Get-MonitoringClass -name 'System.NetworkDevice' | Get-MonitoringObject | Format-Table PathName, DisplayName

Review: Savision LiveMaps v5

The last days I have been looking in to Savision LiveMaps, thought I share some of my thoughts on the product.

My two cents

Maps

So the product is named LiveMaps, it should be good at doing maps… is it? Well, I havn’t seen any product with tight OpsMgr integration that does it better.
You can set almost any picture as a background (vector-based is preferred since they scale up/down best) and then you just drag n’ drop object from OpsMgr on to the map.
A nice feature is that you can create membership rules for every map, so if you are creating a map of a part of your network you can set rules to include every object named XYZ, have an IP-adress of 1.2.3.*… if you are know how to create a group in OpsMgr, it’s basicly the same… with all the options. :-)

Application

Most of the things you can do on application monitoring you can do with OpsMgr Distributed Applications. The best part with doing it in LiveMaps is the placing of objects. In OpsMgr you can’t select that you want to place your database on spot X and service on spot Y. When doing this kind of applications in LiveMaps you can easily set an exact spot for you object and then if you want add an small image, colored box or something nice to give it some more bling. :-)

Network Topologies

When creating network topologies for a large network you should probably use Jalasoft XianIo as well. Today, with a plain vanilla OpsMgr you can’t autocreate relations between devices. So if you have a large network, this will take time… loads of time.
I hope that Savision will post some information on how we can use this to create relations in our own environments without the need of third party products, even with XianIO there are SNMP-enabled devices that XianIO doesn’t cover…

Take a look at this YouTube video: and you understand why you should look in to XianIO Today.

Dashboards

Together with maps, this is the easy way to get project-fundings. :-P
Starting with a map or distributed application, just drag and drop your objects and within seconds you have the dashboard your CIO always wanted. “Economy App – Green”, “HR App – Yellow”, “Mail – Green”… easy to set up, easy to understand.

Notes, suggestions and general thoughts to Savision

Live Maps in OpsMgr

When using large maps it’s hard (well, not hard… just to many clicks) to zoom in/out and then pan around.

Some easier way (than this blogpost) to control the health rollup.
For a OpsMgr admin this shouldn’t be a problem… but we are aiming on having network guys draw the maps and relations between network equipment.

Authoring Console

Where is the export/import button? I want to create my maps in test/dev, export them and then import them to production. Ok, I understand that you need the refering objects GUID when you import a map…
…what if you make it like this: When you export a map you don’t save GUID, instead you save the name of the object. Then, when you import the object you get a wizard that alows you to map saved names against the real object in the new environment.

A “replace this object”-Icon would be nice. When creating larger overviews (say country) I start out by creating the easy dynamic lists for the tier 2 maps (say city). Then, when I have the right amount of information, a background map and so on, I want to replace the dynamic list with a nice map for that city. But today you will loose all connections from and to that city-object on the country map. So… a replace button would be nice.

Missing a global option to set different (default) Sate-icons. I would like to have one for every object with Class X or Class Y.
For instance I want to create Server-icons, Network device-icons and so on. With that option you can remove the image and only use stateicon to describe the equipment.

Missing the option to place the State Icon in the center of the image.

Option to mark the Visible-flag on/off for a folder instead of separate maps.
I know that you can do this by creating a OpsMgr User Role and scope that one… When you have the option for every map/list, why not on folders?

Web

I want to be able to create a Web-url without alerts and the right-click menu, only icons.

An option to grant anonymous access to a single drawing. Say that you want to do a dashboard with your larger applications and publish it on the intranet…

Is it possible to integrate tighter with the OpsMgr Web Console, you do not want to have two consoles for one monitoring solution. Yes, I know that you can work around that by linking in the weburl… It works but it isn’t the nice way to do it.

And please, give some basic support for users not using MSIE.

Licensemodel

How about test/dev-environments? Today the licenses is based on MgmtGroups and most of us have a separate test/dev environment. Ok, you can use the free version but it’s limited to 5 maps and I want my dev environment to reflect the production environment.

Information / Relations

I have been in contact with Savision support, I wanted to know how I can enable the automagic relations-button. Got an answer and they will look in to it.
I want to discover hardware devices, SAN-Switches for instance, how nice wouldn’t it be if LiveMaps could draw the relations to servers for me?


No more secrets…???

After almost 10 years (3 weeks short) at Atea Sweden I’m now leaving the company for an employment on the customer side.
Since I’m not working at a consultant company that sells the kind of solutions I’m blogging about… I have no “restrictions” on what I can blog about.

Hope that I can share more of my scripts, findings and solutions instead of keeping them as a “company secret”.

No more secrets! :-)

On the one hand information wants to be expensive, because it’s so valuable. The right information in the right place just changes your life. On the other hand, information wants to be free, because the cost of getting it out is getting lower and lower all the time. So you have these two fighting against each other.

Thoughtful quote by Stewart Brand at the first Hackers’ Conference back in 1984


ACT filling up your disks?

When you have ACT (The Microsoft Application Compatibility Toolkit) running in your environment you might get disks filled up with XML-files on your ACT-server.

The logprocessor uses those files to populate the database with information. So, when those are processed you do not need them anymore. (If you have a backup of your database…)

So, I did it the easy way, scheduled a powershell command to remove files older than 7 days:

Get-ChildItem D:\ACTLogs -Recurse -Include *.xml* | where {$_.CreationTime -lt (Get-Date).AddDays(-7)} | Remove-Item

If you want a nicer look and feel to your script you can use this instead:

Get-ChildItem D:\ACTLogs -Recurse -Include *.xml* | where {$_.CreationTime -lt (Get-Date).AddDays(-7)} | Sort-Object CreationTime | ForEach-Object {
        Write-Host "Processing: " -ForegroundColor Yellow -NoNewline
        Write-Host $_.FullName -ForegroundColor White -NoNewline

        $span = New-TimeSpan $_.CreationTime $(get-date)
        Write-Host " $($span.Days) days old" -ForegroundColor Yellow -NoNewline

        Remove-Item $_.FullName

        Write-Host " [del]" -ForegroundColor Red
}

SCOM vs OpsMgr

This will not be a post with the technical content you might be used to read on this blog.

In the last 5 years I have been working on “a few” OpsMgr projects with different customers… one thing I have to remind almost every customer of is that they should not use the acronym SCOM for System Center Operations Manager.

Why?
The main reason is the community. Today everyone (well… the most of us) use OpsMgr in writing.
When you search for SCOM you get more hits than a search for OpsMgr, but most of the hits are pointing you to old articles and blogposts.
A few years back the most of us (even Microsoft) used the acronym SCOM, but as I just pointed out… today almost everyone is using OpsMgr.

Ok I’ll use OpsMgr, but what to say?
You probably go nuts if you try to say “System Center Operations Manager” every time…
I have heard a few:
OpsMgr
Ops Manager
Operations Manager
Operations

I probably use Ops Manager the most.

So why this blogpost?
Ehrm… to give you “new guys” an easier way to search for new articles and to give myself an easier way to search for new articles. :-P

So… please, do not write SCOM, write OpsMgr instead.


Manufacturer / Model Collections with hierarchy

The last post made a flat structure of collections with “Manufacturer – Model”, in this post the script creates a hierarchy with (almost) the same collections.


The Model-collections queries are limited to the parent Manufacturer-collection.

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#                                                                                                                            Rikard Ronnkvist / snowland.se
#  Usage:
#   Download and install https://snowland.se/sccm-posh/
#   Save the file as CreateMM-collections-Hierarchy.ps1
#   PS:>.\CreateMM-collections-Hierarchy.ps1 -rootCollectionName "Name Of Some Collection"
#
#  2010-03-24   Rikard Ronnkvist    First snowland.se release
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PARAM (
        [string] $rootCollectionName = $(throw "rootCollectionName required."),
        [string] $hostName = (Get-Content env:computername),
        [switch] $Verbose,
        [Switch] $WhatIf
)

if ($verbose.IsPresent) {
        $VerbosePreference = 'Continue'
} Else {
        $VerbosePreference = 'SilentlyContinue'
}

Import-Module SCCM\SCCM-Functions -Force

Write-Verbose "Connect to SCCM-server $($hostName)"
$sccm = Connect-SCCMServer -HostName $hostName

Write-Host "Get root collection: ""$($rootCollectionName)"""
$rootCollection = Get-SCCMCollection -filter "Name='$($rootCollectionName)'" -sccmserver $sccm
if (!$rootCollection) {
        throw "Cant find ""$($rootCollectionName)"""
}
Write-Host "Found collection: $($rootCollection.CollectionID)"

Function checkAndCreate ($CollectionName, $ParentCollectionID, $wql, $limit = $null) {
        Write-Host "Checking ""$($CollectionName)""" -ForegroundColor Cyan
        $newCollection = Get-SCCMCollection -filter "Name='$($CollectionName)'" -sccmserver $sccm

        if (!$newCollection) {
                if (!$WhatIf.IsPresent) {
                        Write-Host "Creating collection: ""$($CollectionName)"""
                        $newCollection = New-SCCMCollection -name "$($CollectionName)" -SccmServer $sccm -parentCollectionID $ParentCollectionID -refreshDays 1 -Verbose
                } else {
                        Write-Host "What if: Creating collection: ""$($CollectionName)""" -ForegroundColor Red
                }

                if (!$WhatIf.IsPresent) {
                        Write-Verbose "Adding rule with WQL: $wql"
                        Add-SCCMCollectionRule -queryExpression $wql -Server $sccm -collectionID $newCollection.CollectionId -queryRuleName $CollectionName -limitToCollectionId $limit
                } else {
                        Write-Host "What if: Adding collection rule to new collection with wql: $($wql)" -ForegroundColor Red
                }
        } else {
                Write-Host "Found collection ""$($CollectionName)"""
        }

        return $newCollection
}

Write-Host "Lookup Manufacturer and Model"
$Manufacturer = Get-wmiobject -query "SELECT DISTINCT Manufacturer FROM SMS_G_System_COMPUTER_SYSTEM" -computername $Sccm.Machine -namespace $Sccm.Namespace | Sort-Object Manufacturer, Model
$Manufacturer | ForEach-Object {
        $wql = "SELECT * FROM SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Manufacturer = '$($_.Manufacturer)'"
        $ManufacturerCollection = checkAndCreate -collectionName $_.Manufacturer -ParentCollectionID $rootCollection.CollectionId -wql $wql -limit $null

        $Model = Get-wmiobject -query "SELECT DISTINCT Model FROM SMS_G_System_COMPUTER_SYSTEM WHERE Manufacturer = '$($ManufacturerCollection.Name)'" -computername $Sccm.Machine -namespace $Sccm.Namespace | Sort-Object Manufacturer, Model
        $Model | ForEach-Object {
                $wql = "SELECT * FROM SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Model = '$($_.Model)'"
                $ModelCollection = checkAndCreate -collectionName $_.Model -ParentCollectionID $ManufacturerCollection.CollectionId -wql $wql -limit $ManufacturerCollection.CollectionId
        }
}

Manufacturer / Model Collections

You have probably created one or two collections that points to a specific Manufacturer and/or Model.

Well, this script will look in to your SCCM-database and create that kind of collections for you.

First you need my SCCM Module for PowerShell
Then I created a collection named “000 – Manufacturer – Model”
Copy and paste the code below to a file, save it as CreateMM-collections.ps1
Run with at least one param, -rootCollectionName
Example: .\CreateMM-collections.ps1 -rootCollectionName “000 – Manufacturer – Model”

The script support the -WhatIf and -Verbose parameters… might be good to have when testing.

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#                                                                                                                            Rikard Ronnkvist / snowland.se
#  Usage:
#   Download and install https://snowland.se/sccm-posh/
#   Save the file as CreateMM-collections.ps1
#   PS:>.\CreateMM-collections.ps1 -rootCollectionName "Name Of Some Collection"
#
#  2010-03-23   Rikard Ronnkvist    First snowland.se release
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PARAM (
        [string] $rootCollectionName = $(throw "rootCollectionName required."),
        [string] $hostName = (Get-Content env:computername),
        [switch] $Verbose,
        [Switch] $WhatIf
)

if ($verbose.IsPresent) {
        $VerbosePreference = 'Continue'
} Else {
        $VerbosePreference = 'SilentlyContinue'
}

Import-Module SCCM\SCCM-Functions -Force

Write-Verbose "Connect to SCCM-server $($hostName)"
$sccm = Connect-SCCMServer -HostName $hostName

Write-Host "Get root collection: ""$($rootCollectionName)"""
$rootCollection = Get-SCCMCollection -filter "Name='$($rootCollectionName)'" -sccmserver $sccm
if (!$rootCollection) {
        throw "Cant find ""$($rootCollectionName)"""
}
Write-Host "Found collection: $($rootCollection.CollectionID)"

Write-Host "Lookup Manufacturer and Model"
$ManufacturerModel = Get-wmiobject -query "SELECT DISTINCT Manufacturer, Model FROM SMS_G_System_COMPUTER_SYSTEM" -computername $Sccm.Machine -namespace $Sccm.Namespace | Sort-Object Manufacturer, Model
$ManufacturerModel | ForEach-Object {
        $mmCollectionName = "$($_.Manufacturer) - $($_.Model)"
        Write-Host "Checking ""$($mmCollectionName)""" -ForegroundColor Cyan

        $mmCollection = Get-SCCMCollection -filter "Name='$($mmCollectionName)'" -sccmserver $sccm

        if (!$mmCollection) {
                if (!$WhatIf.IsPresent) {
                        Write-Host "Creating collection: ""$($mmCollectionName)"""
                        $newMmCollection = New-SCCMCollection -name "$($mmCollectionName)" -SccmServer $sccm -parentCollectionID $rootCollection.CollectionID -refreshDays 1
                } else {
                        Write-Host "What if: Creating collection: ""$($mmCollectionName)""" -ForegroundColor Red
                }

                $wql = "SELECT * FROM SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.Manufacturer = '$($_.Manufacturer)'  AND SMS_G_System_COMPUTER_SYSTEM.Model = '$($_.Model)'"
                if (!$WhatIf.IsPresent) {
                        Write-Verbose "Adding rule with WQL: $wql"
                        Add-SCCMCollectionRule -queryExpression $wql -Server $sccm -collectionID $newMmCollection.CollectionId -queryRuleName $mmCollectionName
                } else {
                        Write-Host "What if: Adding collection rule to new collection with wql: $($wql)" -ForegroundColor Red
                }
        } else {
                Write-Host "Found collection"
        }
}

SCCM Module for PowerShell

In a post a few days ago I mentioned “some slightly modified functions from Michael Niehaus“.

Well… Why not share them.

Save this as a module, load it and play around.

2010-03-26 – Moved to https://snowland.se/sccm-posh/

Some examples on what you can do:

# List all available SCCM commands
Get-SCCMCommands

# Create an SCCM-Connection to the local server
$sccm = Connect-SCCMServer -Verbose

# Create a new collection with a collection rule
$newCollection = New-SCCMCollection -SccmServer $sccm -name "Some Collection Name" -Verbose
Add-SCCMCollectionRule -Server $sccm -collectionID $newRoot.CollectionId -queryExpression "SELECT * FROM SMS_R_System" -queryRuleName "All Systems" -Verbose

# Count files in the inboxes
$sccm | Get-SCCMInboxes

# Get a package
$MyPackage = Get-SCCMPackage -server $sccm -filter "Name = 'Some Package Name'"

If you have some comments, ideas and things to add… Comment this post or shoot me an .


Scandinavian chars in cmd-files

Got a scriptingquestion from a colleague, wasn’t that easy to find on google.

But with Windows Search I did find an old cmd-script that had exactly that problem sorted out.

So, the question was about scandinavian chars in a cmd-script. Some paths are named with non English letters and when you use them in a script it translates to a strange char instead of the letter.

This works fine:

DEL /F /Q "%USERPROFILE%\Local Settings\Some Directory\*.*"

This doesn’t work since there is a scandinavian letter in the path:

DEL /F /Q "%USERPROFILE%\Lokala inställningar\Some Directory\*.*"

To fix it you need to change codepage, like this:

CHCP 850
DEL /F /Q "%USERPROFILE%\Lokala inställningar\Some Directory\*.*"

You might need to use different codepage depending on the language you are using.

Some more info on MSDN


Add text to images with PowerShell

Been working on some server deployment lately and had some problems with the WinPE… so to not get to confused when using different PE’s to boot up the servers we added some image-information on the background.

Did that in MS Paint… but how fun is that? :-P

Here is a cool function that add some text to a image (Original code from http://www.ravichaganti.com/blog/?p=1012)

Function AddTextToImage {
        # Orignal code from http://www.ravichaganti.com/blog/?p=1012
        [CmdletBinding()]
        PARAM (
                [Parameter(Mandatory=$true)][String] $sourcePath,
                [Parameter(Mandatory=$true)][String] $destPath,
                [Parameter(Mandatory=$true)][String] $Title,
                [Parameter()][String] $Description = $null
        )

        Write-Verbose "Load System.Drawing"
        [Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null

        Write-Verbose "Get the image from $sourcePath"
        $srcImg = [System.Drawing.Image]::FromFile($sourcePath)

        Write-Verbose "Create a bitmap as $destPath"
        $bmpFile = new-object System.Drawing.Bitmap([int]($srcImg.width)),([int]($srcImg.height))

        Write-Verbose "Intialize Graphics"
        $Image = [System.Drawing.Graphics]::FromImage($bmpFile)
        $Image.SmoothingMode = "AntiAlias"

        $Rectangle = New-Object Drawing.Rectangle 0, 0, $srcImg.Width, $srcImg.Height
        $Image.DrawImage($srcImg, $Rectangle, 0, 0, $srcImg.Width, $srcImg.Height, ([Drawing.GraphicsUnit]::Pixel))

        Write-Verbose "Draw title: $Title"
        $Font = new-object System.Drawing.Font("Verdana", 24)
        $Brush = New-Object Drawing.SolidBrush ([System.Drawing.Color]::FromArgb(255, 0, 0,0))
        $Image.DrawString($Title, $Font, $Brush, 10, 10)

        if ($Description -ne $null) {
                Write-Verbose "Draw description: $Description"
                $Font = New-object System.Drawing.Font("Verdana", 12)
                $Brush = New-Object Drawing.SolidBrush ([System.Drawing.Color]::FromArgb(120, 0, 0, 0))
                $Image.DrawString($Description, $Font, $Brush, 10, 50)
        }

        Write-Verbose "Save and close the files"
        $bmpFile.save($destPath, [System.Drawing.Imaging.ImageFormat]::Bmp)
        $bmpFile.Dispose()
        $srcImg.Dispose()
}

With that piece of code and some slightly modified functions from Michael Niehaus you can do some cool stuff…

$taskSequence = "Server Deployment Task Sequence"

Import-Module Misc\Image-Functions.psm1
Import-Module SCCM\SCCM-Functions.psm1

$sccm = Connect-SCCMServer
$taskSequence = Get-TaskSequencePackage -SccmServer $sccm -filter "Name = '$taskSequence'"
$BootImage = Get-BootImagePackage -SccmServer $sccm -filter "PackageID = '$($taskSequence.BootImageID)'"
$DescriptionText = "Version:`t$($BootImage.Version)`nPackageID:`t$($BootImage.PackageID)`n`n$($BootImage.Description)"

AddTextToImage -sourcePath "X:\Path\WinPE-Background-Source.bmp" -destPath "X:\Path\WinPE-Background-To-Inject.bmp" -Title $BootImage.Name -Description $DescriptionText

Shouldn’t be that hard to auto-inject the BMP to the WIM file…


« Previous Page — Next Page »