<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Richard Siddaway's Blog</title><link>http://msmvps.com/blogs/richardsiddaway/default.aspx</link><description>Of PowerShell and Other Things</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>PowerShell Deep Dive–MEAP now complete</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/24/powershell-deep-dive-meap-now-complete.aspx</link><pubDate>Fri, 24 May 2013 20:06:09 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1831457</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1831457</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/24/powershell-deep-dive-meap-now-complete.aspx#comments</comments><description>&lt;p&gt;The final chapters of PowerShell Deep Dive have been added to the MEAP&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.manning.com/hicks/" href="http://www.manning.com/hicks/"&gt;http://www.manning.com/hicks/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Enjoy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1831457" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Books/default.aspx">Books</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/PowerShell+V3/default.aspx">PowerShell V3</category></item><item><title>AD Month of Lunches–Chapter 11 in MEAP</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/24/ad-month-of-lunches-chapter-11-in-meap.aspx</link><pubDate>Fri, 24 May 2013 19:58:42 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1831456</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1831456</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/24/ad-month-of-lunches-chapter-11-in-meap.aspx#comments</comments><description>&lt;p&gt;The MEAP for AD Management in a Month of Lunches has been extended with the inclusion of chapter 11 – Creating Domain Controllers.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.manning.com/siddaway3"&gt;www.manning.com/siddaway3&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Enjoy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1831456" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/PowerShell+and+Active+Directory/default.aspx">PowerShell and Active Directory</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Active+Directory/default.aspx">Active Directory</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Books/default.aspx">Books</category></item><item><title>Scripting Games - Filter early again</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/21/scripting-games-filter-early-again.aspx</link><pubDate>Tue, 21 May 2013 21:48:17 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1831031</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1831031</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/21/scripting-games-filter-early-again.aspx#comments</comments><description>&lt;p&gt;Grading the scripts in Event 4 and the one thing that jumps out is the amount of unnecessary data being carried through the scripts&lt;/p&gt;  &lt;p&gt;You were asked for 7 properties off 20 random users&lt;/p&gt;  &lt;p&gt;Get-ADUser has a –properties parameter. USE it to restrict the properties you return. You don’t NEED all the other properties&lt;/p&gt;  &lt;p&gt;Next select you 20 users as soon as possible&lt;/p&gt;  &lt;p&gt;get-aduser | get-random&lt;/p&gt;  &lt;p&gt;will do that.&amp;#160; You can then format just the few properties you need on the 20 objects you have left&lt;/p&gt;  &lt;p&gt;FILTER EARLY&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1831031" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/PowerShell+and+Active+Directory/default.aspx">PowerShell and Active Directory</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting Games - Win32_LogicalDisk or Win32_Volume</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/20/scripting-games-win32-logicaldisk-or-win32-volume.aspx</link><pubDate>Mon, 20 May 2013 21:49:25 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1830850</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1830850</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/20/scripting-games-win32-logicaldisk-or-win32-volume.aspx#comments</comments><description>&lt;p&gt;I have heard some discussions recently regarding whether Win32_LogicalDisk or Win32_Volume should be used in the answer to event 3 in the Scripting Games.&lt;/p&gt;  &lt;p&gt;The problem requires you pull the drive letter, drive size and freespace for &lt;strong&gt;local&lt;/strong&gt; disks on the server. Notice the emphasis – that will be important.&lt;/p&gt;  &lt;p&gt;Looking at Win32_Volume&lt;/p&gt;  &lt;p&gt;PS&amp;gt; Get-CimClass -ClassName Win32_Volume | select -ExpandProperty CimClassproperties&amp;#160; | select Name&lt;/p&gt;  &lt;p&gt;Name    &lt;br /&gt;----     &lt;br /&gt;Caption     &lt;br /&gt;Description     &lt;br /&gt;InstallDate     &lt;br /&gt;Name     &lt;br /&gt;Status     &lt;br /&gt;Availability     &lt;br /&gt;ConfigManagerErrorCode     &lt;br /&gt;ConfigManagerUserConfig     &lt;br /&gt;CreationClassName     &lt;br /&gt;DeviceID     &lt;br /&gt;ErrorCleared     &lt;br /&gt;ErrorDescription     &lt;br /&gt;LastErrorCode     &lt;br /&gt;PNPDeviceID     &lt;br /&gt;PowerManagementCapabilities     &lt;br /&gt;PowerManagementSupported     &lt;br /&gt;StatusInfo     &lt;br /&gt;SystemCreationClassName     &lt;br /&gt;SystemName     &lt;br /&gt;Access     &lt;br /&gt;BlockSize     &lt;br /&gt;ErrorMethodology     &lt;br /&gt;NumberOfBlocks     &lt;br /&gt;Purpose     &lt;br /&gt;Automount     &lt;br /&gt;BootVolume     &lt;br /&gt;&lt;strong&gt;Capacity      &lt;br /&gt;&lt;/strong&gt;Compressed     &lt;br /&gt;DirtyBitSet     &lt;br /&gt;&lt;strong&gt;DriveLetter      &lt;br /&gt;&lt;/strong&gt;DriveType     &lt;br /&gt;FileSystem     &lt;br /&gt;&lt;strong&gt;FreeSpace      &lt;br /&gt;&lt;/strong&gt;IndexingEnabled     &lt;br /&gt;Label     &lt;br /&gt;MaximumFileNameLength     &lt;br /&gt;PageFilePresent     &lt;br /&gt;QuotasEnabled     &lt;br /&gt;QuotasIncomplete     &lt;br /&gt;QuotasRebuilding     &lt;br /&gt;SerialNumber     &lt;br /&gt;SupportsDiskQuotas     &lt;br /&gt;SupportsFileBasedCompression     &lt;br /&gt;SystemVolume&lt;/p&gt;  &lt;p&gt;You see 3 properties that might be of use&lt;/p&gt;  &lt;p&gt;Get-CimInstance -ClassName Win32_Volume | select DriveLetter, Capacity, FreeSpace&lt;/p&gt;  &lt;p&gt;is a start but I get two drives with no capacity &amp;amp; freespace – must by my DVD drives&lt;/p&gt;  &lt;p&gt;I can filter those out using drive type.&amp;#160; DriveType =3 gives me local disks&lt;/p&gt;  &lt;p&gt;So the WMI call I need is &lt;/p&gt;  &lt;p&gt;Get-CimInstance -ClassName Win32_Volume -Filter &amp;quot;DriveType=3&amp;quot;&amp;#160; | select DriveLetter, Capacity, FreeSpace&lt;/p&gt;  &lt;p&gt;Get-WmiObject -Class Win32_Volume -Filter &amp;quot;DriveType=3&amp;quot;&amp;#160; | select DriveLetter, Capacity, FreeSpace&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now lets look at Win32_LogicalDisk&lt;/p&gt;  &lt;p&gt;PS&amp;gt; Get-CimClass -ClassName Win32_Logicaldisk | select -ExpandProperty CimClassproperties&amp;#160; | select Name&lt;/p&gt;  &lt;p&gt;Name    &lt;br /&gt;----     &lt;br /&gt;Caption     &lt;br /&gt;Description     &lt;br /&gt;InstallDate     &lt;br /&gt;Name     &lt;br /&gt;Status     &lt;br /&gt;Availability     &lt;br /&gt;ConfigManagerErrorCode     &lt;br /&gt;ConfigManagerUserConfig     &lt;br /&gt;CreationClassName     &lt;br /&gt;DeviceID     &lt;br /&gt;ErrorCleared     &lt;br /&gt;ErrorDescription     &lt;br /&gt;LastErrorCode     &lt;br /&gt;PNPDeviceID     &lt;br /&gt;PowerManagementCapabilities     &lt;br /&gt;PowerManagementSupported     &lt;br /&gt;StatusInfo     &lt;br /&gt;SystemCreationClassName     &lt;br /&gt;SystemName     &lt;br /&gt;Access     &lt;br /&gt;BlockSize     &lt;br /&gt;ErrorMethodology     &lt;br /&gt;NumberOfBlocks     &lt;br /&gt;Purpose     &lt;br /&gt;&lt;strong&gt;FreeSpace      &lt;br /&gt;Size       &lt;br /&gt;&lt;/strong&gt;Compressed     &lt;br /&gt;&lt;strong&gt;DriveType      &lt;br /&gt;&lt;/strong&gt;FileSystem     &lt;br /&gt;MaximumComponentLength     &lt;br /&gt;MediaType     &lt;br /&gt;ProviderName     &lt;br /&gt;QuotasDisabled     &lt;br /&gt;QuotasIncomplete     &lt;br /&gt;QuotasRebuilding     &lt;br /&gt;SupportsDiskQuotas     &lt;br /&gt;SupportsFileBasedCompression     &lt;br /&gt;VolumeDirty     &lt;br /&gt;VolumeName     &lt;br /&gt;VolumeSerialNumber&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I can’t find a DriveLetter but I know that DeviceId supplies that information – if in doubt check by displaying all properties of one instance or do this&lt;/p&gt;  &lt;p&gt;PS&amp;gt; Get-CimInstance -ClassName Win32_Logicaldisk | ft -a&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;DeviceID DriveType ProviderName VolumeName&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Size&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; FreeSpace      &lt;br /&gt;-------- --------- ------------ ----------&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ----&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ---------       &lt;br /&gt;C:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 3&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 249951154176 146292559872       &lt;br /&gt;D:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 3&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System Reserved 104853504&amp;#160;&amp;#160;&amp;#160; 69279744       &lt;br /&gt;E:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 2       &lt;br /&gt;F:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 5       &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Drivetype matches with Win32_Volume so we get&lt;/p&gt;  &lt;p&gt;Get-CimInstance -ClassName Win32_Logicaldisk | Select Deviceid, Size, FreeSpace    &lt;br /&gt;Get-WmiObject -Class Win32_Logicaldisk | Select Deviceid, Size, FreeSpace&lt;/p&gt;  &lt;p&gt;You’ll have noticed that D: has a volume name of System Reserved. This means its a system disk that you shouldn’t be touching. Technically the event asked for information on local disks so it should be included. I know that some purists will argue against this so to remove the system volume you can &lt;/p&gt;  &lt;p&gt;PS&amp;gt;&amp;#160; Get-CimInstance -ClassName Win32_Volume -Filter &amp;quot;DriveType=3 AND SystemVolume = $false&amp;quot;&amp;#160; | select DriveLetter, Capacity, FreeSpace&lt;/p&gt;  &lt;p&gt;or&lt;/p&gt;  &lt;p&gt;PS&amp;gt; Get-CimInstance -ClassName Win32_Logicaldisk -Filter &amp;quot;DriveType = 3 AND VolumeName &amp;lt;&amp;gt; &amp;#39;System Reserved&amp;#39;&amp;quot; | select DeviceId, Size, FreeSpace&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;So either will give you the results you need.&amp;#160; You just need to dig into the classes a bit.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1830850" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/PowerShell+and+WMI/default.aspx">PowerShell and WMI</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting Games-Subfunctions</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/16/scripting-games-subfunctions.aspx</link><pubDate>Thu, 16 May 2013 18:51:51 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1830415</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1830415</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/16/scripting-games-subfunctions.aspx#comments</comments><description>&lt;p&gt;One of the principles of writing scripts (or any code) is the KISS principle – Keep It Simple Scripter.&lt;/p&gt;  &lt;p&gt;That principle is being abused al lot in event 3&lt;/p&gt;  &lt;p&gt;I am seeing numerous entries that define an advanced function as the solution and then inside the PROCESS block define one or more functions.&amp;#160; You PROCESS block is executed once for EVERY object on your pipeline. For 1 object might not matter but for 100s of objects it will adversely affect performance.&lt;/p&gt;  &lt;p&gt;The solutions are such that they sensibly fit in a single solution.&amp;#160; If you must define additional functions make the solution a module so you only load them once.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1830415" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting Games–filtering on remote server</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/14/scripting-games-filtering-on-remote-server.aspx</link><pubDate>Tue, 14 May 2013 19:21:27 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1830235</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1830235</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/14/scripting-games-filtering-on-remote-server.aspx#comments</comments><description>&lt;p&gt;In event 3 you have to get information on hard disk capacity.&amp;#160; I’ve only looked at the first couple of dozen scripts but seen this too many times&lt;/p&gt;  &lt;p&gt;Get-WmiObject -Class Win32_LogicalDisk | where DriveType -eq 3&lt;/p&gt;  &lt;p&gt;or if you prefer the version 2 way&lt;/p&gt;  &lt;p&gt;Get-WmiObject -Class Win32_LogicalDisk | where {$_.DriveType -eq 3}&lt;/p&gt;  &lt;p&gt;If puppies get terminated for using Write-Host this sort of construct should triggers a mass extinction.&lt;/p&gt;  &lt;p&gt;When pulling information back with WMI (or any other technique) from a remote server ALWAYS, ALWAYS, ALWAYS filter on the remote server.&amp;#160; What you are doing here is pulling back all of the data and filtering on the client. This is grossly inefficient when you are dealing with hundreds of machines.&lt;/p&gt;  &lt;p&gt;The PowerShell team gave us the –Filter parameter on Get-WmiObject for a reason. Its to do the filtering on the remote server.&lt;/p&gt;  &lt;p&gt;Get-WmiObject -Class Win32_LogicalDisk -Filter &amp;quot;DriveType = 3&amp;quot;&lt;/p&gt;  &lt;p&gt;If you are guilty of not using –Filter write out 100 times “I must filter on the remote server”&lt;/p&gt;  &lt;p&gt;And no – you can’t write a PowerShell script to do it for you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1830235" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/PowerShell+and+WMI/default.aspx">PowerShell and WMI</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting games–ErrorActionPreference</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/12/scripting-games-erroractionpreference.aspx</link><pubDate>Sun, 12 May 2013 21:18:36 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1830049</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1830049</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/12/scripting-games-erroractionpreference.aspx#comments</comments><description>&lt;p&gt;I’ve seen a lot of this type of thing in events 1 and 2&lt;/p&gt;  &lt;p&gt;$ErrorPref = $ErrorActionPreference    &lt;br /&gt;$ErrorActionPreference = &amp;quot;Stop&amp;quot;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Don’t&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The default for $ErrorActionPreference is Continue.&amp;#160; This means that the error message is shown and the cmdlet attempts to continue. The possible values (from about_Preference_Variables)&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;Stop:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Displays the error message and stops&amp;#160; executing. &lt;/p&gt;  &lt;p&gt;Inquire:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Displays the error message and asks you&amp;#160; whether you want to continue.&lt;/p&gt;  &lt;p&gt;Continue:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Displays the error message and continues executing.    &lt;br /&gt;(Default)&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;SilentlyContinue:&amp;#160;&amp;#160; No effect. The error message is not displayed and execution continues without interruption.    &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;This preference variable only affects &lt;strong&gt;non-terminating&lt;/strong&gt; errors. A terminating error will still stop processing.&amp;#160; Using&lt;/p&gt;  &lt;p&gt;$ErrorActionPreference = &amp;quot;Stop&amp;quot; &lt;/p&gt;  &lt;p&gt;effectively turns all errors in to terminating errors.&lt;/p&gt;  &lt;p&gt;There are times when you want to stop processing and deal with the error such as&lt;/p&gt;  &lt;p&gt;try {&lt;/p&gt;  &lt;p&gt;some cmdlet&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;catch {&lt;/p&gt;  &lt;p&gt;do something&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;In this case use –ErrorAction Stop&amp;#160; on the cmdlet to force errors to be terminating. Just makes sure you have the code in place to catch the error.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1830049" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting Games–making work</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/09/scripting-games-making-work.aspx</link><pubDate>Thu, 09 May 2013 19:42:19 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829803</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829803</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/09/scripting-games-making-work.aspx#comments</comments><description>&lt;p&gt;I saw this in one of the submissions:&lt;/p&gt;  &lt;p&gt;$Properties = @{}    &lt;br /&gt;$Properties[&amp;#39;Computer&amp;#39;] = $SystemInfo.__SERVER     &lt;br /&gt;$Properties[&amp;#39;OperatingSystem&amp;#39;] = &amp;quot;$($OSInfo.Caption) - $($OSInfo.CSDVersion)&amp;quot;     &lt;br /&gt;$Properties[&amp;#39;PhysicalMemory&amp;#39;] = $SystemInfo.TotalPhysicalMemory&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;My immediate thought was the entrant likes making work for themselves. The hash table can be created in a much simpler manner&lt;/p&gt;  &lt;p&gt;$Properties = @{    &lt;br /&gt;Computer = $SystemInfo.__SERVER     &lt;br /&gt;OperatingSystem = &amp;quot;$($OSInfo.Caption) - $($OSInfo.CSDVersion)&amp;quot;     &lt;br /&gt;PhysicalMemory = $SystemInfo.TotalPhysicalMemory     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Same result. Less typing and easiert o read when you come back to the script in 6 months time&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829803" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>AD MoL Chapter 10 MEAP</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/08/ad-mol-chapter-10-meap.aspx</link><pubDate>Wed, 08 May 2013 19:07:19 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829726</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829726</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/08/ad-mol-chapter-10-meap.aspx#comments</comments><description>&lt;p&gt;Chapter 10 of AD Management in a Month of Lunches is now available.&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.manning.com/siddaway3/" href="http://www.manning.com/siddaway3/"&gt;http://www.manning.com/siddaway3/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The chapter covers Fine Grained Password Policies&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829726" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Active+Directory/default.aspx">Active Directory</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Books/default.aspx">Books</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/PowerShell+V3/default.aspx">PowerShell V3</category></item><item><title>Scripting Games–new Get-ChildItem parameters</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/07/scripting-games-new-get-childitem-parameters.aspx</link><pubDate>Tue, 07 May 2013 21:20:39 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829645</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829645</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/07/scripting-games-new-get-childitem-parameters.aspx#comments</comments><description>&lt;p&gt;One improvement that came with PowerShell v3 is the –File and –Directory parameters on Get-ChildItem&lt;/p&gt;  &lt;p&gt;If I run this&lt;/p&gt;  &lt;p&gt;Get-ChildItem -Path c:\mydata&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;I will get a mixture of directories and files &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;Mode&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LastWriteTime&amp;#160;&amp;#160;&amp;#160;&amp;#160; Length Name      &lt;br /&gt;----&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; -------------&amp;#160;&amp;#160;&amp;#160;&amp;#160; ------ ----       &lt;br /&gt;d----&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 19/11/2012&amp;#160;&amp;#160;&amp;#160;&amp;#160; 20:19&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Delivery       &lt;br /&gt;d----&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 26/02/2013&amp;#160;&amp;#160;&amp;#160;&amp;#160; 19:24&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Demo       &lt;br /&gt;d----&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 05/05/2013&amp;#160;&amp;#160;&amp;#160;&amp;#160; 11:26&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ScriptingGames 2013       &lt;br /&gt;d-r--&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 07/05/2013&amp;#160;&amp;#160;&amp;#160;&amp;#160; 18:17&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SkyDrive       &lt;br /&gt;d----&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 24/01/2013&amp;#160;&amp;#160;&amp;#160;&amp;#160; 20:08&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Summit NA 2012       &lt;br /&gt;-a---&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 06/05/2013&amp;#160;&amp;#160;&amp;#160;&amp;#160; 15:26&amp;#160;&amp;#160;&amp;#160; 1336320 2013May_ErrorHandling.doc&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;If I add the –Recurse parameter it gets worse – I know I’ve got a lot of files and directories in here.&lt;/p&gt;  &lt;p&gt;In PowerShell v2 you could separate the directories and files by using PSISContainer&lt;/p&gt;  &lt;p&gt;Get-ChildItem -Path c:\mydata | where {$_.PSIsContainer}    &lt;br /&gt;Get-ChildItem -Path c:\mydata | where {!$_.PSIsContainer}&lt;/p&gt;  &lt;p&gt;will give you the directories only and files only respectively.&lt;/p&gt;  &lt;p&gt;It gets easier in PowerShell v3&lt;/p&gt;  &lt;p&gt;Get-ChildItem -Path c:\mydata -Directory    &lt;br /&gt;Get-ChildItem -Path c:\mydata –File&lt;/p&gt;  &lt;p&gt;simple and obvious when you read it.&lt;/p&gt;  &lt;p&gt;if you are using PowerShell v3 don’t forget these parameters&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829645" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/PowerShell+V3/default.aspx">PowerShell V3</category></item><item><title>Scripting Games-don’t repeat the work</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/07/scripting-games-don-t-repeat-the-work.aspx</link><pubDate>Tue, 07 May 2013 20:57:18 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829644</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829644</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/07/scripting-games-don-t-repeat-the-work.aspx#comments</comments><description>&lt;p&gt;There are some good features to this script but what really hurts is the two trips to the server for the Win32_Computersystem class&lt;/p&gt;&lt;pre&gt;Foreach ($IP in (Get-Content &amp;quot;C:\IPList.txt&amp;quot;))
{
  $Name = (Get-WMIObject Win32_ComputerSystem -ComputerName $ip).Name
  $Mem = [math]::truncate((Get-WMIObject Win32_ComputerSystem -ComputerName $ip).TotalPhysicalMemory / 1MB)
  $Ver = (Get-WMIObject Win32_OperatingSystem -ComputerName $ip).Caption
  [Array]$Cpus = (Get-WMIObject Win32_Processor -ComputerName $ip)
  $CpuCount = $Cpus.Count
  $Cores = 0
  Foreach ($Socket in $Cpus)
    {
    $Cores = $Cores + $Socket.NumberOfCores
    }
  &amp;quot;$Name,$Mem,$Ver,$CpuCount,$Cores&amp;quot; | Out-File output.csv -Append
}&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;it would be better to do this &lt;/pre&gt;&lt;pre&gt;$comp = Get-WMIObject Win32_ComputerSystem -ComputerName $ip&lt;/pre&gt;&lt;pre&gt;$name = $comp.Name&lt;/pre&gt;&lt;pre&gt;$mem = [math]::truncate($comp.TotalPhysicalMemory / 1MB)&lt;/pre&gt;&lt;pre&gt;Dropping one round trip on a few servers isn’t that big a deal.  dropping it on 3000 servers will make a difference&lt;/pre&gt;&lt;pre&gt;Always think about how your scripts may need to scale one day&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829644" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/PowerShell+and+WMI/default.aspx">PowerShell and WMI</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting Games–how not to output data</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/07/scripting-games-how-not-to-output-data.aspx</link><pubDate>Tue, 07 May 2013 20:14:16 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829641</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829641</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/07/scripting-games-how-not-to-output-data.aspx#comments</comments><description>&lt;p&gt;I haven’t finished blogging about event 1 yet but this caught my eye.&lt;/p&gt;  &lt;p&gt;Things aren’t too bad until we hit the bunch of&amp;#160; write-host calls&lt;/p&gt;  &lt;p&gt;$wrks = (Get-Content -path C:\IPList.txt)    &lt;br /&gt;foreach ($wrk in $wrks)     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $osver = Get-WMIObject -class win32_operatingsystem -ComputerName $wrk     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $procs = @(Get-WMIObject -class win32_processor -ComputerName $wrk)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $psok=($procs.SocketDesignation).count     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $pcors=(($procs.numberofcores[0])*$psok)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $plog=($pcors * 2)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $psped=$procs.MaxClockSpeed[0]     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $mem = Get-WMIObject -class win32_physicalmemory -ComputerName $wrk     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $memtotal = ($mem | Measure-Object -Property capacity -Sum)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $memgb = $memtotal.sum/1gb     &lt;br /&gt;Write-host &amp;quot;*******************************************************&amp;quot;     &lt;br /&gt;Write-Host &amp;quot;Machine Name: &amp;quot; $osver.CSName     &lt;br /&gt;Write-Host &amp;quot;OS: &amp;quot;$osver.caption     &lt;br /&gt;Write-Host &amp;quot;Service Pack: &amp;quot;$osver.csdversion     &lt;br /&gt;Write-Host &amp;quot;Build #: &amp;quot;$osver.version     &lt;br /&gt;Write-Host &amp;quot;*********** &amp;quot;     &lt;br /&gt;Write-Host &amp;quot;Memory Installed:&amp;quot;     &lt;br /&gt;Write-Host &amp;quot;*********** &amp;quot;     &lt;br /&gt;Write-Host &amp;quot;Memory (GB): $memgb &amp;quot;     &lt;br /&gt;Write-Host &amp;quot;Slots used:&amp;quot; $memtotal.Count     &lt;br /&gt;Write-Host &amp;quot;*********** &amp;quot;     &lt;br /&gt;Write-Host &amp;quot;Processor(s) Installed:&amp;quot;     &lt;br /&gt;Write-Host &amp;quot;*********** &amp;quot;     &lt;br /&gt;Write-Host &amp;quot;Sockets:&amp;quot; $psok     &lt;br /&gt;Write-Host &amp;quot;Cores:&amp;quot; $pcors     &lt;br /&gt;Write-Host &amp;quot;Logical Procs:&amp;quot; $plog     &lt;br /&gt;Write-Host &amp;quot;*********** &amp;quot;     &lt;br /&gt;Write-Host &amp;quot;Processor Details:&amp;quot;     &lt;br /&gt;Write-Host &amp;quot;*********** &amp;quot;     &lt;br /&gt;$procs     &lt;br /&gt;Write-Host &amp;quot;&amp;quot;     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;The correct way is to create an object and output that &lt;/p&gt;  &lt;p&gt;I’ll be blogging a sample answer when the games are over.&amp;#160; for now be aware that write-host is worse than backticks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829641" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/PowerShell+and+WMI/default.aspx">PowerShell and WMI</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting Games: event 1–use of robocopy</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/06/scripting-games-event-1-use-of-robocopy.aspx</link><pubDate>Mon, 06 May 2013 17:51:31 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829529</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829529</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/06/scripting-games-event-1-use-of-robocopy.aspx#comments</comments><description>&lt;p&gt;The object of the exercise in both the beginners and advanced sections of event 1 was to move a set of log files older than a give data to an archive folder.&lt;/p&gt;  &lt;p&gt;A number of solutions were presented that used robocopy.&lt;/p&gt;  &lt;p&gt;This is a workable solution that meets the lettter of the objective but it doesn’t really meet the spirit of the games.&lt;/p&gt;  &lt;p&gt;The Scripting Games is about learning to use PowerShell.&amp;#160; Within PowerShell there is a move-item cmdlet. &lt;/p&gt;  &lt;p&gt;Robocopy isn’t required. Using non-Powershell tools can often be harder than using PowerShell.&amp;#160; In your work, and especially in the games, think very carefully before reaching for a non-PowerShell command&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;And its not PowerShell!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829529" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting Games–major dislike #2</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/06/scripting-games-major-dislike-2.aspx</link><pubDate>Mon, 06 May 2013 15:26:45 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829518</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829518</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/06/scripting-games-major-dislike-2.aspx#comments</comments><description>&lt;p&gt;I’ve already blogged about incorrect use of backticks.&amp;#160; Here is another example of un-necessary use of backticks&lt;/p&gt;  &lt;p&gt;$Files= Get-ChildItem `    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; -Path $Path `     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; -include $Type `     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; -Recurse `     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; -File |     &lt;br /&gt;Where-Object {$_.LastWriteTime -lt (get-date).AddDays(-$OlderThan) }&lt;/p&gt;  &lt;p&gt;Spreading out one parameter per line like this doesn’t add anything to the script and makes working on the get-childitem cmdlet code harder if you want to change it.&lt;/p&gt;  &lt;p&gt;Don’t do this&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829518" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting games-major dislike</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/06/scripting-games-major-dislike.aspx</link><pubDate>Mon, 06 May 2013 13:52:11 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829512</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829512</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/06/scripting-games-major-dislike.aspx#comments</comments><description>&lt;p&gt;One of the things we were asked to blog about as Scripting Games judges was things we liked and disliked. This code is a major dislike&lt;/p&gt;  &lt;p&gt;Get-ChildItem $sourceDirectory | ? {$_.PsISContainer } |    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; % { $subDirectory = $_ ; Get-ChildItem (&amp;quot;$sourceDirectory\$subDirectory&amp;quot;) -Include *.LOG -Recurse } |     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ? { $logFile = $_ ; $logFile.LastWriteTime -le $modifiedCutOffDate } |    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %&amp;#160; { $logFileAndSubDirDictionary.Add($logFile, $subDirectory) }    &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;Two things really make this stand out as how not to do things:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Using % &amp;amp; ? as aliases in a script. They are tolerable (just) in an interactive command but have no place in a script. Tab completion is so easy. Use the proper command.&lt;/li&gt;    &lt;li&gt;Putting multiple commands on a line separated by ;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; It makes the code hard to read and awkward to work out whats going on. It also makes script testing, debug and maintenance much more difficult&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Avoid these two things in your scripts&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829512" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting Games–integer parameters</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/06/scripting-games-integer-parameters.aspx</link><pubDate>Mon, 06 May 2013 10:18:41 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829503</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829503</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/06/scripting-games-integer-parameters.aspx#comments</comments><description>&lt;p&gt;I keep seeing paramter constructs like this:&lt;/p&gt;  &lt;p&gt;[int]$age = &amp;#39;90&amp;#39;&lt;/p&gt;  &lt;p&gt;Why set the parameter to an integer and then set the default as a string.&amp;#160; PowerShell will convert but it just doesn’t make sense.&lt;/p&gt;  &lt;p&gt;All you need is &lt;/p&gt;  &lt;p&gt;[int]$age = 90&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829503" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting games–using parameters</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/05/scripting-games-using-parameters.aspx</link><pubDate>Sun, 05 May 2013 22:11:18 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829463</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829463</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/05/scripting-games-using-parameters.aspx#comments</comments><description>&lt;p&gt;I am seeing an incredible number of scripts that have this sort of coding round parameters&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;# Input from the user   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [Parameter(Mandatory=$false,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValueFromPipeline=$False,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Position=0)]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [ValidateScript({Test-Path $_ })]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [String]$SourcePath = &amp;#39;C:\Application\Log&amp;#39;,    &lt;br /&gt;&amp;#160; &lt;br /&gt;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [Parameter(Mandatory=$false,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValueFromPipeline=$False,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Position=1)]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [ValidateScript({Test-Path $_ })]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [String]$ArchivePath = &amp;#39;\\NASServer\Archives&amp;#39;,    &lt;br /&gt;&amp;#160; &lt;br /&gt;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [Parameter(Mandatory=$false,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ValueFromPipeline=$False,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Position=2)]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [Int]$Days = 90&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Why do you need to state that Mandatory=$false or that ValueFromPipeline=$False.&amp;#160; The DEFAULT values are false.&amp;#160; You only need to use them if you are setting them to TRUE.&lt;/p&gt;  &lt;p&gt;Its a waste of coding time and processing time when you run the script.&lt;/p&gt;  &lt;p&gt;I remember blogging about this last year. &lt;/p&gt;  &lt;p&gt;Please stop doing it so I don’t to blog about it next year&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829463" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting Games–observation</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/05/scripting-games-observation.aspx</link><pubDate>Sun, 05 May 2013 11:12:17 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829438</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829438</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/05/scripting-games-observation.aspx#comments</comments><description>&lt;p&gt;I don’t have the numbers to back this up but my feeling is that the Scripting Community is marking the entries for this years Games in a harsher manner than the judges did over the last few games.&lt;/p&gt;  &lt;p&gt;What will be very interesting is the level, type and usefulness of the comments that come through. if you do mark low please explain why&lt;/p&gt;  &lt;p&gt;Whether this relaxes over the next few entries will be interesting to see.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829438" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Scripting Games–a word of advice for competitors</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/01/scripting-games-a-word-of-advice-for-competitors.aspx</link><pubDate>Wed, 01 May 2013 21:24:12 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829108</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829108</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/01/scripting-games-a-word-of-advice-for-competitors.aspx#comments</comments><description>&lt;p&gt;At the moment it isn’t necessary to run your script to give a vote. &lt;/p&gt;  &lt;p&gt;Probably the quickest way to lose points is have an obvious and glaring error in your script such as&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;. . . | where {$_.LastWriteTime –lt (&lt;strong&gt;date&lt;/strong&gt;).ADDdays(-90)} | . . . &lt;/p&gt;  &lt;p&gt;or&lt;/p&gt;  &lt;p&gt;. . . | where {$_.LastWriteTime –lt (get-date).&lt;strong&gt;ADDseconds&lt;/strong&gt;(-90)} | . . . &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Both of which I’ve seen today.&lt;/p&gt;  &lt;p&gt;Please make sure your script syntax is correct before you submit otherwise all your hard work will be for nothing&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829108" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category></item><item><title>Filter vs Include</title><link>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/01/filter-vs-include.aspx</link><pubDate>Wed, 01 May 2013 20:19:19 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829103</guid><dc:creator>RichardSiddaway</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/richardsiddaway/rsscomments.aspx?PostID=1829103</wfw:commentRss><comments>http://msmvps.com/blogs/richardsiddaway/archive/2013/05/01/filter-vs-include.aspx#comments</comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I’ve gone through most of the Beginner event submissions over the last couple of days.&amp;#160; One thing that has jumped out is the potential misunderstanding around using the –include or –filter&amp;#160; parameters on get-childitem.&lt;/p&gt;  &lt;p&gt;If we look at the two parameters&lt;/p&gt;  &lt;p&gt;-Include &amp;lt;String[]&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Gets only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or&amp;#160; pattern, such as &amp;quot;*.txt&amp;quot;. Wildcards are permitted.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; The Include parameter is effective only when the command includes the Recurse parameter or the path leads to the contents of a directory, such as C:\Windows\*, where the wildcard character specifies the contents of the C:\Windows directory.     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;-Filter &amp;lt;String&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Specifies a filter in the provider&amp;#39;s format or language. The value of this parameter qualifies the Path parameter.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.&lt;/p&gt;  &lt;p&gt;These are best explained by some examples. Lets start with the current directory&lt;/p&gt;  &lt;p&gt;PS&amp;gt; Get-ChildItem -Filter *.csv | select -First 1&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font face="Courier New"&gt;Directory: C:\MyData\SkyDrive\Data\scripts&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;Mode&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LastWriteTime&amp;#160;&amp;#160;&amp;#160;&amp;#160; Length Name      &lt;br /&gt;----&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; -------------&amp;#160;&amp;#160;&amp;#160;&amp;#160; ------ ----       &lt;br /&gt;-a---&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 12/09/2012&amp;#160;&amp;#160;&amp;#160;&amp;#160; 19:07&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 2665 log.csv&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;but &lt;/p&gt;  &lt;p&gt;Get-ChildItem -include *.csv | select -First 1&lt;/p&gt;  &lt;p&gt;returns nothing&lt;/p&gt;  &lt;p&gt;To get –Include to work you need to do this&lt;/p&gt;  &lt;p&gt;PS&amp;gt; Get-ChildItem&amp;#160; -path .\*&amp;#160; -include *.csv | select -First 1&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; Directory: C:\MyData\SkyDrive\Data\scripts&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;Mode&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LastWriteTime&amp;#160;&amp;#160;&amp;#160;&amp;#160; Length Name      &lt;br /&gt;----&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; -------------&amp;#160;&amp;#160;&amp;#160;&amp;#160; ------ ----       &lt;br /&gt;-a---&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 12/09/2012&amp;#160;&amp;#160;&amp;#160;&amp;#160; 19:07&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 2665 log.csv&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The path has to be given for –Include to return anything&lt;/p&gt;  &lt;p&gt;Looking at another folder&lt;/p&gt;  &lt;p&gt;These work&lt;/p&gt;  &lt;p&gt;Get-ChildItem -Path C:\MyData\SkyDrive\Data\scripts -Filter *.csv&lt;/p&gt;  &lt;p&gt;Get-ChildItem -Path C:\MyData\SkyDrive\Data\scripts\* -Filter *.csv&lt;/p&gt;  &lt;p&gt;Get-ChildItem -Path C:\MyData\SkyDrive\Data\scripts\* -Include *.csv&lt;/p&gt;  &lt;p&gt;Get-ChildItem -Path C:\MyData\SkyDrive\Data\scripts -Include *.csv -Recurse&lt;/p&gt;  &lt;p&gt;But these don’t&lt;/p&gt;  &lt;p&gt;Get-ChildItem -Path C:\MyData\SkyDrive\Data\scripts -Include *.csv&lt;/p&gt;  &lt;p&gt;Get-ChildItem -Path C:\MyData\SkyDrive\Data\scripts\ -Include *.csv&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;If you want to use –Include remember the path and wildcard or use recurse&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829103" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Powershell/default.aspx">Powershell</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/Scripting+Games/default.aspx">Scripting Games</category><category domain="http://msmvps.com/blogs/richardsiddaway/archive/tags/PowerShell+Basics/default.aspx">PowerShell Basics</category></item></channel></rss>