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

<channel>
	<title>PowerShell for Windows Admins</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/powershell</link>
	<description>PowerShell and WMI: The fast and furious of windows administration.</description>
	<lastBuildDate>Tue, 21 May 2013 21:49:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Scripting Games &#8211; Filter early again</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-filter-early-again/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-filter-early-again/#comments</comments>
		<pubDate>Tue, 21 May 2013 21:49:17 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting Games]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=920</guid>
		<description><![CDATA[Grading the scripts in Event 4 and the one thing that jumps out is the amount of unnecessary data being carried through the scripts You were asked for 7 properties off 20 random users Get-ADUser has a –properties parameter. USE it to restrict the properties you return. You don’t NEED all the other properties Next [...]]]></description>
				<content:encoded><![CDATA[
<p>Grading the scripts in Event 4 and the one thing that jumps out is the amount of unnecessary data being carried through the scripts</p>
<p>You were asked for 7 properties off 20 random users</p>
<p>Get-ADUser has a –properties parameter. USE it to restrict the properties you return. You don’t NEED all the other properties</p>
<p>Next select you 20 users as soon as possible</p>
<p>get-aduser | get-random</p>
<p>will do that.  You can then format just the few properties you need on the 20 objects you have left</p>
<p>FILTER EARLY</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-filter-early-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Games &#8211; Win32_LogicalDisk or Win32_Volume</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-win32_logicaldisk-or-win32_volume/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-win32_logicaldisk-or-win32_volume/#comments</comments>
		<pubDate>Mon, 20 May 2013 21:50:40 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting Games]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=919</guid>
		<description><![CDATA[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. The problem requires you pull the drive letter, drive size and freespace for local disks on the server. Notice the emphasis – that will be important. Looking at Win32_Volume PS&#62; Get-CimClass [...]]]></description>
				<content:encoded><![CDATA[
<p>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.</p>
<p>The problem requires you pull the drive letter, drive size and freespace for local disks on the server. Notice the emphasis – that will be important.</p>
<p>Looking at Win32_Volume</p>
<p>PS&gt; Get-CimClass -ClassName Win32_Volume | select -ExpandProperty CimClassproperties  | select Name</p>
<p>Name<br />
&#8212;-<br />
Caption<br />
Description<br />
InstallDate<br />
Name<br />
Status<br />
Availability<br />
ConfigManagerErrorCode<br />
ConfigManagerUserConfig<br />
CreationClassName<br />
DeviceID<br />
ErrorCleared<br />
ErrorDescription<br />
LastErrorCode<br />
PNPDeviceID<br />
PowerManagementCapabilities<br />
PowerManagementSupported<br />
StatusInfo<br />
SystemCreationClassName<br />
SystemName<br />
Access<br />
BlockSize<br />
ErrorMethodology<br />
NumberOfBlocks<br />
Purpose<br />
Automount<br />
BootVolume<br />
Capacity<br />
Compressed<br />
DirtyBitSet<br />
DriveLetter<br />
DriveType<br />
FileSystem<br />
FreeSpace<br />
IndexingEnabled<br />
Label<br />
MaximumFileNameLength<br />
PageFilePresent<br />
QuotasEnabled<br />
QuotasIncomplete<br />
QuotasRebuilding<br />
SerialNumber<br />
SupportsDiskQuotas<br />
SupportsFileBasedCompression<br />
SystemVolume</p>
<p>You see 3 properties that might be of use</p>
<p>Get-CimInstance -ClassName Win32_Volume | select DriveLetter, Capacity, FreeSpace</p>
<p>is a start but I get two drives with no capacity &amp; freespace – must by my DVD drives</p>
<p>I can filter those out using drive type.  DriveType =3 gives me local disks</p>
<p>So the WMI call I need is </p>
<p>Get-CimInstance -ClassName Win32_Volume -Filter &#8220;DriveType=3&#8243;  | select DriveLetter, Capacity, FreeSpace</p>
<p>Get-WmiObject -Class Win32_Volume -Filter &#8220;DriveType=3&#8243;  | select DriveLetter, Capacity, FreeSpace</p>
<p>Now lets look at Win32_LogicalDisk</p>
<p>PS&gt; Get-CimClass -ClassName Win32_Logicaldisk | select -ExpandProperty CimClassproperties  | select Name</p>
<p>Name<br />
&#8212;-<br />
Caption<br />
Description<br />
InstallDate<br />
Name<br />
Status<br />
Availability<br />
ConfigManagerErrorCode<br />
ConfigManagerUserConfig<br />
CreationClassName<br />
DeviceID<br />
ErrorCleared<br />
ErrorDescription<br />
LastErrorCode<br />
PNPDeviceID<br />
PowerManagementCapabilities<br />
PowerManagementSupported<br />
StatusInfo<br />
SystemCreationClassName<br />
SystemName<br />
Access<br />
BlockSize<br />
ErrorMethodology<br />
NumberOfBlocks<br />
Purpose<br />
FreeSpace<br />
Size<br />
Compressed<br />
DriveType<br />
FileSystem<br />
MaximumComponentLength<br />
MediaType<br />
ProviderName<br />
QuotasDisabled<br />
QuotasIncomplete<br />
QuotasRebuilding<br />
SupportsDiskQuotas<br />
SupportsFileBasedCompression<br />
VolumeDirty<br />
VolumeName<br />
VolumeSerialNumber</p>
<p>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</p>
<p>PS&gt; Get-CimInstance -ClassName Win32_Logicaldisk | ft -a</p>
<p>DeviceID DriveType ProviderName VolumeName      Size         FreeSpace<br />
&#8212;&#8212;&#8211; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;-      &#8212;-         &#8212;&#8212;&#8212;<br />
C:       3                                      249951154176 146292559872<br />
D:       3                      System Reserved 104853504    69279744<br />
E:       2<br />
F:       5 </p>
<p>Drivetype matches with Win32_Volume so we get</p>
<p>Get-CimInstance -ClassName Win32_Logicaldisk | Select Deviceid, Size, FreeSpace<br />
Get-WmiObject -Class Win32_Logicaldisk | Select Deviceid, Size, FreeSpace</p>
<p>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 </p>
<p>PS&gt;  Get-CimInstance -ClassName Win32_Volume -Filter &#8220;DriveType=3 AND SystemVolume = $false&#8221;  | select DriveLetter, Capacity, FreeSpace</p>
<p>or</p>
<p>PS&gt; Get-CimInstance -ClassName Win32_Logicaldisk -Filter &#8220;DriveType = 3 AND VolumeName  &#8216;System Reserved&#8217;&#8221; | select DeviceId, Size, FreeSpace</p>
<p>So either will give you the results you need.  You just need to dig into the classes a bit.</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-win32_logicaldisk-or-win32_volume/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Games-Subfunctions</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-subfunctions/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-subfunctions/#comments</comments>
		<pubDate>Thu, 16 May 2013 18:56:16 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting Games]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=918</guid>
		<description><![CDATA[One of the principles of writing scripts (or any code) is the KISS principle – Keep It Simple Scripter. That principle is being abused al lot in event 3 I am seeing numerous entries that define an advanced function as the solution and then inside the PROCESS block define one or more functions. You PROCESS [...]]]></description>
				<content:encoded><![CDATA[
<p>One of the principles of writing scripts (or any code) is the KISS principle – Keep It Simple Scripter.</p>
<p>That principle is being abused al lot in event 3</p>
<p>I am seeing numerous entries that define an advanced function as the solution and then inside the PROCESS block define one or more functions.  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.</p>
<p>The solutions are such that they sensibly fit in a single solution.  If you must define additional functions make the solution a module so you only load them once.</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-subfunctions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Games–filtering on remote server</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-filtering-on-remote-server/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-filtering-on-remote-server/#comments</comments>
		<pubDate>Tue, 14 May 2013 19:22:56 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting Games]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=917</guid>
		<description><![CDATA[In event 3 you have to get information on hard disk capacity. I’ve only looked at the first couple of dozen scripts but seen this too many times Get-WmiObject -Class Win32_LogicalDisk &#124; where DriveType -eq 3 or if you prefer the version 2 way Get-WmiObject -Class Win32_LogicalDisk &#124; where {$_.DriveType -eq 3} If puppies get [...]]]></description>
				<content:encoded><![CDATA[
<p>In event 3 you have to get information on hard disk capacity.  I’ve only looked at the first couple of dozen scripts but seen this too many times</p>
<p>Get-WmiObject -Class Win32_LogicalDisk | where DriveType -eq 3</p>
<p>or if you prefer the version 2 way</p>
<p>Get-WmiObject -Class Win32_LogicalDisk | where {$_.DriveType -eq 3}</p>
<p>If puppies get terminated for using Write-Host this sort of construct should triggers a mass extinction.</p>
<p>When pulling information back with WMI (or any other technique) from a remote server ALWAYS, ALWAYS, ALWAYS filter on the remote server.  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.</p>
<p>The PowerShell team gave us the –Filter parameter on Get-WmiObject for a reason. Its to do the filtering on the remote server.</p>
<p>Get-WmiObject -Class Win32_LogicalDisk -Filter &#8220;DriveType = 3&#8243;</p>
<p>If you are guilty of not using –Filter write out 100 times “I must filter on the remote server”</p>
<p>And no – you can’t write a PowerShell script to do it for you!</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-filtering-on-remote-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting games–ErrorActionPreference</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/915/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/915/#comments</comments>
		<pubDate>Sun, 12 May 2013 21:20:17 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting Games]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=915</guid>
		<description><![CDATA[I’ve seen a lot of this type of thing in events 1 and 2 $ErrorPref = $ErrorActionPreference $ErrorActionPreference = &#8220;Stop&#8221; Don’t The default for $ErrorActionPreference is Continue. This means that the error message is shown and the cmdlet attempts to continue. The possible values (from about_Preference_Variables) Stop: Displays the error message and stops executing. Inquire: [...]]]></description>
				<content:encoded><![CDATA[
<p>I’ve seen a lot of this type of thing in events 1 and 2</p>
<p>$ErrorPref = $ErrorActionPreference<br />
$ErrorActionPreference = &#8220;Stop&#8221;</p>
<p>Don’t</p>
<p>The default for $ErrorActionPreference is Continue.  This means that the error message is shown and the cmdlet attempts to continue. The possible values (from about_Preference_Variables)</p>
<p>Stop:               Displays the error message and stops  executing.<br />
Inquire:            Displays the error message and asks you  whether you want to continue.<br />
Continue:           Displays the error message and continues executing.<br />
(Default)<br />
SilentlyContinue:   No effect. The error message is not displayed and execution continues without interruption. </p>
<p>This preference variable only affects non-terminating errors. A terminating error will still stop processing.  Using<br />
$ErrorActionPreference = &#8220;Stop&#8221; </p>
<p>effectively turns all errors in to terminating errors.<br />
There are times when you want to stop processing and deal with the error such as</p>
<p>try {<br />
some cmdlet<br />
}<br />
catch {<br />
do something<br />
}</p>
<p>In this case use –ErrorAction Stop  on the cmdlet to force errors to be terminating. Just makes sure you have the code in place to catch the error.</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/915/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Games–making work</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-making-work/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-making-work/#comments</comments>
		<pubDate>Thu, 09 May 2013 19:43:39 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting Games]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=914</guid>
		<description><![CDATA[I saw this in one of the submissions: $Properties = @{} $Properties['Computer'] = $SystemInfo.__SERVER $Properties['OperatingSystem'] = &#8220;$($OSInfo.Caption) &#8211; $($OSInfo.CSDVersion)&#8221; $Properties['PhysicalMemory'] = $SystemInfo.TotalPhysicalMemory My immediate thought was the entrant likes making work for themselves. The hash table can be created in a much simpler manner $Properties = @{ Computer = $SystemInfo.__SERVER OperatingSystem = &#8220;$($OSInfo.Caption) &#8211; $($OSInfo.CSDVersion)&#8221; [...]]]></description>
				<content:encoded><![CDATA[
<p>I saw this in one of the submissions:</p>
<p>$Properties = @{}<br />
$Properties['Computer'] = $SystemInfo.__SERVER<br />
$Properties['OperatingSystem'] = &#8220;$($OSInfo.Caption) &#8211; $($OSInfo.CSDVersion)&#8221;<br />
$Properties['PhysicalMemory'] = $SystemInfo.TotalPhysicalMemory   </p>
<p>My immediate thought was the entrant likes making work for themselves. The hash table can be created in a much simpler manner</p>
<p>$Properties = @{<br />
Computer = $SystemInfo.__SERVER<br />
OperatingSystem = &#8220;$($OSInfo.Caption) &#8211; $($OSInfo.CSDVersion)&#8221;<br />
PhysicalMemory = $SystemInfo.TotalPhysicalMemory<br />
}</p>
<p>Same result. Less typing and easier to read when you come back to the script in 6 months time</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-making-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AD MoL Chapter 10 MEAP</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/ad-mol-chapter-10-meap/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/ad-mol-chapter-10-meap/#comments</comments>
		<pubDate>Wed, 08 May 2013 19:08:42 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[PowerShell 3]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=913</guid>
		<description><![CDATA[Chapter 10 of AD Management in a Month of Lunches is now available. http://www.manning.com/siddaway3/ The chapter covers Fine Grained Password Policies]]></description>
				<content:encoded><![CDATA[
<p>Chapter 10 of AD Management in a Month of Lunches is now available.</p>
<p>http://www.manning.com/siddaway3/</p>
<p>The chapter covers Fine Grained Password Policies</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/ad-mol-chapter-10-meap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Games–new Get-ChildItem parameters</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-new-get-childitem-parameters/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-new-get-childitem-parameters/#comments</comments>
		<pubDate>Tue, 07 May 2013 21:21:44 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell 3]]></category>
		<category><![CDATA[Scripting Games]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=912</guid>
		<description><![CDATA[One improvement that came with PowerShell v3 is the –File and –Directory parameters on Get-ChildItem If I run this Get-ChildItem -Path c:\mydata I will get a mixture of directories and files Mode LastWriteTime Length Name &#8212;- &#8212;&#8212;&#8212;&#8212;- &#8212;&#8212; &#8212;- d&#8212;- 19/11/2012 20:19 Delivery d&#8212;- 26/02/2013 19:24 Demo d&#8212;- 05/05/2013 11:26 ScriptingGames 2013 d-r&#8211; 07/05/2013 18:17 [...]]]></description>
				<content:encoded><![CDATA[
<p>One improvement that came with PowerShell v3 is the –File and –Directory parameters on Get-ChildItem</p>
<p>If I run this</p>
<p>Get-ChildItem -Path c:\mydata</p>
<p>I will get a mixture of directories and files </p>
<p>Mode                LastWriteTime     Length Name<br />
&#8212;-                &#8212;&#8212;&#8212;&#8212;-     &#8212;&#8212; &#8212;-<br />
d&#8212;-        19/11/2012     20:19            Delivery<br />
d&#8212;-        26/02/2013     19:24            Demo<br />
d&#8212;-        05/05/2013     11:26            ScriptingGames 2013<br />
d-r&#8211;        07/05/2013     18:17            SkyDrive<br />
d&#8212;-        24/01/2013     20:08            Summit NA 2012<br />
-a&#8212;        06/05/2013     15:26    1336320 2013May_ErrorHandling.doc</p>
<p>If I add the –Recurse parameter it gets worse – I know I’ve got a lot of files and directories in here.</p>
<p>In PowerShell v2 you could separate the directories and files by using PSISContainer</p>
<p>Get-ChildItem -Path c:\mydata | where {$_.PSIsContainer}<br />
Get-ChildItem -Path c:\mydata | where {!$_.PSIsContainer}</p>
<p>will give you the directories only and files only respectively.</p>
<p>It gets easier in PowerShell v3</p>
<p>Get-ChildItem -Path c:\mydata -Directory<br />
Get-ChildItem -Path c:\mydata –File</p>
<p>simple and obvious when you read it.</p>
<p>if you are using PowerShell v3 don’t forget these parameters</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-new-get-childitem-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Games-don’t repeat the work</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/909/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/909/#comments</comments>
		<pubDate>Tue, 07 May 2013 21:00:57 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting Games]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=909</guid>
		<description><![CDATA[There are some good features to this script but what really hurts is the two trips to the server for the Win32_Computersystem class Foreach ($IP in (Get-Content &#8220;C:\IPList.txt&#8221;)) { $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) [...]]]></description>
				<content:encoded><![CDATA[
<p>There are some good features to this script but what really hurts is the two trips to the server for the Win32_Computersystem class</p>
<p>Foreach ($IP in (Get-Content &#8220;C:\IPList.txt&#8221;))<br />
{<br />
  $Name = (Get-WMIObject Win32_ComputerSystem -ComputerName $ip).Name<br />
  $Mem = [math]::truncate((Get-WMIObject Win32_ComputerSystem -ComputerName $ip).TotalPhysicalMemory / 1MB)<br />
  $Ver = (Get-WMIObject Win32_OperatingSystem -ComputerName $ip).Caption<br />
  [Array]$Cpus = (Get-WMIObject Win32_Processor -ComputerName $ip)<br />
  $CpuCount = $Cpus.Count<br />
  $Cores = 0<br />
  Foreach ($Socket in $Cpus)<br />
    {<br />
    $Cores = $Cores + $Socket.NumberOfCores<br />
    }<br />
  &#8220;$Name,$Mem,$Ver,$CpuCount,$Cores&#8221; | Out-File output.csv -Append<br />
}<br />
it would be better to do this<br />
$comp = Get-WMIObject Win32_ComputerSystem -ComputerName $ip<br />
$name = $comp.Name<br />
$mem = [math]::truncate($comp.TotalPhysicalMemory / 1MB)</p>
<p>Dropping one round trip on a few servers isn’t that big a deal.  dropping it on 3000 servers will make a difference<br />
Always think about how your scripts may need to scale one day</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/909/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Games–how not to output data</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-how-not-to-output-data/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-how-not-to-output-data/#comments</comments>
		<pubDate>Tue, 07 May 2013 20:15:50 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting Games]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=908</guid>
		<description><![CDATA[I haven’t finished blogging about event 1 yet but this caught my eye. Things aren’t too bad until we hit the bunch of write-host calls $wrks = (Get-Content -path C:\IPList.txt) foreach ($wrk in $wrks) { $osver = Get-WMIObject -class win32_operatingsystem -ComputerName $wrk $procs = @(Get-WMIObject -class win32_processor -ComputerName $wrk) $psok=($procs.SocketDesignation).count $pcors=(($procs.numberofcores[0])*$psok) $plog=($pcors * 2) $psped=$procs.MaxClockSpeed[0] [...]]]></description>
				<content:encoded><![CDATA[
<p>I haven’t finished blogging about event 1 yet but this caught my eye.</p>
<p>Things aren’t too bad until we hit the bunch of  write-host calls</p>
<p>$wrks = (Get-Content -path C:\IPList.txt)<br />
foreach ($wrk in $wrks)<br />
{<br />
    $osver = Get-WMIObject -class win32_operatingsystem -ComputerName $wrk<br />
    $procs = @(Get-WMIObject -class win32_processor -ComputerName $wrk)<br />
    $psok=($procs.SocketDesignation).count<br />
    $pcors=(($procs.numberofcores[0])*$psok)<br />
    $plog=($pcors * 2)<br />
    $psped=$procs.MaxClockSpeed[0]<br />
    $mem = Get-WMIObject -class win32_physicalmemory -ComputerName $wrk<br />
    $memtotal = ($mem | Measure-Object -Property capacity -Sum)<br />
    $memgb = $memtotal.sum/1gb<br />
Write-host &#8220;*******************************************************&#8221;<br />
Write-Host &#8220;Machine Name: &#8221; $osver.CSName<br />
Write-Host &#8220;OS: &#8220;$osver.caption<br />
Write-Host &#8220;Service Pack: &#8220;$osver.csdversion<br />
Write-Host &#8220;Build #: &#8220;$osver.version<br />
Write-Host &#8220;*********** &#8221;<br />
Write-Host &#8220;Memory Installed:&#8221;<br />
Write-Host &#8220;*********** &#8221;<br />
Write-Host &#8220;Memory (GB): $memgb &#8221;<br />
Write-Host &#8220;Slots used:&#8221; $memtotal.Count<br />
Write-Host &#8220;*********** &#8221;<br />
Write-Host &#8220;Processor(s) Installed:&#8221;<br />
Write-Host &#8220;*********** &#8221;<br />
Write-Host &#8220;Sockets:&#8221; $psok<br />
Write-Host &#8220;Cores:&#8221; $pcors<br />
Write-Host &#8220;Logical Procs:&#8221; $plog<br />
Write-Host &#8220;*********** &#8221;<br />
Write-Host &#8220;Processor Details:&#8221;<br />
Write-Host &#8220;*********** &#8221;<br />
$procs<br />
Write-Host &#8220;&#8221;<br />
}</p>
<p>The correct way is to create an object and output that </p>
<p>I’ll be blogging a sample answer when the games are over.  for now be aware that write-host is worse than backticks</p>

<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/scripting-games-how-not-to-output-data/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
