Citrix – Change wallpaper with powershell on a Citrix published desktop or Microsoft remote desktop

Summary

You publish Desktops with a Citrix XenApp/XenDesktop or Microsoft Remote Desktop Services (RDS) environment and restrict your users with GPO to change any display settings, but your users want to change the background image/wallpaper?

Here is a method with powershell, that gives your users the flexibility back to upload an own  background image/wallpapers or choose from three default background wallpapers.

Description

The powershell script and the required images are saved in a subfolder in the program files path and can be started through a start menu or desktop shortcut. The powershell script generate a user friendly GUI that allows the users to upload an own image/wallpaper or choose from three different and pre- defined wallpapers.

You can find the complete Script and image structure here => SetWallpaper_20171004.

OK, let’s start…

First you must declare some variables and values to understand and use the following powershell script.

  • Location of the powershell script (script line 32) $ProgramPath (In my scenario, the powershell script and the images are saved in the program files path.)
  • Upload location for the own wallpaper (script line 33) $ProfilePath (Path to save the uploaded wallpaper image and the generated base64 thumbnail.)
  • Max file length for upload (script line 34) $MaxFileLength (restrict file size for upload.)
  • Wallpaper icon (script line 37) $WallpaperIcon (Filename of the icon, that show in the upper left corner of the powershell GUI.)
  • Wallpaper style (script line 38) $WallpaperStyle (Stretch or center the wallpaper)
  • Name of wallpaper file (script line 39-41) $WallpaperPict1, $WallpaperPict2, $WallpaperPict3 (The names of the wallpaper image files)

    The Features of the powershell script

  • Three different pre-defined background wallpapers to choose
  • Upload and set own background image/wallpaper
  • Automatically generate a thumbnail from own uploaded image/wallpaper as base64 file in the roaming user profile (Why a base64 file; The thumbnail must be changed while the powershell form are active and loaded. A picture are locked by the loaded powershell form and cannot be deleted or changed, but a base64 file can be deleted and changed when the powershell form are loaded.)
  • File size limitation for own uploaded image/wallpaper
  • Graphical user interface (GUI)
  • The powershell script read the actual session resolution and set the most fitting image/wallpaper from the source files

The GUI

The GUI are simple and easy to understand, that’s important for all users. 😉

Start powershell GUI over desktop or start menu shortcut.
Powershell GUI overview.

 Assistant to upload own background image/wallpaper.
 
Automatically generate a thumbnail from own uploaded image/wallpaper as base64 file in the roaming user profile.
 
 Thumbnail preview and set own background image/wallpaper.
 File size limitation for own uploaded image/wallpaper (the default file size upload limitation are 1MB and can be changed in the powershell script variables).
 Three different pre-defined background wallpapers to choose.

The powershell script

The script set your own uploaded or one of the three pre-defined background images/wallpaper on a Citrix published Desktop or Microsoft remote desktop.

SCOM – Add additional informations to alert custom fields and notifications from extended class

Summary

You have built extended classes in SCOM and fill the extended classes with data from your own built attributes? Now you want to use this data in custom fields from alerts und notifications?

Here is a method with powershell and SCORCH to add data from extended classes to custom fields in SCOM and use this data for custom notifications and other cool stuff.

Description

The script running in my scenario trough a SCORCH runbook. With small changes, the script will also run without SCORCH on a command channel notification.

First you musst declare some variables and values to understand and use the following powershell script.

  • Alert ID (script line 11) $alertID (In my scenario, the SCORCH runbook run only when a specific alert are come up in SCOM.)
  • SCOM management server (script line 14) $hostname (The hostname in FQDN from any of your SCOM management server)
  • Property name of your extended class (script line 60) $className (The display name of your extended class)
  • Value names from your extended class (script lines 61 – 63) $classAttr1, $classAttr2, $classAttr3 (How you can find the value names of your extended class with powershell, is explained in this post.)

The SCORCH runbook

 

The SCORCH runbook are pretty easy to create.

 Create a “Monitor Alert” pattern, with following settings.

Set the filter for “Monitor Alert” to the SCOM (Source) attribute “MonitorObjectDisplayName” or something else that you like to filter from the alert.

Create a “Run .Net Script” pattern and paste the powershell script.

Link the string from the variable $alertID to the published data filed “ID” from the pattern “Monitor Alert”.

Add following string data to the “Published Data” section, to pass the values in to the linked runbook pattern.

Create an “Update SCOM Alert” pattern with the following data.

Link the property “Alert ID” to the published data filed “ID” from the pattern “Monitor Alert”.

Add fields to the properties area that you want to fill with the runbook. In my scenario I fill the custom fields 1-3.

Link the selected fields to the passed variables from the “Run .Net Script” pattern.

Link the created patterns and voilà, the runbook are complete.

The powershell script

The script collect the values from your extended class and write the values in the custom fields to the original alert. (How you can find the value names of your extended class with powershell, is explained in this post.)

EventLog entry
The powershell script  create on line 26 an Event Log entry on the SCOM management server, to check whether the runbook was started. When you dont need this, comment it out.

Result

When the triggered alert shows up in SCOM the created runbook will run and add the values in the custom fields.

Important to know: When you have a lot of data in your extended class, the powershell script take a little bit longer then thought. If the values in notifications are needed, configure the delay for sending the notification to 1 minute.

If the runbook has updated the alert, the “Last Modified By” data switch from System to the SCORCH service account.

Now the custom fields are filled up with the values from your extended class.

SCOM – Get values from your own built extended class with powershell

Summary

You want show or use values from your own extended classes in SCOM with powershell?

Yes you can, this is possible with the following powershell commands.

Description

First you must declare your extended class. In my scenario I take the SCOM class “Windows Computer”. The new extended class are named “Windows Computer Extended Attributes”. Now, I filled up the extended class with a lot of data from monitored Windows and Linux computers.  As example; Server function, server type, server team membership and a lot of other important data from registry and WMI. You can now filter, sort and group the monitored objects dynamically in SCOM with the data from the extended class.

Also, you can get the values with powershell and create some other great scripts.

The powershell commands

To get the SCOM class instance (extended class) you must declare first the extended SCOM class.

Now you can get the SCOM class instance (extended class). The command “Get-SCOMClassInstance” shows a large amount of data. I restrict the result with a monitored object, in this case I take a monitored Windows server. The Displayname must match exactly the Displayname from the monitored object, in my case the FQDN “hostname.domain.com”.

To figure out the value names to be used, you can export the SCOM class instance to a text file or something else.

In the exported List, you can find the values that you need. You can see default values from the base class that you extended and the own values (imported attributes).


The following value names are relevant to continue with the powershell script. The value names in your own extended class have for all monitored objects the same UID.

  • Server function:
    [Typec3a7a87fba9948b2bccc46a3ea47fe9e].AttributeDiscoveryGeneratedByUI843f4fa102e24b2791be3ccce9441e92
  • Server type:
    [Type1a1021e9c2c6410dace6e73c3f95cb66].AttributeDiscoveryGeneratedByUIc16fe093d54846159a5f620545143277
  • Active Directory Site:
    [Microsoft.Windows.Computer].ActiveDirectorySite

To get the values use the subsequent powershell command

Result

The script displays the following output. You can use this output to fill the custom fields from SCOM alerts and create some custom notifications.