<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PowerShell.cz &#187; SMS</title>
	<atom:link href="http://powershell.cz/category/sms/feed/" rel="self" type="application/rss+xml" />
	<link>http://powershell.cz</link>
	<description>Get-World &#124; ConvertTo-PowerShell</description>
	<lastBuildDate>Mon, 07 May 2012 15:09:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Find path to specific node in SMS console</title>
		<link>http://powershell.cz/2011/01/12/find-path-in-console/</link>
		<comments>http://powershell.cz/2011/01/12/find-path-in-console/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 21:25:43 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[SMS]]></category>
		<category><![CDATA[MMC]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=45</guid>
		<description><![CDATA[Have you ever heard this: “Hey, someone is on holiday so please take care of his work. I need to find info about specific (collection&#124;package&#124;advertisement). Can you please send it to me?” Sometimes it could be a nightmare. Especially if you are looking for collection named This test is what I am looking for and <a href="http://powershell.cz/2011/01/12/find-path-in-console/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Have you ever heard this: “Hey, someone is on holiday so please take care of his work. I need to find info about specific (collection|package|advertisement). Can you please send it to me?” Sometimes it could be a nightmare. Especially if you are looking for collection named <em>This test is what I am looking for</em> and the structure looks like:</p>
<p><a href="http://www.powershell.cz/images/4d44a9373539_123AB/image.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.powershell.cz/images/4d44a9373539_123AB/image_thumb.png" border="0" alt="image" width="244" height="100" /></a></p>
<p>Not so funny. Just for this case I created small tool.</p>
<p><strong>Note:</strong> Actually I have two separate tools which I want to merge to one. First is written in C# and the screenshot is taken from this one.</p>
<p><a href="http://www.powershell.cz/images/4d44a9373539_123AB/image_3.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.powershell.cz/images/4d44a9373539_123AB/image_thumb_3.png" border="0" alt="image" width="258" height="300" /></a></p>
<p>It’s now working only for collections and you can filter out collections live – as you are writing requested name to filter field. Second are just functions in PowerShell and I use them for queries against IDs of packages and advertisements. I will talk only about scripts in this article.</p>
<p><strong>WMI behind the code</strong></p>
<p>For work with hierarchy in SMS admin console there are two useful classes: <a href="http://msdn.microsoft.com/en-us/library/cc144997.aspx">SMS_ObjectContainerItem</a> and <a href="http://msdn.microsoft.com/en-us/library/cc145264.aspx">SMS_ObjectContainerNode</a> (based on SDK it looks a bit different for SMS2003 and SCCM2007 – of course as it uses different MMC version &#8211; so I pointed to newer version – even the script below works with SMS). This code can’t be used for collections as they used different method for storing it’s hierarchy (which is clear if you will think how it works). More info related to collections can be found in <a href="http://msdn.microsoft.com/en-us/library/cc145320.aspx">SMS_Collection</a> and <a href="http://msdn.microsoft.com/en-us/library/cc144508.aspx">SMS_CollectToSubCollect</a> MSDN articles.</p>
<p><strong>Get-SMSConsolePath</strong></p>
<p>This is the entry point to functionality. It accepts ID of package or advertisement to look for.</p>
<pre style="width: 105.03%; height: 799px;"><span style="color: #0000ff;">function</span><span style="color: #000000;"> Get-SMSConsolePath
</span><span style="color: #008000;">&lt;#</span><span style="color: #008000;">
.SYNOPSIS
    Displays path in SMS Console.

.DESCRIPTION
    For given SMS object (package or advertisement) shows full path to this object as it's in SMS Console.

.PARAMETER id
    Id of the object to check

.EXAMPLE
    Get-SMSConsolePath tst00123
    Packages/Test/Testing package
</span><span style="color: #008000;">#&gt;</span><span style="color: #000000;">

{
    </span><span style="color: #0000ff;">param</span><span style="color: #000000;"> (
         [Parameter(
            Mandatory</span><span style="color: #ff0000;">=</span><span style="color: #800080;">$true</span><span style="color: #000000;">,
            ValueFromPipeline</span><span style="color: #ff0000;">=</span><span style="color: #800080;">$true</span><span style="color: #000000;">,
            ValueFromPipelineByPropertyName</span><span style="color: #ff0000;">=</span><span style="color: #800080;">$true</span><span style="color: #000000;">
        )]
        [ValidatePattern(</span><span style="color: #800000;">"</span><span style="color: #800000;">tst[02]0[a-f0-9]{3}</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
        [</span><span style="color: #008080;">string</span><span style="color: #000000;">]
        </span><span style="color: #800080;">$id</span><span style="color: #000000;">
    )    

    </span><span style="color: #0000ff;">BEGIN</span><span style="color: #000000;">
    {
        </span><span style="color: #800080;">$Script:ocn</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-weight: bold;">Get-WmiObject</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-ComputerName</span><span style="color: #000000;"> </span><span style="color: #800080;">$Global:SMSServer</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Namespace</span><span style="color: #000000;"> </span><span style="color: #800080;">$Global:SMSWmiNamespace</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-weight: bold;">`</span><span style="color: #000000;">
            </span><span style="font-style: italic; color: #5f9ea0;">-Class</span><span style="color: #000000;"> </span><span style="color: #800000;">SMS_ObjectContainerNode</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Filter</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">ObjectType IN (2,3)</span><span style="color: #800000;">"</span><span style="color: #000000;"> |
            </span><span style="color: #5f9ea0; font-weight: bold;">Select</span><span style="color: #000000;"> ContainerNodeID, Name, ObjectType, </span><span style="color: #800000;">ParentContainerNodeID</span><span style="color: #000000;">
    }

    </span><span style="color: #0000ff;">PROCESS</span><span style="color: #000000;">
    {
        </span><span style="color: #800080;">$Script:SMSConsolePath</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">""</span><span style="color: #000000;">
        </span><span style="color: #800080;">$Script:SMSConsoleItem</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">""</span><span style="color: #000000;">
        </span><span style="color: #800080;">$container</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> Get-SMSConsoleContainer </span><span style="color: #800080;">$id</span><span style="color: #000000;">

        Get-SMSConsoleParent -currNode </span><span style="color: #800080;">$container</span><span style="color: #000000;">
        </span><span style="color: #5f9ea0; font-weight: bold;">Write-Host</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">$Script:SMSConsolePath$Script:SMSConsoleItem</span><span style="color: #800000;">"</span><span style="color: #000000;">
    }

    </span><span style="color: #0000ff;">END</span><span style="color: #000000;">
    {
        </span><span style="color: #5f9ea0; font-weight: bold;">Remove-Variable</span><span style="color: #000000;"> </span><span style="color: #800000;">ocn</span><span style="color: #000000;">            </span><span style="font-style: italic; color: #5f9ea0;">-Scope</span><span style="color: #000000;"> </span><span style="color: #800000;">Script</span><span style="color: #000000;">
        </span><span style="color: #5f9ea0; font-weight: bold;">Remove-Variable</span><span style="color: #000000;"> </span><span style="color: #800000;">SMSConsolePath</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Scope</span><span style="color: #000000;"> </span><span style="color: #800000;">Script</span><span style="color: #000000;">
        </span><span style="color: #5f9ea0; font-weight: bold;">Remove-Variable</span><span style="color: #000000;"> </span><span style="color: #800000;">SMSConsoleItem</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Scope</span><span style="color: #000000;"> </span><span style="color: #800000;">Script</span><span style="color: #000000;">
    }
}</span></pre>
<p>You see that in begin section I load data from <a href="http://msdn.microsoft.com/en-us/library/cc145264.aspx">SMS_ObjectContainerNode</a> and store it for future use. I am filtering the results to have just data for packages and advertisements (ObjectType=2,3). Then call two other support functions in process part and will remove some variables at the end.</p>
<p><strong>Get-SMSConsoleContainer</strong></p>
<p>This is the part where I’ll check actual name of the package/advertisement. I will receive it by linking result from <a href="http://msdn.microsoft.com/en-us/library/cc144997.aspx">SMS_ObjectContainerItem</a> class and respective class of <a href="http://msdn.microsoft.com/en-us/library/cc144959.aspx">SMS_Package</a> or <a href="http://msdn.microsoft.com/en-us/library/cc146108.aspx">SMS_Advertisement</a>.</p>
<pre style="width: 105.16%; height: 569px;"><span style="color: #0000ff;">function</span><span style="color: #000000;"> </span><span style="color: #5f9ea0;">Get-SMSConsoleContainer</span><span style="color: #000000;">
{
</span><span style="color: #008000;">&lt;#</span><span style="color: #008000;">
.SYNOPSIS
    Returns containerID for given object.

.DESCRIPTION
    For given object (based on ID) return its containerID.
</span><span style="color: #008000;">#&gt;</span><span style="color: #000000;">    

    </span><span style="color: #0000ff;">param</span><span style="color: #000000;"> (
        </span><span style="color: #800080;">$id</span><span style="color: #000000;">
    )

    </span><span style="color: #800080;">$filter</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">InstanceKey = '</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #ff0000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">$id</span><span style="color: #000000;"> </span><span style="color: #ff0000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">' AND ObjectType IN (2,3)</span><span style="color: #800000;">"</span><span style="color: #000000;">
    </span><span style="color: #800080;">$tmp</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-weight: bold;">Get-WmiObject</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-ComputerName</span><span style="color: #000000;"> </span><span style="color: #800080;">$Global:SMSServer</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Namespace</span><span style="color: #000000;"> </span><span style="color: #800080;">$Global:SMSWmiNamespace</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-weight: bold;">`</span><span style="color: #000000;">
        </span><span style="font-style: italic; color: #5f9ea0;">-Class</span><span style="color: #000000;"> </span><span style="color: #800000;">SMS_ObjectContainerItem</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Filter</span><span style="color: #000000;"> </span><span style="color: #800080;">$filter</span><span style="color: #000000;"> |
        </span><span style="color: #5f9ea0; font-weight: bold;">Select</span><span style="color: #000000;"> ContainerNodeID, InstanceKey, </span><span style="color: #800000;">ObjectType</span><span style="color: #000000;">

    </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ($(</span><span style="color: #800080;">$tmp</span><span style="color: #000000;">.ObjectType) </span><span style="color: #ff0000;">-eq</span><span style="color: #000000;"> </span><span style="color: #800000;">'</span><span style="color: #800000;">2</span><span style="color: #800000;">'</span><span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$Script:SMSConsolePath</span><span style="color: #000000;"> </span><span style="color: #ff0000;">+=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">Packages</span><span style="color: #800000;">"</span><span style="color: #000000;">
        </span><span style="color: #800080;">$filter</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">PackageID = '</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #ff0000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">$tmp</span><span style="color: #000000;">.InstanceKey </span><span style="color: #ff0000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">'</span><span style="color: #800000;">"</span><span style="color: #000000;">
        </span><span style="color: #800080;">$Script:SMSConsoleItem</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> (</span><span style="color: #5f9ea0; font-weight: bold;">Get-WmiObject</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-ComputerName</span><span style="color: #000000;"> </span><span style="color: #800080;">$Global:SMSServer</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Namespace</span><span style="color: #000000;"> </span><span style="color: #800080;">$Global:SMSWmiNamespace</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-weight: bold;">`</span><span style="color: #000000;">
            </span><span style="font-style: italic; color: #5f9ea0;">-Class</span><span style="color: #000000;"> </span><span style="color: #800000;">SMS_Package</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Filter</span><span style="color: #000000;"> </span><span style="color: #800080;">$filter</span><span style="color: #000000;">).Name
        </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> $(</span><span style="color: #800080;">$tmp</span><span style="color: #000000;">.ContainerNodeID)
    }
    </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
    {
        </span><span style="color: #800080;">$Script:SMSConsolePath</span><span style="color: #000000;"> </span><span style="color: #ff0000;">+=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">Advertisements</span><span style="color: #800000;">"</span><span style="color: #000000;">
        </span><span style="color: #800080;">$filter</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">AdvertisementID = '</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #ff0000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">$tmp</span><span style="color: #000000;">.InstanceKey </span><span style="color: #ff0000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">'</span><span style="color: #800000;">"</span><span style="color: #000000;">
        </span><span style="color: #800080;">$Script:SMSConsoleItem</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> (</span><span style="color: #5f9ea0; font-weight: bold;">Get-WmiObject</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-ComputerName</span><span style="color: #000000;"> </span><span style="color: #800080;">$Global:SMSServer</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Namespace</span><span style="color: #000000;"> </span><span style="color: #800080;">$Global:SMSWmiNamespace</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-weight: bold;">`</span><span style="color: #000000;">
            </span><span style="font-style: italic; color: #5f9ea0;">-Class</span><span style="color: #000000;"> </span><span style="color: #800000;">SMS_Advertisement</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Filter</span><span style="color: #000000;"> </span><span style="color: #800080;">$filter</span><span style="color: #000000;">).AdvertisementName
        </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> $(</span><span style="color: #800080;">$tmp</span><span style="color: #000000;">.ContainerNodeID)
    }
}</span></pre>
<p><strong>Get-SMSConsoleParent</strong></p>
<p>And this is the function which actually resolves parent names. It works recursively from bottom to root folder in console. It uses data stored in <em>$ocn</em> variable and creates final string.</p>
<pre style="width: 103%; height: 337px;"><span style="color: #0000ff;">function</span><span style="color: #000000;"> </span><span style="color: #5f9ea0;">Get-SMSConsoleParent</span><span style="color: #000000;">
{
</span><span style="color: #008000;">&lt;#</span><span style="color: #008000;">
.SYNOPSIS
    Returns parent of given object.

.DESCRIPTION
    For current node return it's parent. Used for recursion.
</span><span style="color: #008000;">#&gt;</span><span style="color: #000000;">
    </span><span style="color: #0000ff;">param</span><span style="color: #000000;"> (
        </span><span style="color: #800080;">$currNode</span><span style="color: #000000;">
    )

    </span><span style="color: #800080;">$parNode</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> (</span><span style="color: #800080;">$Script:ocn</span><span style="color: #000000;"> |? {</span><span style="color: #800080;">$_</span><span style="color: #000000;">.ContainerNodeID </span><span style="color: #ff0000;">-eq</span><span style="color: #000000;"> </span><span style="color: #800080;">$currNode</span><span style="color: #000000;">}).parentContainerNodeID

    </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (</span><span style="color: #800080;">$parNode</span><span style="color: #000000;"> </span><span style="color: #ff0000;">-ge</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">)
    {
        Get-SMSConsoleParent </span><span style="color: #800080;">$parNode</span><span style="color: #000000;">
    }
    </span><span style="color: #800080;">$Script:SMSConsolePath</span><span style="color: #000000;"> </span><span style="color: #ff0000;">+=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">$(($Script:ocn |? {$_.ContainerNodeID -eq $currNode}).Name)/</span><span style="color: #800000;">"</span><span style="color: #000000;">
}</span></pre>
<p><strong>Put it together</strong></p>
<p>As we have everything now (I have all three functions in one module) we can try to do some test.</p>
<p class="code">PS C:\&gt; Get-SmsConsolePath tst00035</p>
<p>Packages/_Global/Windows 7/Adobe/Adobe Reader X – for test</p>
<p>I use this code mainly for documentation purposes. Every time I am reporting to our change request system I just run another function &#8211;  which uses those mentioned &#8211; and it will generate nice table for me. It’s &#8220;similar&#8221; to this:</p>
<p class="code">PS C:\&gt; remedyTable ‘Adobe Reader X’</p>
<p class="code">Package:</p>
<p class="code">&lt;package info&gt; #here is the path in console also</p>
<p class="code">Collection:</p>
<p class="code">&lt;here is collection info&gt;</p>
<p class="code">Advertisement:</p>
<p class="code">&lt;same as for package&gt;</p>
<p class="code">&#8230;</p>
<p>So I am not spending whole day in console looking for settings are other annoying things.</p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2011/01/12/find-path-in-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check refresh time for collections</title>
		<link>http://powershell.cz/2011/01/07/check-refresh-time-for-collections/</link>
		<comments>http://powershell.cz/2011/01/07/check-refresh-time-for-collections/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 21:56:21 +0000</pubDate>
		<dc:creator>makovec</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SMS]]></category>
		<category><![CDATA[ConfigMgr]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://powershell.cz/?p=26</guid>
		<description><![CDATA[It happened to me that during the day I found one of our SMS servers a bit unresponsive. After short investigation I found out that a lot of collections is refreshing at the same time and therefore my refresh was in the queue. As the refresh is by default set for everyday, to the time <a href="http://powershell.cz/2011/01/07/check-refresh-time-for-collections/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>It happened to me that during the day I found one of our SMS servers a bit unresponsive. After short investigation I found out that a lot of collections is refreshing at the same time and therefore my refresh was in the queue. As the refresh is by default set for everyday, to the time when the collection was created, it can happen that there are some peaks when most of our collections are refreshing. So I decided to check this.</p>
<p>Looking into <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyId=58833CD1-6DBB-45BB-BB77-163446068EF6&amp;displaylang=en">SMS SDK</a> I found necessary information</p>
<p><a href="http://www.powershell.cz/images/Checkrefreshtimeforcollections_13B00/image.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.powershell.cz/images/Checkrefreshtimeforcollections_13B00/image_thumb.png" border="0" alt="image" width="244" height="185" /></a></p>
<p>and was able to check <em>RefreshSchedule</em> with <a href="http://technet.microsoft.com/en-us/library/dd315295.aspx">Get-WmiObject</a> cmdlet.</p>
<p class="code">__GENUS          : 2<br />
__CLASS          : SMS_ST_RecurInterval<br />
__SUPERCLASS     : SMS_ScheduleToken<br />
__DYNASTY        : SMS_ScheduleToken<br />
__RELPATH        :<br />
__PROPERTY_COUNT : 8<br />
__DERIVATION     : {SMS_ScheduleToken}<br />
__SERVER         :<br />
__NAMESPACE      :<br />
__PATH           :<br />
DayDuration      : 1<br />
DaySpan          : 1<br />
HourDuration     : 0<br />
HourSpan         : 0<br />
IsGMT            : False<br />
MinuteDuration   : 0<br />
MinuteSpan       : 0<br />
StartTime        : 20040614175400.000000+***</p>
<p>As you can see, <em>StartTime </em>is in standard <a href="http://msdn.microsoft.com/en-us/library/aa387237(VS.85).aspx">obscure</a> WMI format and we are able to convert it to standard <a href="http://msdn.microsoft.com/en-us/library/system.datetime.aspx">DateTime</a> format easily (if you want to see more, you can check <a href="http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2009/06/14/converting-wmi-dates-in-a-pipeline.aspx">nice post</a> from Shay Levy).</p>
<p>We have all info so can build short function:</p>
<pre style="width: 73.72%; height: 160px;"><span style="color: #0000ff;">function</span><span style="color: #000000;"> </span><span style="color: #5f9ea0;">Get-SMSCollectionRefreshTime</span><span style="color: #000000;">
{
    </span><span style="color: #800080;">$colls</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #5f9ea0; font-weight: bold;">Get-WmiObject</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-ComputerName</span><span style="color: #000000;"> </span><span style="color: #800000;">vmsms01</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Namespace</span><span style="color: #000000;"> </span><span style="color: #800000;">root\sms\site_xxx</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Class</span><span style="color: #000000;"> </span><span style="color: #800000;">SMS_Collection</span><span style="color: #000000;">

    </span><span style="color: #0000ff;">foreach</span><span style="color: #000000;"> (</span><span style="color: #800080;">$coll</span><span style="color: #000000;"> </span><span style="color: #0000ff;">in</span><span style="color: #000000;"> </span><span style="color: #800080;">$colls</span><span style="color: #000000;">)
    {
        $([</span><span style="color: #008080;">wmi</span><span style="color: #000000;">]</span><span style="color: #800000;">"</span><span style="color: #800000;">$($coll.__PATH)</span><span style="color: #800000;">"</span><span style="color: #000000;">).RefreshSchedule
    }
}</span></pre>
<p>It will produce long list of refresh schedules for all our collections.</p>
<p><strong>Note:</strong> You can see that in the list are some other properties and if you are interested, you can find more at <a href="http://msdn.microsoft.com/en-us/library/ms815750.aspx">SMS_ST_RecurInterval</a> MSDN page. Most of our collections are set to refresh daily (in case of direct membership we are not refreshing at all) but we have few (three) to refresh more often. In the following code I will count all collections as if they are refreshed daily. If you have more frequently updated collections, you can think about modifying the code.</p>
<p>After some experimenting I came with following code:</p>
<pre style="width: 97.01%; height: 75px;"><span style="color: #000000;">Get-SMSCollectionRefreshTime | </span><span style="color: #5f9ea0; font-weight: bold;">`</span><span style="color: #000000;">
    </span><span style="color: #5f9ea0; font-weight: bold;">Select</span><span style="color: #000000;"> @{l</span><span style="color: #ff0000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">Hour</span><span style="color: #800000;">"</span><span style="color: #000000;">;e</span><span style="color: #ff0000;">=</span><span style="color: #000000;">{</span><span style="color: #800000;">"</span><span style="color: #800000;">{0:d2}</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #ff0000;">-f</span><span style="color: #000000;"> $([</span><span style="color: #008080;">System.Management.ManagementDateTimeConverter</span><span style="color: #000000;">]::</span><span style="color: #8b4513;">ToDateTime</span><span style="color: #000000;">(</span><span style="color: #800080;">$_</span><span style="color: #000000;">.StartTime)).Hour}} | </span><span style="color: #5f9ea0; font-weight: bold;">`</span><span style="color: #000000;">
    </span><span style="color: #5f9ea0; font-weight: bold;">Group</span><span style="color: #000000;"> </span><span style="color: #800000;">Hour</span><span style="color: #000000;"> | </span><span style="color: #5f9ea0; font-weight: bold;">Select</span><span style="color: #000000;"> Name, Count, @{l</span><span style="color: #ff0000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">Graph</span><span style="color: #800000;">"</span><span style="color: #000000;">;e</span><span style="color: #ff0000;">=</span><span style="color: #000000;">{</span><span style="color: #800000;">"</span><span style="color: #800000;">*</span><span style="color: #800000;">"</span><span style="color: #ff0000;">*</span><span style="color: #000000;">$(</span><span style="color: #800080;">$_</span><span style="color: #000000;">.Count</span><span style="color: #ff0000;">/</span><span style="color: #000000;">2</span><span style="color: #000000;">)}} | </span><span style="color: #5f9ea0; font-weight: bold;">Sort</span><span style="color: #000000;"> </span><span style="color: #800000;">Name</span><span style="color: #000000;"> | </span><span style="color: #5f9ea0; font-weight: bold;">ft</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-AutoSize</span><span style="color: #000000;"> </span><span style="font-style: italic; color: #5f9ea0;">-Wrap</span></pre>
<p>which produced following result:</p>
<p class="code">Name Count Graph</p>
<p class="code">
<p class="code">&#8212;- &#8212;&#8211; &#8212;&#8211;</p>
<p class="code">00      16 ********</p>
<p class="code">02       2 *</p>
<p class="code">03       2 *</p>
<p class="code">04       6 ***</p>
<p class="code">05      10 *****</p>
<p class="code">06      66 *********************************</p>
<p class="code">07      22 ***********</p>
<p class="code">08      94 ***********************************************</p>
<p class="code">09     125 **************************************************************</p>
<p class="code">10     163 **********************************************************************************</p>
<p class="code">11     141 **********************************************************************</p>
<p class="code">12      79 ****************************************</p>
<p class="code">13      86 *******************************************</p>
<p class="code">14     118 ***********************************************************</p>
<p class="code">15     166 ***********************************************************************************</p>
<p class="code">16     101 **************************************************</p>
<p class="code">17      99 **************************************************</p>
<p class="code">18      61 ******************************</p>
<p class="code">19      33 ****************</p>
<p class="code">20      12 ******</p>
<p class="code">21       2 *</p>
<p class="code">22       1</p>
<p class="code">23      12 ******</p>
<p>So based on this result, most of our collections are refreshed during 10AM-11AM and 3PM-4PM intervals. Let me describe the code used.</p>
<ol>
<li>First <a href="http://technet.microsoft.com/en-us/library/dd315291.aspx">Select</a> is pretty big construction. I used computed value where the conversion from WMI time is running (<em>[System.Management.ManagementDateTimeConverter]::ToDateTime($_.StartTime)</em>)<em>,</em> from the result I then used just the hour and format it using –f operator (<em>&#8220;{0:d2}&#8221; -f $(…)</em>).</li>
<li>Then <a href="http://technet.microsoft.com/en-us/library/dd347561.aspx">Group</a> it based on computed hour so can see frequency during the day. At the first time I stopped here as I already saw requested data (number of collection refreshed at specific time). But to have more fun I continued…</li>
<li><a href="http://technet.microsoft.com/en-us/library/dd315291.aspx">Select</a> hour, number of collections and show “graph” represented by stars. I found out that because of big peaks it’s better to multiply result by two to have all stars at one screen (<em>&#8220;*&#8221;*$($_.Count/2)</em>).</li>
<li>Then I <a href="http://technet.microsoft.com/en-us/library/dd347688.aspx">Sort</a> results by hour,</li>
<li>and <a href="http://technet.microsoft.com/en-us/library/dd315255.aspx">Format</a> result as table.</li>
</ol>
<p>Whole work didn’t take longer than five (OK – maybe 10) minutes and I was able to confirm my first thoughts. Next task is to check collections refreshed in peaks and decide what can be changed to different time (preferably overnight). But – it will be (maybe) another post.</p>
<p><strong>Note:</strong> I have small piece of paper hung at my screen in the office. It contains this citation:</p>
<p><a href="http://www.powershell.cz/images/Checkrefreshtimeforcollections_13B00/image_3.png"><img style="display: inline; border: 0px;" title="image" src="http://www.powershell.cz/images/Checkrefreshtimeforcollections_13B00/image_thumb_3.png" border="0" alt="image" width="145" height="131" /></a></p>
<p>I am looking to it during the day and today I confirmed it again.</p>
]]></content:encoded>
			<wfw:commentRss>http://powershell.cz/2011/01/07/check-refresh-time-for-collections/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

