For relaxing times, make it Umeå times.

Here’s a function dedicated to my friends in Umeå who attended my 8-day PowerShell Course,
special thanks to Roger!

 

You can display the types available by writing:

 

 

The example above displays the different types available.

 

If you want to search for a specific type you can simply write:

 

 

You can also search by name as shown below.

 

 

And here’s an example of pipe:ing the objects to Out-GridView.

 

 

Click here to download the function.

 

Rating 4.67 out of 5
[?]

PowerShell & SCCM – Packages

You can retrieve a specific Package in SCCM through the SMS_Package class. In the example below we use a WQL statement to retrieve a Package where the Name is equal to “Adobe Reader”.

PS > Get-WmiObject -Namespace "root\SMS\Site_LAB" `
>> -Query "Select * from SMS_Package WHERE Name = 'Adobe Reader'"

__GENUS                    : 2
__CLASS                    : SMS_Package
__SUPERCLASS               : SMS_PackageBaseclass
__DYNASTY                  : SMS_BaseClass
__RELPATH                  : SMS_Package.PackageID="LAB00016"
__PROPERTY_COUNT           : 38
__DERIVATION               : {SMS_PackageBaseclass, SMS_BaseClass}
__SERVER                   : SCCM
__NAMESPACE                : root\SMS\Site_LAB
__PATH                     : \\SCCM\root\SMS\Site_LAB:SMS_Package.PackageID="LAB00016"
ActionInProgress           : 0
AlternateContentProviders  :
Description                :
ExtendedData               :
ExtendedDataSize           : 0
ForcedDisconnectDelay      : 5
ForcedDisconnectEnabled    : False
ForcedDisconnectNumRetries : 2
Icon                       :
IconSize                   : 0
IgnoreAddressSchedule      : False
ISVData                    :
ISVDataSize                : 0
Language                   : English
LastRefreshTime            : 20100926161618.000000+***
Manufacturer               :
MIFFilename                :
MIFName                    :
MIFPublisher               :
MIFVersion                 :
Name                       : Adobe Reader
PackageID                  : LAB00016
PackageType                : 0
PkgFlags                   : 0
PkgSourceFlag              : 2
PkgSourcePath              : \\sccm\Sources\Applications\Adobe Reader 9
PreferredAddressType       :
Priority                   : 2
RefreshPkgSourceFlag       : False
RefreshSchedule            :
ShareName                  :
ShareType                  : 1
SourceDate                 : 20100926161610.000000+***
SourceSite                 : LAB
SourceVersion              : 3
StoredPkgPath              :
StoredPkgVersion           : 0
Version                    : 9

As you can see, a package contains alot of useful information. We can also store the instance in a variable as shown below.

PS > $pkgAdobe = Get-WmiObject -Namespace "root\SMS\Site_LAB" `
>> -Query "Select * from SMS_Package WHERE Name = 'Adobe Reader'"

If we want to display specific properties we can use the Select-Object cmdlet.

PS > $pkgAdobe | Select-Object -Property Name, Description, Version |
>> Format-Table -AutoSize

Name         Description Version
----         ----------- -------
Adobe Reader             9

In the example above we use Select-Object to display the Name, Description and Version properties. Notice that the Description property is empty. Let’s go ahead and change the description using Windows PowerShell.

PS > $pkgAdobe.Description = "PowerShell Rocks"
PS > $pkgAdobe.Put()

Path          : \\localhost\root\SMS\Site_LAB:SMS_Package.PackageID="LAB00016"
RelativePath  : SMS_Package.PackageID="LAB00016"
Server        : localhost
NamespacePath : root\SMS\Site_LAB
ClassName     : SMS_Package
IsClass       : False
IsInstance    : True
IsSingleton   : False

In the example above we set the description to “PowerShell Rocks” and call the put() method to commit the changes on the package. If we Select the Description property we’ll see that its changed.

PS > $pkgAdobe | Select-Object -Property Name, Description, Version |
>> Format-Table -AutoSize

Name         Description      Version
----         -----------      -------
Adobe Reader PowerShell Rocks 9

Apart from displaying and modifying Packages in SCCM we can also create new Packages using Windows PowerShell. To achieve this we will use the Set-WmiInstance cmdlet. The Cmdlet requires a hashtable containing the properties and values that we want to use when creating a new package. First let’s see how we can create a hashtable:

PS > $arguments = @{Name = "Windows PowerShell";
>> Description = "Worlds Coolest Product";
>> Version = "2.0";
>> Language = "English";
>> PackageType = 0;
>> PkgSourceFlag = 2;
>> PkgSourcePath = "\\sccm\sources\Applications\PowerShell"
>> }

In the example above we specify that the Name of our new package should be “Windows PowerShell”, next we set the Description to “2.0″ and the Language to “English”. We also set the PackageType to 0 – which indicates that its a regular software distribution package and PkgSourceFlag to 2 – which indicates that the Package takes source files directly from the source without compression. Finally we set point the PkgSourcePath to the location of the actual files.

If we type $arguments the hashtable is displayed.

PS > $arguments

Name                           Value
----                           -----
Name                           Windows PowerShell
PkgSourcePath                  \\sccm\sources\Applications\PowerShell
Language                       English
Version                        2.0
Description                    Worlds Coolest Product
PackageType                    0
PkgSourceFlag                  2

With the HashTable in place we can go ahead and create a new package using the Set-WmiInstance cmdlet as shown below.

