<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2titles.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemtitles.css"?><rss 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/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>snowland.se</title>
	
	<link>http://www.snowland.se</link>
	<description>Rikard Rönnkvist blogging about Microsoft System Center and other management stuff...</description>
	<lastBuildDate>Thu, 09 May 2013 15:26:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/snowland" /><feedburner:info uri="snowland" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><thespringbox:skin xmlns:thespringbox="http://www.thespringbox.com/dtds/thespringbox-1.0.dtd">http://feeds.feedburner.com/snowland?format=skin</thespringbox:skin><geo:lat>60.602214</geo:lat><geo:long>15.586493</geo:long><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/snowland" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2Fsnowland" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
		<title>Logon Scripts in Powershell – Part4: Trigger ConfigMgr client actions</title>
		<link>http://feedproxy.google.com/~r/snowland/~3/FnEAENKnMYc/</link>
		<comments>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part4-trigger-configmgr-client-actions/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 07:09:06 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[ConfigMgr]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Series]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.snowland.se/?p=639</guid>
		<description><![CDATA[With the ConfigMgr agent in place on your client&#8217;s you probably want to force it to start some client actions on logon to speed up deployment of new applications. This function will work with the ConfigMgr 2007 (on x86) and 2012 agent. (The reason for not working on a Win7 x64 and ConfigMgr 2007 is [...]]]></description>
				<content:encoded><![CDATA[<p>With the ConfigMgr agent in place on your client&#8217;s you probably want to force it to start some client actions on logon to speed up deployment of new applications.</p>
<p>This function will work with the ConfigMgr 2007 (on x86) and 2012 agent. (The reason for not working on a Win7 x64 and ConfigMgr 2007 is the lack of X64 support).</p>
<pre class="brush: powershell; title: ; notranslate">
Function Run-ConfigMgrActions {
	&lt;#
	.SYNOPSIS 
		Trigger ConfigMgr client actions
	#&gt;
	PARAM (
		[string] $actionFilter1 = &quot;Application Global Evaluation Task*&quot;,
		[string] $actionFilter2 = &quot;Request ? Evaluate*&quot;
	)

	Write-Verbose &quot;Run-ConfigMgrActions: Start actions with filter '$($actionFilter1)' or '$($actionFilter2)'&quot;
	TRY {
		(New-Object -ComObject CPApplet.cpAppletMgr).GetClientActions() | Where-Object {$_.Name -like $actionFilter1 -or $_.Name -like $actionFilter2} | Sort-Object Name | ForEach-Object {
			Write-Verbose &quot;Run-ConfigMgrActions: Starting ConfigMgr action: $($_.Name)&quot;
			$_.PerformAction()
		}
	}
	CATCH {
		Write-Verbose &quot;Run-ConfigMgrActions: Can't find and/or trigger ConfigMgr Agent&quot;
	}
}
</pre>
<img src="http://feeds.feedburner.com/~r/snowland/~4/FnEAENKnMYc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part4-trigger-configmgr-client-actions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part4-trigger-configmgr-client-actions/</feedburner:origLink></item>
		<item>
		<title>Logon Scripts in Powershell – Part3: Storing and retrieving shares to map to/from AD</title>
		<link>http://feedproxy.google.com/~r/snowland/~3/RCAx79qj7xU/</link>
		<comments>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part3-storing-and-retrieving-shares-to-map-tofrom-ad/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 07:01:52 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Series]]></category>
		<category><![CDATA[ActiveDirectory]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.snowland.se/?p=636</guid>
		<description><![CDATA[To keep you logon scripts static one way of storing information on who sould get what mapped is to use the Active Directory. First of, talk to the AD-guys and &#8220;reserve&#8221; 3 attributes on groups (or extend the schema and add your own attributes). You need attributes for: - Share Path - Display Name - [...]]]></description>
				<content:encoded><![CDATA[<p>To keep you logon scripts static one way of storing information on who sould get what mapped is to use the Active Directory.</p>
<p>First of, talk to the AD-guys and &#8220;reserve&#8221; 3 attributes on groups (or extend the schema and add your own attributes). You need attributes for:<br />
- Share Path<br />
- Display Name<br />
- Type of mapping</p>
<p>In the example I will use:<br />
- displayName = Share Path<br />
- displayNamePrintable = Display Name<br />
- extensionAttribute3 = Type of mapping (I will use a 1 for &#8220;Network Location&#8221;, 0 for not in use and letters to map to a specific drive)</p>
<p>Then, populate the groups with information:</p>
<pre class="brush: powershell; title: ; notranslate">
Import-Module ActiveDirectory

Get-Adgroup &quot;MyGroupName&quot; | Set-ADGroup -Replace @{
	DisplayName=&quot;\\SERVER\PathToMapAsNetworkLocation&quot;;
	DisplayNamePrintable=&quot;Some Description&quot;;
	extensionAttribute3=1
}
Get-Adgroup &quot;SomeOtherGroupName&quot; | Set-ADGroup -Replace @{
	DisplayName=&quot;\\SERVER\PathToMapAsDrive&quot;;
	DisplayNamePrintable=&quot;Some Description&quot;;
	extensionAttribute3=X
}

Get-Adgroup &quot;ProjXDocs&quot; | Set-ADGroup -Replace @{
	DisplayName=&quot;\\SERVER\Projects\ProjectXdocuments&quot;;
	DisplayNamePrintable=&quot;ProjectX Documents&quot;;
	extensionAttribute3=1
}
</pre>
<p>Then, retrieve the groups for the current user with a recursive LDAP-query.</p>
<pre class="brush: powershell; title: ; notranslate">
Function Get-SharesToMap {
	&lt;#
	.SYNOPSIS
		Read groups in AD for a user, then collect information to use when mapping disk
	#&gt;
	PARAM (
		$UserDN = (Get-UserDN)
	)

	$mappedShares = @()
	$ldapFilter = &quot;(&amp;(member:1.2.840.113556.1.4.1941:=$($UserDN))(displayName=*)(extensionAttribute3=*)(!extensionAttribute3=0))&quot;

	Run-LdapQuery -ldapFilter $ldapFilter | ForEach-Object {
		Write-Verbose &quot;Get-SharesToMap: $($ssabMappedSharePath) - Mapping: $($ssabMappedShare)&quot;
		$shareInfo = New-Object -TypeName System.Object
		$shareInfo | add-Member -memberType NoteProperty -name Group -Value $_.Properties.Item(&quot;cn&quot;)
		$shareInfo | add-Member -memberType NoteProperty -name Path -Value $_.Properties.Item('displayName')
		$shareInfo | add-Member -memberType NoteProperty -name DisplayName -Value $_.Properties.Item('displayNamePrintable')
		$shareInfo | add-Member -memberType NoteProperty -name MappedShare -Value $_.Properties.Item('extensionAttribute3')
		
		$mappedShares += $shareInfo
	}

	Return $mappedShares
}
</pre>
<p>Now you have a list of all shares to take care of&#8230;</p>
<pre class="brush: powershell; title: ; notranslate">
Get-SharesToMap | Sort-Object Path | ForEach-Object {
	$Path        = $_.Path
	$MappedShare = $_.MappedShare
	$DisplayName = $_.DisplayName

	# Map UNC path once
	If ($lastMappedPath -ne $Path) {
		Switch -regex ($MappedShare) {
			0        { Write-Verbose &quot;Loginscript:Main: Do not map UNC path $($UncPath)&quot; }
			1        { Create-NethoodShortcut -LinkTarget $Path -LinkName $DisplayName -Description $DisplayName }
			&quot;[A-Z]&quot;  { Map-UncPathToDrive -UncPath $Path -DriveLetter $MappedShare }
			default  { Write-Verbose &quot;Loginscript:Main: $($MappedShare) Do not map path $($Path)&quot; }
		}
		$lastMappedPath = $Path
	}
}
</pre>
<p>With this in place, no one needs to edit the logonscript to change mappings. <img src='http://www.snowland.se/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Sidenote 1:</strong><br />
To speed up the LDAP-queries add indexes on the attributes.<br />
Start MMC<br />
Add the snapin &#8220;Active Directory Schema&#8221;<br />
Search for the attribute(s)<br />
On the properties-page, check the box &#8220;Index this attribute&#8221;</p>
<p><strong>Sidenote 2:</strong><br />
To make it easy to search the attributes, check the box &#8220;Ambigous Name Resolution (ANR)&#8221; in the properties page for the attribute<br />
With ANR enabled you can do a LDAP-query like:<br />
(ANR=SomeNameOfTheShare)<br />
So, if someone wants to be member of the group for the share &#8220;ProjectX&#8221; just query like (ANR=ProjectX) and the group for that share will show up.</p>
<img src="http://feeds.feedburner.com/~r/snowland/~4/RCAx79qj7xU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part3-storing-and-retrieving-shares-to-map-tofrom-ad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part3-storing-and-retrieving-shares-to-map-tofrom-ad/</feedburner:origLink></item>
		<item>
		<title>Logon Scripts in Powershell – Part2: LDAP-Queries</title>
		<link>http://feedproxy.google.com/~r/snowland/~3/LAptDNgxKRo/</link>
		<comments>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part2-ldap-queries/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 06:29:23 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Series]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Sites]]></category>

		<guid isPermaLink="false">http://www.snowland.se/?p=633</guid>
		<description><![CDATA[Next up&#8230; running LDAP in pure Powershell. It would of course be nice to use ActiveDirectory cmdlets in the logonscript&#8230; but you probably don&#8217;t deploy those to all machines. So, running LDAP queries can be done using a ADSI Searcher. One drawback with using this techniqe is the lack of site awareness&#8230; so if you [...]]]></description>
				<content:encoded><![CDATA[<p>Next up&#8230; running LDAP in pure Powershell.<br />
It would of course be nice to use ActiveDirectory cmdlets in the logonscript&#8230; but you probably don&#8217;t deploy those to all machines.</p>
<p>So, running LDAP queries can be done using a ADSI Searcher. One drawback with using this techniqe is the lack of site awareness&#8230; so if you have a larger network (or user out on low performing WAN-links) you need to take care of this &#8220;manually&#8221;.</p>
<p>The easy way to do this is by using the environment variable LogonServer&#8230; and if you have your AD-Sites set up right, this should be the closest server.</p>
<p>Here is how you can run LDAP-Queries on the LogonServer:</p>
<pre class="brush: powershell; title: ; notranslate">
Function Get-AdLogonServer {
	&lt;#
	.SYNOPSIS 
		Returns the AD logon server
	#&gt;

	Return [string] (Get-ChildItem ENV:LogonServer).Value.ToUpper().Replace(&quot;\&quot;, &quot;&quot;)
}

Function Run-LdapQuery {
	&lt;#
	.SYNOPSIS
		Run a LDAP-query on logonserver
	#&gt;
	PARAM (
		[string] $ldapFilter,
		[int] $pageSize = 512,
		[switch] $findOne
	)

	Write-Verbose &quot;Run-LdapQuery: Running: LDAP://$(Get-AdLogonServer)/$($ldapFilter)&quot;

	$AdSearch=([ADSISearcher]([ADSI](&quot;LDAP://$(Get-AdLogonServer)&quot;)))
	$AdSearch.Filter = $ldapFilter
	if ($findOne.IsPresent) {
		$AdSearch.pagesize = 1
		Return $AdSearch.FindOne()
	} else {
		$AdSearch.pagesize = $pageSize
		Return $AdSearch.FindAll()
	}
}
</pre>
<p>And a quick sample to get the current users DN-string:</p>
<pre class="brush: powershell; title: ; notranslate">
Function Get-UserDN {
	&lt;#
	.SYNOPSIS
		Return a DN-string for a user (default to current user)
	#&gt;
	PARAM (
		[string] $UserName = (Get-UserName)
	)

	Run-LdapQuery -ldapFilter &quot;(sAMAccountName=$($UserName))&quot; -findOne | ForEach-Object {
		$userDN = $_.Properties.Item(&quot;DistinguishedName&quot;)
	}

	Return $userDN
}
</pre>
<img src="http://feeds.feedburner.com/~r/snowland/~4/LAptDNgxKRo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part2-ldap-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part2-ldap-queries/</feedburner:origLink></item>
		<item>
		<title>Logon Scripts in Powershell – Part1: Network Locations</title>
		<link>http://feedproxy.google.com/~r/snowland/~3/DaDRbYGVD6Y/</link>
		<comments>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part1-network-locations/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 06:16:00 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Series]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.snowland.se/?p=630</guid>
		<description><![CDATA[Long time no blog&#8230; Since I have written the logonscript we use (of course in Powershell).. why not share some snippets. Starting out with the most common ones that &#8220;everyone&#8221; use. Map shares on file servers&#8230; I prefer to create Network Shortcuts instead of using mapped drives. Why? Take a &#8220;standard&#8221; service desk call: User: [...]]]></description>
				<content:encoded><![CDATA[<p>Long time no blog&#8230;</p>
<p>Since I have written the logonscript we use (of course in Powershell).. why not share some snippets. <img src='http://www.snowland.se/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Starting out with the most common ones that &#8220;everyone&#8221; use. Map shares on file servers&#8230;<br />
I prefer to create Network Shortcuts instead of using mapped drives.<br />
Why?<br />
Take a &#8220;standard&#8221; service desk call:<br />
User: Hey, I want to access X:<br />
Operator: Ok&#8230; where does it point?<br />
User: I don&#8217;t know, but John Doe has a X: and I need it.<br />
* Operator search for John Doe, checks all groups and how they are configured *<br />
Operator: Ok&#8230; found it, log off and on and you are good to go.<br />
User: But what will happen to my X: that I have today?</p>
<p>So, if you use drive letters you are bound to a specific number of letters and when you use X: for multiple of shares you will sooner or later end up in big mess&#8230;</p>
<p>Anyway, I will start of by showing you how to create the Network Locations.</p>
<p>(I will continue with another part on how the AD can be used to make this a lot easier than writing the shares, names and groups directly in the script)</p>
<p>So, here we go&#8230; a few good-to-have functions:</p>
<pre class="brush: powershell; title: ; notranslate">
Function Get-NethoodPath {
	&lt;#
	.SYNOPSIS 
		Returns path to &quot;Network Locations&quot;
		C:\Users\riro\AppData\Roaming\Microsoft\Windows\Network Shortcuts
	#&gt;

	$folderNETHOOD = 0x13
	Return ((New-Object -com Shell.Application).Namespace($folderNETHOOD)).Self.Path
}

Function Delete-NethoodShortcut {
	&lt;#
	.SYNOPSIS 
		Deletes a shortcut under Network Locations
	#&gt;
	PARAM (
		[string] $LinkName
	)

	$NetLocLocalPath = Join-Path (Get-NethoodPath) $LinkName

	If (Test-Path $NetLocLocalPath) {
		Write-Verbose &quot;Delete-NethoodShortcut: Removing: $($NetLocLocalPath)&quot;
		Remove-Item $NetLocLocalPath -Force -Recurse
	}
}

Function Create-NethoodShortcut {
	&lt;#
	.SYNOPSIS 
		Creates a shortcut under Network Locations
	#&gt;
	PARAM (
		[string] $LinkTarget,
		[string] $LinkName,
		[string] $Description = &quot;Folder on the network&quot;,
		$IconLocation = &quot;%SystemRoot%\system32\SHELL32.DLL&quot;,
		$IconIndex = 9
	)
	
	Write-Verbose &quot;Create-NethoodShortcut: Nethood shortcut: '$($LinkName)' targeting '$($LinkTarget)'&quot;

	$NetLocLocalPath = Join-Path (Get-NethoodPath) $LinkName

	If (Test-Path &quot;$($NetLocLocalPath).lnk&quot;) {
		Write-Verbose &quot;Create-NethoodShortcut: Removing old link: $($NetLocLocalPath).lnk&quot;
		Remove-Item &quot;$($NetLocLocalPath).lnk&quot; -Force
	}

	New-Item $NetLocLocalPath -Type directory -Force | Out-Null
	attrib &quot;$NetLocLocalPath&quot; +R

	if ( !(Test-Path &quot;$NetLocLocalPath\Desktop.ini&quot; -pathType leaf) ) {
		$oFile = new-Item &quot;$NetLocLocalPath\Desktop.ini&quot; -type file -force
		add-Content $oFile &quot;[.ShellClassInfo]&quot;
		add-Content $oFile &quot;CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}&quot;
		add-Content $oFile &quot;Flags=2&quot;
		attrib &quot;$NetLocLocalPath\Desktop.ini&quot; +H +S -A
	}

	$wshShell = new-object -comobject wscript.shell
	$shortCut = $wshShell.CreateShortcut($NetLocLocalPath + &quot;\target.lnk&quot;)
	$shortCut.TargetPath = $LinkTarget
	$shortCut.IconLocation = &quot;$($IconLocation), $($IconIndex)&quot;
	$shortCut.Description = $Description
	$shortCut.Save()
}
</pre>
<p>OK.. so you want to map diskdrives instead? This can also be done&#8230;</p>
<pre class="brush: powershell; title: ; notranslate">
Function Test-DriveLetterInUse {
	&lt;#
	.SYNOPSIS
		Return True if a disk is in use
		Test-Path doesnt work to good on UNC-mapped disks
	#&gt;
	PARAM (
		[char] $DriveLetter
	)
	If ((Get-PSDrive -PSProvider FileSystem | Where {$_.Root -eq &quot;$($DriveLetter):\&quot;}) -eq $null) {
		Return $false
	} else {
		Return $true
	}
}

Function Remove-MappedDrive {
	PARAM (
		[char] $DriveLetter
	)

	If ( (Test-DriveLetterInUse -DriveLetter $DriveLetter) -eq $true ) {
		$wshNetwork = New-Object -com WScript.Network
		Write-Verbose &quot;Remove-MappedDrive: $($DriveLetter): in use, removing drivemap&quot;
		$wshNetwork.RemoveNetworkDrive(&quot;$($DriveLetter):&quot;)
	}
}

Function Map-UncPathToDrive {
	PARAM (
		[string] $UncPath,
		[char] $DriveLetter,
		[bool] $OverwriteExisting = $true
	)
	$wshNetwork = New-Object -com WScript.Network

	If ( (Test-DriveLetterInUse -DriveLetter $DriveLetter) -eq $true -and $OverwriteExisting -eq $true) {
		Write-Verbose &quot;Map-UncPathToDrive: $($DriveLetter): in use, removing current drivemap&quot;
		$wshNetwork.RemoveNetworkDrive(&quot;$($DriveLetter):&quot;)
	}
	
	If ((Test-DriveLetterInUse -DriveLetter $DriveLetter) -eq $false) {
		Write-Verbose &quot;Map-UncPathToDrive: Mapping drive $($DriveLetter): to $($UncPath)&quot;

		$wshNetwork.MapNetworkDrive(&quot;$($DriveLetter):&quot;, &quot;$($UncPath)&quot;)
	} else {
		Write-Verbose &quot;Map-UncPathToDrive: $($DriveLetter): allready in use&quot;
	}
}
</pre>
<img src="http://feeds.feedburner.com/~r/snowland/~4/DaDRbYGVD6Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part1-network-locations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.snowland.se/2013/04/18/logon-scripts-in-powershell-part1-network-locations/</feedburner:origLink></item>
		<item>
		<title>PoSH: Send-Prowl</title>
		<link>http://feedproxy.google.com/~r/snowland/~3/OqGaMFuHVQI/</link>
		<comments>http://www.snowland.se/2012/11/11/posh-send-prowl/#comments</comments>
		<pubDate>Sun, 11 Nov 2012 09:49:27 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[OpsMgr]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.snowland.se/?p=561</guid>
		<description><![CDATA[So I&#8217;ve been playing around with Prowl on my iPhone and since the Prowl API is really simple to use why now try some Powershell Here is a function that i wrote: Just download the Prowl APP (from iTunes Store), register an API-key and you are good to go. Some examples: Yes, I knwo that [...]]]></description>
				<content:encoded><![CDATA[<p>So I&#8217;ve been playing around with <a href="http://www.prowlapp.com/ " title="Prowl">Prowl</a> on my iPhone and since the <a href="http://www.prowlapp.com/api.php" title="API">Prowl API</a> is really simple to use why now try some Powershell <img src='http://www.snowland.se/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here is a function that i wrote:</p>
<pre class="brush: powershell; title: ; notranslate">
Function Send-Prowl {
	PARAM (
		[string] [Parameter(Mandatory=$True) ][ValidateLength(1, 1024)]  $Event,
		[string] [Parameter(Mandatory=$False)][ValidateLength(0, 10000)] $Description = &quot;&quot;,
		[string] [Parameter(Mandatory=$False)][ValidateLength(1, 256)]   $ApplicationName = &quot;PoSH: Send-Prowl&quot;,
		[int]    [Parameter(Mandatory=$False)][ValidateRange(-2, 2)]     $Priority = 0,
		[string] [Parameter(Mandatory=$False)][ValidateLength(0, 512)]   $url,
		[string] [Parameter(Mandatory=$True) ][ValidateScript({ $_.Length -ge 40})] $apiKey
	)

	# URL-encode some strings
	[Reflection.Assembly]::LoadWithPartialName(&quot;System.Web&quot;) | Out-Null
	$Event = [web.httputility]::urlencode($Event.Trim())
	$Description = [web.httputility]::urlencode($Description.Trim())
	$ApplicationName = [web.httputility]::urlencode($ApplicationName.Trim())
	$url = [web.httputility]::urlencode($url.Trim())

	# Compose the complete URL
    $apiBaseUrl = &quot;https://prowl.weks.net/publicapi/add&quot;
	$ProwlUrl = &quot;$($apiBaseUrl)?apikey=$($apiKey)&amp;application=$($ApplicationName)&amp;event=$($Event)&amp;Description=$($Description)&amp;priority=$($Priority)&amp;url=$($url)&quot;	
	Write-Verbose &quot;Complete URL: $($ProwlUrl)&quot;

	# Try to send message
    TRY {
	   $webReturn = ([String] (New-Object Net.WebClient).DownloadString($ProwlUrl))
    }
    CATCH {
        Write-Verbose &quot;Error sending Prowl Message: $($error[0])&quot;
        Return $false
    }

    # Output what comes back from the API
	Write-Verbose $webReturn

    If ( (1$webReturn).prowl.success.code -eq 200 ) {
        Write-Verbose &quot;Prowl message sent OK&quot;
        Return $true
    } else {        
        Write-Verbose &quot;Error sending Prowl Message: $((1$webReturn).prowl.error.code) - $((1$webReturn).prowl.error.innerXml)&quot;
        Return $false
    }
}
</pre>
<p>Just download the Prowl APP (from <a href="https://itunes.apple.com/us/app/prowl-growl-client/id320876271?mt=8&#038;ign-mpt=uo%3D4">iTunes Store</a>), <a href="https://www.prowlapp.com/api_settings.php">register</a> an API-key and you are good to go.</p>
<p>Some examples:</p>
<pre class="brush: powershell; title: ; notranslate">
Send-Prowl -apiKey &quot;1234567890123456789012345678901234567890&quot; -Event &quot;Sent from Powershell&quot;
Send-Prowl -apiKey &quot;1234567890123456789012345678901234567890&quot; -Event &quot;Server room on fire!!!&quot; -Priority 2 -Description &quot;Call 112 and get you ass here with an fire extinguisher&quot; -url &quot;tel:112&quot;
Send-Prowl -apiKey &quot;1234567890123456789012345678901234567890&quot; -Event &quot;New Alert&quot; -Priority 1 -Description &quot;Some info...&quot; -url &quot;https://opsmgr.company.com/&quot;
</pre>
<p>Yes, I knwo that there are other ways to do it&#8230; but most of them requires that you load a DLL or use an external EXE-file.</p>
<p>Anyway kudos to <a href="http://www.janssenjones.com/blog/2009/10/18/powershell-iphone-prowl-sysadmin-notification-nirvana.html">Janssen Jones article</a> that inspired me&#8230;</p>
<img src="http://feeds.feedburner.com/~r/snowland/~4/OqGaMFuHVQI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.snowland.se/2012/11/11/posh-send-prowl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.snowland.se/2012/11/11/posh-send-prowl/</feedburner:origLink></item>
		<item>
		<title>Update ConfigMgr Site Description</title>
		<link>http://feedproxy.google.com/~r/snowland/~3/aCUkGKJR07w/</link>
		<comments>http://www.snowland.se/2012/10/12/update-configmgr-site-description/#comments</comments>
		<pubDate>Fri, 12 Oct 2012 05:18:42 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[ConfigMgr]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SiteCode]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.snowland.se/?p=557</guid>
		<description><![CDATA[I did an install of a secondary site and accidently put in the wrong description&#8230; Anyway, easy to fix with some SQL commands. If you use this you can see the current sitenames and descriptions (change CM_XYZ to your database name): And here is the way to update it (Change to you database name and [...]]]></description>
				<content:encoded><![CDATA[<p>I did an install of a secondary site and accidently put in the wrong description&#8230;</p>
<p>Anyway, easy to fix with some SQL commands.</p>
<p>If you use this you can see the current sitenames and descriptions (change CM_XYZ to your database name):</p>
<pre class="brush: sql; title: ; notranslate">
SELECT SiteCode, SiteName, SiteServerName
FROM CM_XYZ..SC_SiteDefinition
</pre>
<p>And here is the way to update it (Change to you database name and the site code of the site you want to change)</p>
<pre class="brush: sql; title: ; notranslate">
UPDATE SC_SiteDefinition
SET SiteName = 'My Site Description'
WHERE CM_XYZ.SiteCode = 'ABC'
</pre>
<p>FYI: When running this you will se &#8220;Updated X rows&#8230; Updated Y rows&#8230;&#8221; and so on.</p>
<img src="http://feeds.feedburner.com/~r/snowland/~4/aCUkGKJR07w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.snowland.se/2012/10/12/update-configmgr-site-description/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.snowland.se/2012/10/12/update-configmgr-site-description/</feedburner:origLink></item>
		<item>
		<title>Set ConfigMgr 2012 Working Hours with Powershell</title>
		<link>http://feedproxy.google.com/~r/snowland/~3/LWUFzaMZLPs/</link>
		<comments>http://www.snowland.se/2012/10/10/set-configmgr-2012-working-hours-with-powershell/#comments</comments>
		<pubDate>Wed, 10 Oct 2012 08:35:06 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[ConfigMgr]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Client]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.snowland.se/?p=553</guid>
		<description><![CDATA[The &#8220;working hours&#8221; defined in ConfigMgr 2012 Software Center on the client is a bit off for our environment&#8230; Did a bit of digging and found some examples in VBScript, but I like Powershell&#8230; And this is how you use it (setting work days Mon-Fri between 08:00 and 17:00) There are a few other methods [...]]]></description>
				<content:encoded><![CDATA[<p>The &#8220;working hours&#8221; defined in ConfigMgr 2012 Software Center on the client is a bit off for our environment&#8230;</p>
<p>Did a bit of digging and found some examples in VBScript, but I like Powershell&#8230; <img src='http://www.snowland.se/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: powershell; title: ; notranslate">
Function Set-CmClientBusinessHours {
	PARAM (
		[int] $StarTime = 7,
		[int] $EndTime = 18,
		[switch] $Sunday,
		[switch] $Monday,
		[switch] $Tuesday,
		[switch] $Wednesday,
		[switch] $Thursday,
		[switch] $Friday,
		[switch] $Saturday
	)
	
	$WorkingDays += ([int]$Sunday.IsPresent    * 1)
	$WorkingDays += ([int]$Monday.IsPresent    * 2)
	$WorkingDays += ([int]$Tuesday.IsPresent   * 4)
	$WorkingDays += ([int]$Wednesday.IsPresent * 8)
	$WorkingDays += ([int]$Thursday.IsPresent  * 16)
	$WorkingDays += ([int]$Friday.IsPresent    * 32)
	$WorkingDays += ([int]$Saturday.IsPresent  * 64)

	TRY {
		$cliUX = [WmiClass]&quot;\\.\ROOT\CCM\ClientSDK:CCM_ClientUXSettings&quot;
		$Params = $cliUX.PSBase.GetMethodParameters(&quot;SetBusinessHours&quot;)
		$Params.StartTime = $StarTime
		$Params.EndTime = $EndTime
		$Params.WorkingDays = $WorkingDays
		$cliUX.PSBase.InvokeMethod(&quot;SetBusinessHours&quot;, $Params, $null) | Out-Null
		Write-Verbose &quot;Business Hours set to $($WorkingDays), between $($StarTime) - $($EndTime)&quot;
		Return $true
	}
	CATCH {
		Write-Verbose &quot;Can't set Business Hours&quot;
		Return $false
	}
}
</pre>
<p>And this is how you use it (setting work days Mon-Fri between 08:00 and 17:00)</p>
<pre class="brush: powershell; title: ; notranslate">
Set-CmClientBusinessHours -Monday -Tuesday -Wednesday -Thursday -Friday -StarTime 8 -EndTime 17
</pre>
<p>There are a few other methods that you can use with (almost) the same code&#8230;</p>
<pre class="brush: powershell; title: ; notranslate">
# First connect to ClientUX
$cliUX = [WmiClass]&quot;\\.\ROOT\CCM\ClientSDK:CCM_ClientUXSettings&quot;

# Get a list of all methods
$cliUX.PSBase.methods | Format-Table Name

# Get list of parameters to a method
$cliUX.PSBase.GetMethodParameters(&quot;SetSuppressComputerActivityInPresentationMode&quot;) | Get-Member
$cliUX.PSBase.GetMethodParameters(&quot;SetAutoInstallRequiredSoftwaretoNonBusinessHours&quot;) | Get-Member
$cliUX.PSBase.GetMethodParameters(&quot;SetBusinessHours&quot;) | Get-Member
</pre>
<img src="http://feeds.feedburner.com/~r/snowland/~4/LWUFzaMZLPs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.snowland.se/2012/10/10/set-configmgr-2012-working-hours-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.snowland.se/2012/10/10/set-configmgr-2012-working-hours-with-powershell/</feedburner:origLink></item>
		<item>
		<title>Keep a list of user/computer groups in registry</title>
		<link>http://feedproxy.google.com/~r/snowland/~3/cff90lEsO_s/</link>
		<comments>http://www.snowland.se/2012/10/08/keep-a-list-of-usercomputer-groups-in-registry/#comments</comments>
		<pubDate>Mon, 08 Oct 2012 07:29:41 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[ConfigMgr]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Collection]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[System Center]]></category>

		<guid isPermaLink="false">http://www.snowland.se/?p=548</guid>
		<description><![CDATA[In the migration to ConfigMgr 2012 we are aiming at just keeping one collection for software distribution and instead rely on global conditions. We do want to keep the option to add a user to a group and with that do a automagic distribution. So, the examples below are snippets from the logonscript. Here is [...]]]></description>
				<content:encoded><![CDATA[<p>In the migration to ConfigMgr 2012 we are aiming at just keeping one collection for software distribution and instead rely on global conditions.<br />
We do want to keep the option to add a user to a group and with that do a automagic distribution.</p>
<p>So, the examples below are snippets from the logonscript.</p>
<p><strong>Here is the short version:</strong><br />
- Recursive search for group membership for user<br />
- If group-list changed, update the reg key<br />
(Then do the same for computer groups)<br />
- If there are any changes to groups, trigger the ConfigMgr agent</p>
<p>- Create a global condition in ConfigMgr<br />
- Use the condition like &#8220;If MyGlobalCondition contains SwDistGroupName&#8221;</p>
<pre class="brush: powershell; title: ; notranslate">
$userDN = &quot;CN=MyUser,OU=Users,DC=snowland,DC=se&quot;
$computerDN = &quot;CN=CyComputer,OU=Computers,DC=snowland,DC=se&quot;

Function Get-DistGroups {
	PARAM (
		$ObjectDN,
		$nameFilter = &quot;SwDist_*&quot;
	)

	$distGroups = @()
	$AdSearch=([ADSISearcher]&quot;LDAP://&quot;)
	$AdSearch.pagesize=512
	$AdSearch.Filter=&quot;(&amp;(member:1.2.840.113556.1.4.1941:=$($ObjectDN))(name=$($nameFilter)))&quot;
	$AdSearch.findAll() | ForEach-Object {
		Write-Verbose &quot;Found group: $($_.Properties.Item('Name'))&quot;
		$distGroups += $_.Properties.Item(&quot;Name&quot;)
	}

	Return $distGroups
}

# Standard setting
$runConfigMgrActions = $false

# Store DIST groups in registry
Write-Host &quot;Reading User DIST groups&quot;
$userDistGroups = Get-DistGroups -ObjectDN $userDN | Sort-Object
$CurrKeys = Read-RegKey -Key &quot;HKCU:\Software\SSAB\SoftwareDistribution&quot; -Name &quot;UserGroups&quot; | Sort-Object
If ((Compare-Object -ReferenceObject $CurrKeys -DifferenceObject $userDistGroups) -ne $null) {
	Write-Host &quot;Found added/removed user groups, writing new list to registry&quot;
	New-ItemProperty &quot;HKCU:\Software\snowland\SoftwareDistribution&quot; -Name &quot;UserGroups&quot; -Value $userDistGroups -PropertyType &quot;MultiString&quot; -Force | Out-Null

	$runConfigMgrActions = $true
} else {
	Write-Verbose &quot;No changes in user groups&quot;
}

Write-Host &quot;Reading computer groups&quot;
$computerDistGroups = Get-DistGroups -ObjectDN $computerDN | Sort-Object
$CurrKeys = Read-RegKey -Key &quot;HKLM:\Software\SSAB\SoftwareDistribution&quot; -Name &quot;ComputerGroups&quot; | Sort-Object

If ((Compare-Object -ReferenceObject $CurrKeys -DifferenceObject $computerDistGroups) -ne $null) {
	Write-Host &quot;Found added/removed computer groups, writing new list to registry&quot;
	New-ItemProperty &quot;HKLM:\Software\snowland\SoftwareDistribution&quot; -Name &quot;ComputerGroups&quot; -Value $computerDistGroups -PropertyType &quot;MultiString&quot; -Force | Out-Null
	$runConfigMgrActions = $true
} else {
	Write-Verbose &quot;No changes in computer groups&quot;
}

# Trigger ConfigMgr client actions if groups have changed
If ($runConfigMgrActions -eq $true) {
	Write-Verbose &quot;Changes to DIST groups, running ConfigMgr Actions&quot;
	(New-Object -ComObject CPApplet.cpAppletMgr).GetClientActions() | Where-Object {$_.Name -like &quot;Application Global Evaluation Task*&quot; -or $_.Name -like &quot;Request &amp; Evaluate*&quot;} | Sort-Object Name | ForEach-Object {
		Write-Host &quot;Starting ConfigMgr action: $($_.Name)&quot;
		$_.PerformAction()
	}
}
</pre>
<p>(To do this you need to set a security GPO to the HKLM-key so that your users are allowed to write there.)</p>
<img src="http://feeds.feedburner.com/~r/snowland/~4/cff90lEsO_s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.snowland.se/2012/10/08/keep-a-list-of-usercomputer-groups-in-registry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.snowland.se/2012/10/08/keep-a-list-of-usercomputer-groups-in-registry/</feedburner:origLink></item>
		<item>
		<title>MDT and Webservices – Small bug</title>
		<link>http://feedproxy.google.com/~r/snowland/~3/onTO4g31WB0/</link>
		<comments>http://www.snowland.se/2012/10/01/mdt-and-webservices-small-bug/#comments</comments>
		<pubDate>Mon, 01 Oct 2012 13:40:05 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[ConfigMgr]]></category>
		<category><![CDATA[VBScript]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Fix]]></category>
		<category><![CDATA[MDT]]></category>

		<guid isPermaLink="false">http://www.snowland.se/?p=541</guid>
		<description><![CDATA[Long time no blog&#8230; Working on a move to CM2012 from CM2007, and with that we are trying to move to Webservices instead of client side VBScript. I found a small bug in MDT (Looked at version 2010U1 and 2012U1 and it&#8217;s the same) You will see this bug if you have a webservice call [...]]]></description>
				<content:encoded><![CDATA[<p>Long time no blog&#8230;</p>
<p>Working on a move to CM2012 from CM2007, and with that we are trying to move to Webservices instead of client side VBScript.</p>
<p>I found a small bug in MDT (Looked at version 2010U1 and 2012U1 and it&#8217;s the same)</p>
<p>You will see this bug if you have a webservice call from CustomSettings where a parameter value have a space (or any other &#8220;strange&#8221; char).<br />
Since the script <strong>ZTIDataAccess.vbs</strong> doesn&#8217;t URL-encode the parameters some of them will get messed up&#8230;</p>
<p>Heres how to fix it:<br />
Search for the text &#8220;Handle it appropriately&#8221; in <strong>ZTIDataAccess.vbs</strong> and you can replace the code with this bugfixed version:</p>
<pre class="brush: vb; title: ; notranslate">
' Handle it appropriately
If IsObject(tmpValue) then
	oLogging.CreateEntry &quot;Only the first &quot; &amp; sElement &amp; &quot; value will be used in the web service call.&quot;, LogTypeInfo
	tmpArray = tmpValue.Keys
	If UCase(sMethod) = &quot;REST&quot; then
		sEnvelope = sEnvelope &amp; sColumn &amp; &quot; eq '&quot; &amp; tmpArray(0) &amp; &quot;' and &quot;
	Else
' riro Buggfix
' Org: sEnvelope = sEnvelope &amp; sColumn &amp; &quot;=&quot; &amp; tmpArray(0) &amp; &quot;&amp;&quot;
		sEnvelope = sEnvelope &amp; sColumn &amp; &quot;=&quot; &amp; Escape(tmpArray(0)) &amp; &quot;&amp;&quot;
	End if
Else
	If UCase(sMethod) = &quot;REST&quot; then
		sEnvelope = sEnvelope &amp; sColumn &amp; &quot; eq '&quot; &amp; tmpValue &amp; &quot;' and &quot;
	Else
' riro Buggfix
' Org: sEnvelope = sEnvelope &amp; sColumn &amp; &quot;=&quot; &amp; tmpValue &amp; &quot;&amp;&quot;
		sEnvelope = sEnvelope &amp; sColumn &amp; &quot;=&quot; &amp; Escape(tmpValue) &amp; &quot;&amp;&quot;
	End If
End If
</pre>
<p>As you can see I have just added Escape() to the values. <img src='http://www.snowland.se/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/snowland/~4/onTO4g31WB0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.snowland.se/2012/10/01/mdt-and-webservices-small-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.snowland.se/2012/10/01/mdt-and-webservices-small-bug/</feedburner:origLink></item>
		<item>
		<title>Get ConfigMgr Collection rules</title>
		<link>http://feedproxy.google.com/~r/snowland/~3/m1hwh_PXQxI/</link>
		<comments>http://www.snowland.se/2011/01/25/get-configmgr-collection-rules/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 09:32:57 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[ConfigMgr]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Rules]]></category>
		<category><![CDATA[WQL]]></category>

		<guid isPermaLink="false">http://www.snowland.se/?p=537</guid>
		<description><![CDATA[I&#8217;m in the process of installing Forefront Endpoint Protection and wanted to look at some of the collection queries that was created&#8230; but with the ConfigMgr console you cant view them&#8230; So Powershell it is. Did a function that you can use on any collection (with subcollections) to view the WQL. A small warning: It [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m in the process of installing Forefront Endpoint Protection and wanted to look at some of the collection queries that was created&#8230; but with the ConfigMgr console you cant view them&#8230;</p>
<p>So Powershell it is.</p>
<p>Did a function that you can use on any collection (with subcollections) to view the WQL.</p>
<pre class="brush: powershell; title: ; notranslate">
Import-Module SCCM\SCCM-Functions -Force
Function Get-CollectionRules {
	PARAM (
		$parentCollection,
		$spacer,
		$sccm
	)

	$subCollections = Get-SCCMSubCollections -SccmServer $sccm -CollectionID $parentCollection
	
	if ($subCollections -ne $null) {
		$subCollections | ForEach-Object {
			$collection = Get-SCCMCollection -Filter &quot;CollectionID='$($_.subCollectionID)'&quot; -SccmServer $sccm
			Write-Host &quot;$($spacer) Name: &quot; -ForegroundColor Yellow -NoNewline
			Write-Host &quot;$($collection.CollectionID) - $($collection.Name)&quot;

			$collectionRule = (Get-SCCMCollectionRules -SccmServer ( Connect-SCCMServer ) -CollectionID $collection.CollectionID)
			if ($collectionRule -ne $null) {
				Write-Host &quot;$($spacer)Limit: &quot; -ForegroundColor Yellow -NoNewline
				if ($collectionRule.LimitToCollectionID.Length -gt 0) {
					Write-Host &quot;$($collectionRule.LimitToCollectionID)&quot; -ForegroundColor White
				} else {
					Write-Host &quot;&lt;No limit to collection&gt;&quot; -ForegroundColor Gray
				}

				Write-Host &quot;$($spacer)  WQL: &quot; -ForegroundColor Yellow -NoNewline
				Write-Host &quot;$($collectionRule.QueryExpression)&quot;
			} else {
				Write-Host &quot;$($spacer)&lt;no rule present on collection&gt;&quot; -ForegroundColor Gray
			}
			Write-Host &quot;&quot;

			Get-CollectionRules -parentCollection $_.subCollectionID -spacer &quot;   $($spacer)&quot; -sccm $sccm
		}
	}
}

Get-CollectionRules -parentCollection &quot;XYZ00123&quot; -spacer &quot;&quot; -sccm (Connect-SCCMServer)
</pre>
<p>A small warning: It will loop all of the subcollections, and the subcollections subcollections, and so on&#8230;</p>
<img src="http://feeds.feedburner.com/~r/snowland/~4/m1hwh_PXQxI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.snowland.se/2011/01/25/get-configmgr-collection-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.snowland.se/2011/01/25/get-configmgr-collection-rules/</feedburner:origLink></item>
	</channel>
</rss>