PS > $newPackage = Set-WmiInstance -class SMS_Package `
>> -arguments $arguments -namespace "root\SMS\Site_LAB"

Pretty cool. If we pipe the variable to the Select-Object cmdlet and display the Name, Description and PackageID you’ll notice that PackageID is empty.

PS > $newPackage | Select-Object Name, Description, PackageID

Name                                    Description                             PackageID
----                                    -----------                             ---------
Windows PowerShell                      Worlds Coolest Product

To generate a PackageID, the instance object needs to be called, a simple way to do this is to pipe the object to the Format-List cmdlet as shown below.

PS > $newPackage | Format-List | Out-Null

If we select the PackageID now an ID will have been generated.

PS > $newPackage | Select-Object Name, Description, PackageID

Name                                    Description                             PackageID
----                                    -----------                             ---------
Windows PowerShell                      Worlds Coolest Product                  LAB00024

When we create a new Package it’s placed directly under “Packages”.

If we want to move the package to a specific folder we use the SMS_ObjectContainerItem class. First we retrieve the “Folder” that we want to place the package in using the SMS_ObjectContainerNode class. In the WQL statement we specify that the container name is equal to “Applications” and that the ObjectType is equal to 2. Setting the ObjectType to “2″ indicates that the object placed in the container will be of the type SMS_Package.

PS > $containerNode = Get-WmiObject -Namespace "root\SMS\Site_LAB" `
>> -Query "Select * from SMS_ObjectContainerNode WHERE Name = 'Applications' AND ObjectType = '2'"
PS > $containerNode

__GENUS               : 2
__CLASS               : SMS_ObjectContainerNode
__SUPERCLASS          : SMS_BaseClass
__DYNASTY             : SMS_BaseClass
__RELPATH             : SMS_ObjectContainerNode.ContainerNod
__PROPERTY_COUNT      : 9
__DERIVATION          : {SMS_BaseClass}
__SERVER              : SCCM
__NAMESPACE           : root\SMS\Site_LAB
__PATH                : \\SCCM\root\SMS\Site_LAB:SMS_ObjectC
ContainerNodeID       : 11
FolderFlags           : 0
FolderGuid            : 32538291-DAB7-4E9C-92F4-58CAE9B641C1
Name                  : Applications
ObjectType            : 2
ParentContainerNodeID : 0
SearchFolder          : False
SearchString          :
SourceSite            : LAB

Next we build up a HashTable containing the Property Names and Values that we want to use. In this example we use InstanceKey and set the value to the PackageID, ObjectType points to “2″ and finally we set the COntainerNodeID to the COntainerNodes ID.

PS > $arguments = @{
>> InstanceKey = $newPackage.PackageID;
>> ObjectType = 2;
>> ContainerNodeID = $containerNode.ContainerNodeID
>> }

PS > $arguments

Name                           Value
----                           -----
ObjectType                     2
InstanceKey                    LAB00024
ContainerNodeID                11

Finally we use the SMS_ObjectContainerItem class to move the package as demonstrated below.

PS > Set-WmiInstance -Class SMS_ObjectContainerItem `
>> -arguments $arguments -namespace "root\SMS\Site_LAB"

__GENUS          : 2
__CLASS          : SMS_ObjectContainerItem
__SUPERCLASS     : SMS_BaseClass
__DYNASTY        : SMS_BaseClass
__RELPATH        : SMS_ObjectContainerItem.MemberID=137
__PROPERTY_COUNT : 6
__DERIVATION     : {SMS_BaseClass}
__SERVER         : SCCM
__NAMESPACE      : root\SMS\Site_LAB
__PATH           : \\SCCM\root\SMS\Site_LAB:SMS_ObjectContainerItem.MemberID=137
ContainerNodeID  : 11
InstanceKey      : LAB00024
MemberGuid       : 06032D6C-6426-411E-912F-462DF35D2ADE
MemberID         : 137
ObjectType       : 2
SourceSite       : LAB

If we take a look in the Configuration Manager Console we’ll see that the Package is moved to the “Applications” folder.

In the next post we’ll see how to work with Programs using Windows PowerShell.

Rating 4.00 out of 5
[?]

#SEF09

First of all I would like o thank all the great people that attended the SharePoint and Exchange Forum 2009 here in Stockholm, Sweden.
Special Thanks to Göran Husman, Everyone at Humandata and all sponsors. Great work!

The international Speakers included Joel Oleson, Eric Shupps, Todd Klindt, Steve Smith and Penny Coventry.
On the Swedish team we got some great sessions from Wictor Wilén, Tobias Zimmergren and, of course, Göran Husman.

My session on SharePoint & PowerShell went well.. almost. The night before my presentation I decided to run through all my code examples one last time, which resultet in a USB-Disc crash. Unlucky for me was that my VMWare was stored on the USB-Disc.
So after half an hour of panic, 3 hours of installation and 1 hour of testing i finally got everything in place, just in time to get my morning coffee and head off to SEF. Anyway, you can download my presentation here or on www.seforum.se

Hope to see all y’all next year!

Rating 4.00 out of 5
[?]

StarTrek and PowerShell:TNG

So I’ve been watching a couple of episodes from ST:TNG Season 6 between PowerShelling. At first i thought I had been sitting in front of my computer a little to long..

Anyway, the image from the episode menu says it all!! The USS Enterprise (NCC-1701-D) is obviously powered by: PowerShell

startrek01

Rating 3.00 out of 5
[?]