<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>thescriptlad.com - ScriptingJournal</title>
	<atom:link href="http://thescriptlad.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://thescriptlad.com</link>
	<description>Powershell Scripts and Tips for the System Administrator</description>
	<lastBuildDate>Mon, 14 Nov 2011 14:02:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='thescriptlad.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>thescriptlad.com - ScriptingJournal</title>
		<link>http://thescriptlad.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://thescriptlad.com/osd.xml" title="thescriptlad.com - ScriptingJournal" />
	<atom:link rel='hub' href='http://thescriptlad.com/?pushpress=hub'/>
		<item>
		<title>Find Users Actively Connected to a Share</title>
		<link>http://thescriptlad.com/2011/08/29/find-users-actively-connected-to-a-share/</link>
		<comments>http://thescriptlad.com/2011/08/29/find-users-actively-connected-to-a-share/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 19:25:49 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[One-liners]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://thescriptlad.com/?p=134</guid>
		<description><![CDATA[The work I do for AT&#38;T deals extensively with performing data migrations; moving user and group data from one server to another.  To make the data transition easier for the active share users I send emails to them indicating when a share is going to move, and what its new location will be? Q:How do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=134&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The work I do for AT&amp;T deals extensively with performing data migrations; moving user and group data from one server to another.  To make the data transition easier for the active share users I send emails to them indicating when a share is going to move, and what its new location will be?</p>
<p><span style="color:#0000ff;"><strong>Q:How do I capture that active user information?</strong></span></p>
<p><span style="color:#008000;"><strong>A:  I use a WMI query using the class Win32_ServerConnection.</strong></span></p>
<p>With Powershell you can easily query a remote server to find out what accounts are connected to all shares, or a specific share.</p>
<p>One of the very nice things about Powershell is that you can create a &#8220;one-liner&#8221; to grab the information quickliy.  This would be used  as a quick reference.  Here is an example of a one liner to find all of the employees connected to server <strong>ServerBravo1</strong></p>
<p><span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">Get-WmiObject </span></span></span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">Win32_ServerConnection </span></span></span><span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">-ComputerName </span></span></span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;"><strong>ServerBravo1 </strong></span></span></span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">| </span></span></span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">select </span></span></span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">username</span></span></span><span style="color:#000000;">, </span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sharename</span></span></span><span style="color:#000000;">, </span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">computername</span></span></span><span style="color:#000000;"> </span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">| sort sharename |</span></span></span><span style="color:#000000;"> </span><span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">Format-Table -AutoSize</span></span></span></p>
<p><strong>Here is the break down of that command:</strong></p>
<p><em><span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">Get-WmiObject </span></span></span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">Win32_ServerConnection</span></span></span></em>: Performs the WMI query using the Get-WMIObject cmdlet.</p>
<p><em><span style="color:#5f9ea0;">-ComputerName </span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">ServerBravo1</span></span></span></em>: Runs the query on the remote server ServerBravo1.  If the -ComputerName property is excluded then the command is run on the local computer.</p>
<p><em><span style="color:#0000ff;">select<span style="color:#0000ff;"><span style="color:#0000ff;">username</span></span></span><span style="color:#000000;">, </span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sharename</span></span></span><span style="color:#000000;">, </span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">computername</span></span></span></em>:  This determines which properties are returned from the query.  I find these to be the most useful properties, but there are a lot more that can be returned.</p>
<p><strong>Here is a list of the properties that could be useful:</strong></p>
<p style="padding-left:30px;"><span style="color:#000080;">Name                           MemberType</span><br />
<span style="color:#000080;"> &#8212;-                                &#8212;&#8212;&#8212;-</span><br />
<span style="color:#000080;"> ActiveTime               Property</span><br />
<span style="color:#000080;"> Caption                       Property</span><br />
<span style="color:#000080;"> ComputerName      Property</span><br />
<span style="color:#000080;"> ConnectionID          Property</span><br />
<span style="color:#000080;"> Description              Property</span><br />
<span style="color:#000080;"> InstallDate               Property</span><br />
<span style="color:#000080;"> Name                          Property</span><br />
<span style="color:#000080;"> NumberOfFiles       Property</span><br />
<span style="color:#000080;"> NumberOfUsers     Property</span><br />
<span style="color:#000080;"> ShareName              Property</span><br />
<span style="color:#000080;"> Status                         Property</span><br />
<span style="color:#000080;"> UserName                Property</span></p>
<p><span style="color:#5f9ea0;"><span style="color:#0000ff;">sort sharename</span></span>: This sorts the results based on the value of the ShareName property.</p>
<p><span style="color:#5f9ea0;">Format-Table-AutoSize</span>: This formats the output in columns.  The <strong>-autosize</strong> option places the columns in a nice compact presentation.  Other output options include <strong>format-list</strong>, and my personal favorite <strong>out-gridview</strong>.</p>
<p>The one-liner is nice but you have to type the full text each time.  Since I use this command so much, I prefered to make a <strong>function </strong>where I can type the function name followed by a server name.  The required typing is a lot less for each use, and you don&#8217;t really need to remember the specific property names.</p>
<p>Here is how that funtion would look:</p>
<p style="text-align:center;"><strong>Function to Find Active Share Users on a Server</strong></p>
<p><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">function </span></span></span><span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">get-ShareUsers</span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">{</span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">&lt;#</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">.SYNOPSIS</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">Determine which shares are actively being used by employees.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">.DESCRIPTION</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">This provides a live time view of shares currently being accessed by employees. The output can be to the Powershell screen, the out-gridview window, a CSV file, or all of the above.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"> </span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">.PARAMETER &lt;paramName&gt;</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">ServerName &#8211; Used to determine the server to scan.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">GridView &#8211; Enables the output to the gridview.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">Export &#8211; Enables the output to a CSV file using the export-csv cmdlet.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">.EXAMPLE</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">get-ShareUsers S47715C014001</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">Description</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">&#8212;&#8212;&#8212;&#8211;</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">This command scans a server called S47715C014001 for active share users. The result is sent to the Powershell screen.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">.EXAMPLE</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">get-ShareUsers S47715C014001 -Gridview</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">Description</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">&#8212;&#8212;&#8212;&#8211;</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">This command scans a server called S47715C014001 for active share users. The result is sent to the Powershell screen, and to the out-gridview window.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">.EXAMPLE</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">get-ShareUsers S47715C014001 -Gridview -Export</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">Description</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">&#8212;&#8212;&#8212;&#8211;</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">This command scans a server called S47715C014001 for active share users. The result is sent to the Powershell screen, to the out-gridview window, and to a CSV file called S47715C014001 _Share_Users.csv</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">#&gt;</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">[<span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">CmdletBinding</span></span></span>()]</span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">Param</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">(</span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">#First parameter</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">[<span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">parameter</span></span></span>(<span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">Mandatory</span></span></span><span style="color:#ff0000;"><span style="color:#ff0000;"><span style="color:#ff0000;">=</span></span></span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">$true</span></span></span>, <span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">#Makes this a required parameter. The user will be prompted for this item if it is not provided.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">ValueFromPipeline</span></span></span><span style="color:#ff0000;"><span style="color:#ff0000;"><span style="color:#ff0000;">=</span></span></span><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">$true</span></span></span>)] <span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">#Allows the server name to be &#8220;Piped&#8221; into the function.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">[<span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">String</span></span></span>[]] <span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$ServerName</span></span></span>, <span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">#The name against which to run the query.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">#Second parameter &#8211; Sends the output to the out-gridview display.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">[<span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">switch</span></span></span>] <span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$Gridview</span></span></span>, </span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">#Third parameter &#8211; Sends the output to a CSV file for later used.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">[<span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">switch</span></span></span>] <span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$Export</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">) </span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"> </span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">#Default output to the Powershell interface.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">Get-WmiObject</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">Win32_ServerConnection</span></span></span> <span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">-ComputerName</span></span></span> <span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$ServerName</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">|</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">select</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">username</span></span></span>, <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sharename</span></span></span>, <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">computername</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">|</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sort</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sharename</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">|</span></span></span> <span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">Format-Table</span></span></span> <span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">-AutoSize</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">if</span></span></span> (<span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$Gridview</span></span></span> <span style="color:#ff0000;"><span style="color:#ff0000;"><span style="color:#ff0000;">-eq</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">$true</span></span></span>) <span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">#Use this switch if you want to output to the Out-Gridview window.</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">{</span></span></span></p>
<p style="padding-left:30px;"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">Get-WmiObject</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">Win32_ServerConnection</span></span></span> <span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">-ComputerName</span></span></span> <span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$ServerName</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">|</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">select</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">username</span></span></span>, <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sharename</span></span></span>, <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">computername</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">|</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sort</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sharename</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">|</span></span></span> <span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">Out-GridView</span></span></span> <span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">-Title</span></span></span> <span style="color:#800000;"><span style="color:#800000;"><span style="color:#800000;">&#8220;$computername Share Users&#8221;</span></span></span></span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">}</span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">if</span></span></span> (<span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$Export</span></span></span> <span style="color:#ff0000;"><span style="color:#ff0000;"><span style="color:#ff0000;">-eq</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">$true</span></span></span>) <span style="color:#008000;"><span style="color:#008000;"><span style="color:#008000;">#Use this switch if you want to output to a CSV file.</span></span></span></span></span></span><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">{</span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">[<span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">string</span></span></span>]<span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$filename</span></span></span> <span style="color:#ff0000;"><span style="color:#ff0000;"><span style="color:#ff0000;">=</span></span></span> <span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$ServerName</span></span></span><span style="color:#ff0000;"><span style="color:#ff0000;"><span style="color:#ff0000;">+</span></span></span> <span style="color:#800000;"><span style="color:#800000;"><span style="color:#800000;">&#8220;_Share_Users.csv&#8221;</span></span></span></span></span></span></p>
<p style="padding-left:30px;"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">Get-WmiObject</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">Win32_ServerConnection</span></span></span> <span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">-ComputerName</span></span></span> <span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$ServerName</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">|</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">select</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">username</span></span></span>, <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sharename</span></span></span>, <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">computername</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">|</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sort</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">sharename</span></span></span> <span style="color:#0000ff;"><span style="color:#0000ff;"><span style="color:#0000ff;">|</span></span></span> <span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">Export-Csv</span></span></span> <span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">-Path</span></span></span> <span style="color:#800080;"><span style="color:#800080;"><span style="color:#800080;">$filename</span></span></span> <span style="color:#5f9ea0;"><span style="color:#5f9ea0;"><span style="color:#5f9ea0;">-NoTypeInformation</span></span></span> </span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">}</span></span></span></p>
<p><span style="font-family:'Courier New';"><span style="font-family:'Courier New';"><span style="font-family:'Courier New';">}</span></span></span></p>
<p><strong>A few final comments:</strong></p>
<ul>
<li>To make this function available all of the time when you are using PowerShell, paste the function into your PowerShell profile document.  When you do that it will load each time you start PowerShell.</li>
</ul>
<ul>
<li>Once it is loaded into your PowerShell session, you can find help on this function by typing the following in the PowerShell command line window:</li>
</ul>
<p><em><strong>help get-shareusers -Full</strong></em></p>
<p>This will give examples of how to use the function, and also give detailed information on each of the parameters.</p>
<ul>
<li>Finally, to make it easier to use this function, I have uploaded the text of the script here at my Google page:</li>
</ul>
<p><a title="Get-ShareUsers.ps1" href="https://docs.google.com/leaf?id=0BxBTFzyyzC3NZTJhMjcxNjUtZThkOS00YjU4LTkyZmEtNDA5MGIwOGRhOTk4&amp;hl=en_US" target="_blank">Get-ShareUsers.ps1</a></p>
<p>I hope this is a helpful utility for you.</p>
<p>Please let me know if you have any questions about this, or any of my other posts.</p>
<p>Have a good day.</p>
<p>Patrick</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scriptingjournal.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scriptingjournal.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scriptingjournal.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scriptingjournal.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scriptingjournal.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scriptingjournal.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scriptingjournal.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scriptingjournal.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scriptingjournal.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scriptingjournal.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scriptingjournal.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scriptingjournal.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scriptingjournal.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scriptingjournal.wordpress.com/134/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=134&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thescriptlad.com/2011/08/29/find-users-actively-connected-to-a-share/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb8c6355d03ba59222ca8d70f4055bb8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">w4pwp</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Run a PowerShell Script from Batch File</title>
		<link>http://thescriptlad.com/2011/08/16/run_ps_from_a_batchfile/</link>
		<comments>http://thescriptlad.com/2011/08/16/run_ps_from_a_batchfile/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 16:27:39 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[System Administration]]></category>

		<guid isPermaLink="false">http://thescriptlad.com/?p=121</guid>
		<description><![CDATA[A friend was lamenting to me recently that there was an aspect of Powershell that he found annoying. He didn&#8217;t like the fact that you had to open a PowerShell command line window to run a script. Well guess what, dear friend &#8211; you don&#8217;t really need to do that! Purpose: This blog entry details [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=121&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A friend was lamenting to me recently that there was an aspect of Powershell that he found annoying. He didn&#8217;t like the fact that you had to open a PowerShell command line window to run a script. Well guess what, dear friend &#8211; you don&#8217;t really need to do that! <img class="alignnone size-medium wp-image-122" title="image001" src="http://scriptingjournal.files.wordpress.com/2011/08/image001.gif?w=18&#038;h=18" alt="" width="18" height="18" /></p>
<p><strong>Purpose:</strong></p>
<p>This blog entry details the quick and easy method for running a PowerShell script from a shortcut on your desktop. To get started let’s have a quick little script on hand to test how this works.</p>
<p>1. Open notepad, copy the below text into it, and save it as <strong>PowerShellTest.ps1</strong>. Keep track of where you save it.</p>
<p>$name = Read-Host &#8220;What is your name?&#8221; #Get name from CLI.</p>
<p>$quest = Read-Host &#8220;What is your quest?&#8221; #Get quest fromCLI</p>
<p>$windowObject = new-object -comobject wscript.shell #Create windows message box object.</p>
<p>$output = $windowObject.popup(&#8220;Hello $name.`nYour quest sounds exciting!&#8221;,0,&#8221;Quest: $quest&#8221;,1) #Display the message.</p>
<p>Now, here is how you can open that script in Powershell by just clicking on an icon.</p>
<p>2. Where ever you saved <strong>PowerShellTest.ps1</strong>, right click and select <strong>New Document</strong>.</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/08/image011.jpg"><img class="alignnone size-medium wp-image-128" title="image011" src="http://scriptingjournal.files.wordpress.com/2011/08/image011.jpg?w=271&#038;h=175" alt="" width="271" height="175" /></a></p>
<p>3. Name the file &#8220;<strong>PowerShellTest.cmd</strong>&#8220;. The <strong>cmd</strong> is used to assign a file extension type of command to the text file. This lets it operate as an executable file.</p>
<p>4. You will see the following popup message:</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/08/image004.jpg"><img class="alignnone size-medium wp-image-123" title="image004" src="http://scriptingjournal.files.wordpress.com/2011/08/image004.jpg?w=300&#038;h=84" alt="" width="300" height="84" /></a></p>
<p>Select &#8220;<strong>Yes</strong>&#8221; to confirm.</p>
<p>5. Now right click the PowerShellTest.cmd file that you just made, and select &#8220;<strong>Edit</strong>&#8220;. This will open up the CMD file in Notepad, and allow you to finish this process.</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/08/image005.jpg"><img class="alignnone size-medium wp-image-124" title="image005" src="http://scriptingjournal.files.wordpress.com/2011/08/image005.jpg?w=179&#038;h=300" alt="" width="179" height="300" /></a></p>
<p>6. Inside of the cmd file, type in &#8220;Powershell.exe&#8221;, a space, and then the name of the PowerShell file you made in step 1.</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/08/image006.jpg"><img class="alignnone size-medium wp-image-125" title="image006" src="http://scriptingjournal.files.wordpress.com/2011/08/image006.jpg?w=300&#038;h=75" alt="" width="300" height="75" /></a></p>
<p>Notice that I added <strong>&#8220;.&#8221;</strong> to the front of the file name. This is required by Powershell to help indicate that this is a file, and not a variable. It is called &#8220;<strong>Dot Sourcing</strong>&#8221; in Powershell.</p>
<p>The actual text I used is: <strong>Powershell.exe .PowerShellTest.ps1</strong></p>
<p>7. <strong>Save </strong>and then <strong>close </strong>the CMD file to continue.</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/08/image012.jpg"><img class="alignnone size-medium wp-image-129" title="image012" src="http://scriptingjournal.files.wordpress.com/2011/08/image012.jpg?w=300&#038;h=93" alt="" width="300" height="93" /></a></p>
<p>8. Now, to test the final product, <strong>double-click on the CMD file that you made in steps 3 and 4</strong>. You will get the following result:</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/08/image009.jpg"><img class="alignnone size-medium wp-image-126" title="image009" src="http://scriptingjournal.files.wordpress.com/2011/08/image009.jpg?w=300&#038;h=62" alt="" width="300" height="62" /></a></p>
<p>You are going to be prompted for your <em><strong>name</strong></em>, and your <em><strong>quest</strong></em>. Just make up something dreadfully clever for each. Once you type the text, press <strong>Enter </strong>for each line. After your final entry a message box is displayed, indicating the the script has completed.</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/08/image010.jpg"><img class="alignnone size-medium wp-image-127" title="image010" src="http://scriptingjournal.files.wordpress.com/2011/08/image010.jpg?w=230&#038;h=143" alt="" width="230" height="143" /></a></p>
<p>So, there you go. You were able to run a PowerShell script by simply clicking on a CMD text file. I generally store the CMD file with the PowerShell script file to make them quickly accessible.</p>
<p><strong>Summary:</strong></p>
<p>While this program is simple, it does highlight the method for opening a PowerShell script from Windows Explorer. Incidentally, it shows the method to prompt a script user for input, and also shows how to display a Windows message box output.</p>
<p><em>As always, let know if you have any questions or comments.</em></p>
<p><em>Thank you, Patrick</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scriptingjournal.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scriptingjournal.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scriptingjournal.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scriptingjournal.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scriptingjournal.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scriptingjournal.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scriptingjournal.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scriptingjournal.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scriptingjournal.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scriptingjournal.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scriptingjournal.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scriptingjournal.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scriptingjournal.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scriptingjournal.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=121&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thescriptlad.com/2011/08/16/run_ps_from_a_batchfile/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb8c6355d03ba59222ca8d70f4055bb8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">w4pwp</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/08/image001.gif?w=18" medium="image">
			<media:title type="html">image001</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/08/image011.jpg?w=271" medium="image">
			<media:title type="html">image011</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/08/image004.jpg?w=300" medium="image">
			<media:title type="html">image004</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/08/image005.jpg?w=179" medium="image">
			<media:title type="html">image005</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/08/image006.jpg?w=300" medium="image">
			<media:title type="html">image006</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/08/image012.jpg?w=300" medium="image">
			<media:title type="html">image012</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/08/image009.jpg?w=300" medium="image">
			<media:title type="html">image009</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/08/image010.jpg?w=230" medium="image">
			<media:title type="html">image010</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting the Directory Size on Remote Servers.</title>
		<link>http://thescriptlad.com/2011/04/16/get-remote-dir-size/</link>
		<comments>http://thescriptlad.com/2011/04/16/get-remote-dir-size/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 17:50:53 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[dir size]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[out-gridview]]></category>
		<category><![CDATA[remote get-childitem]]></category>

		<guid isPermaLink="false">http://thescriptlad.com/?p=108</guid>
		<description><![CDATA[Greetings Kenny In regards to your question on scanning for a directory size&#8230; I think I would use a different approach for finding the results of a remote directory size.  A good choice for this is the &#8220;Get-ChildItem&#8221; cmdlette. The DOS version of this is simply the DIR command. Unlike VBScript, Powershell doesn&#8217;t have a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=108&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Greetings Kenny</p>
<p>In regards to your question on scanning for a directory size&#8230;</p>
<p>I think I would use a different approach for finding the results of a remote directory size.  A good choice for this is the &#8220;Get-ChildItem&#8221; cmdlette.</p>
<p>The DOS version of this is simply the DIR command.</p>
<p>Unlike VBScript, Powershell doesn&#8217;t have a direct method for getting a folder size, but there is a work around. You can use the “Measure-Object –Sum” cmdlette and properties to calculate the data.</p>
<p>Let’s say I want to calculate the size of the c:\temp directory on my local computer.</p>
<p>The command would look like this:</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/04/pp1071_1302974953902.jpg"><img class="alignleft size-full wp-image-109" title="get-children" src="http://scriptingjournal.files.wordpress.com/2011/04/pp1071_1302974953902.jpg?w=630" alt=""   /></a></p>
<p>We are creating a resulting PowerShell object with the properties of count, average, sum, etc.</p>
<p>We are only assigning a value to Sum.</p>
<p><strong>So how would that be used to calculate the size of a folder on a remote server?</strong>  Instead of using “c:\temp” you could put in any path, including a URL.  Here is the conceptual example.</p>
<p>I am using <strong>–recurse</strong> to check all subfolders, and <strong>–force</strong> to check hidden and system files.</p>
<p><em>Get-ChildItem \\servername\c$\temp -recurse -force | select Length |Measure-Object -Sum length</em></p>
<p>In your comment you indicated that you wanted to check the size of <strong>E:\VM</strong> on multiple servers.  You could pull the server name out of a text file.  The text file could be called server.txt</p>
<p>Assuming I put the file containing my list of servers to check at c:\servers.txt, the command could like this.</p>
<p><em>$path = &#8220;\\<span style="text-decoration:underline;">$serverName\E$\VM</span>&#8220;</em></p>
<p><em>foreach ($serverName in (get-content <span style="text-decoration:underline;">c:\servers.txt))</span></em></p>
<p><em>{</em></p>
<p><em>       $dirSize = Get-ChildItem $path -recurse -force | select Length  |Measure-Object -Sum length     </em></p>
<p><em>       $dirSize #Output the result to the screen.</em></p>
<p><em>}</em></p>
<p>That works, but the result is kind of awkward as output is in bytes instead of MB.</p>
<p>We can dress this up by applying formatting to the result, and converting to MB.</p>
<p><em>…</em></p>
<p><em>$dirSize = Get-ChildItem $path -recurse -force | select Length  |Measure-Object -Sum length</em></p>
<p><em>$dirSize.sum = $dirSize.sum/1MB</em></p>
<p><em>$finalResult = &#8220;{0:N2} MB&#8221; -f $result.sum</em></p>
<p><em>…</em></p>
<p>Now the resulting directory size would be in MB.</p>
<p>One more way to improve this would be to collect each iteration of the <strong>“foreach”</strong> cmdlette, and put into an object so that would could get the result into a CSV file, or maybe output to the <strong>out-gridview</strong> cmdlette.</p>
<p>Here is the result of all that code..</p>
<p><em>$dataColl = @()#Makes an array, or a collection to hold all the object of the same fields.</em></p>
<p><em>foreach ($serverName in (get-content <span style="text-decoration:underline;">c:\servers.txt))</span></em></p>
<p><em>{</em></p>
<p><em>       $path = &#8220;\\<span style="text-decoration:underline;">$serverName\e$\VM</span>&#8220;</em></p>
<p><em>       $dirSize = Get-ChildItem $path -recurse -force | select Length  |Measure-Object -Sum                   length</em></p>
<p><em>       $dirSize.sum = $dirSize.sum/1MB</em></p>
<p><em>       $finalResult = &#8220;{0:N2} MB&#8221; -f $result.sum</em></p>
<p><em>       $dataObject = New-Object PSObject</em></p>
<p><em>       Add-Member -inputObject $dataObject -memberType NoteProperty -name &#8220;ServerName&#8221; -value                 $serverName</em></p>
<p><em>       Add-Member -inputObject $dataObject -memberType NoteProperty -name &#8220;Dir_Size&#8221; -value                   $finalResult</em></p>
<p><em>       $dataColl += $dataObject  </em></p>
<p><em>       $dataObject</em></p>
<p><em>}</em></p>
<p><em>$dataColl | Out-GridView -Title &#8220;Remote Directory Scan Results&#8221;</em></p>
<p><em>$dataColl | Export-Csv -noTypeInformation -path <span style="text-decoration:underline;">c:\temp.csv</span></em></p>
<p>Here is the resulting <strong>“Out-GridView”</strong>.  I’ve smudged out the actual server names I used.</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/04/pp1071_13029749539331.jpg"><img class="alignleft size-full wp-image-111" title="out-gridview" src="http://scriptingjournal.files.wordpress.com/2011/04/pp1071_13029749539331.jpg?w=630" alt=""   /></a></p>
<p>The resulting output is also available in the temp.CSV file at the root of my C: drive.</p>
<p>Depending on your number of servers, network, and folder sizes this could take a while to run.  I would save it to a script and run it from a separate Powershell window so you don’t have to stare at it while it runs.</p>
<p>Please let me know if this helps, and if you have any further questions.</p>
<p>Have a nice day.</p>
<p>Patrick</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scriptingjournal.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scriptingjournal.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scriptingjournal.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scriptingjournal.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scriptingjournal.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scriptingjournal.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scriptingjournal.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scriptingjournal.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scriptingjournal.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scriptingjournal.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scriptingjournal.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scriptingjournal.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scriptingjournal.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scriptingjournal.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=108&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thescriptlad.com/2011/04/16/get-remote-dir-size/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb8c6355d03ba59222ca8d70f4055bb8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">w4pwp</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/04/pp1071_1302974953902.jpg" medium="image">
			<media:title type="html">get-children</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/04/pp1071_13029749539331.jpg" medium="image">
			<media:title type="html">out-gridview</media:title>
		</media:content>
	</item>
		<item>
		<title>Get-DriveSpace on One or Multiple Computers</title>
		<link>http://thescriptlad.com/2011/03/08/get-drivespace-on-one-or-multiple-computers/</link>
		<comments>http://thescriptlad.com/2011/03/08/get-drivespace-on-one-or-multiple-computers/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 15:09:40 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[One-liners]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[diskspace]]></category>
		<category><![CDATA[free disk space]]></category>
		<category><![CDATA[one liner]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://scriptingjournal.wordpress.com/?p=79</guid>
		<description><![CDATA[One common administrative task is to find the  available disk space on a server.  The standard methods to do this are connecting to the computer remotely to verify disk space, and using VBScript scripting to gather the data.  But there is a better way&#8230; With Powershell&#8217;s extensive use of WMI and the &#8220;piping&#8221; options, a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=79&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One common administrative task is to find the  available disk space on a server.  The standard methods to do this are connecting to the computer remotely to verify disk space, and using VBScript scripting to gather the data.  But there is a better way&#8230;</p>
<p>With Powershell&#8217;s extensive use of WMI and the &#8220;piping&#8221; options, a very useful one-liner can be used to retrieve the disk space for one or more servers.</p>
<p>Here is the WMI property that we will be using: <strong>Win32_LogicalDisk</strong>.</p>
<p><strong>To find the disk space available for one computer you would use this one-liner:</strong></p>
<p style="padding-left:30px;"><span style="color:#0000ff;">get-wmiobject Win32_LogicalDisk -computername Server001 | select __server, Name, Description, FileSystem, @{Label=&#8221;Size&#8221;;Expression={&#8220;{0:n0} MB&#8221; -f ($_.Size/1mb)}}, @{Label=&#8221;Free Space&#8221;;Expression={&#8220;{0:n0} MB&#8221; -f ($_.FreeSpace/1mb)}} | out-gridview -Title &#8220;Disk Space Scan Results&#8221;</span></p>
<p>Lets take a look at the different sections of that one-liner.</p>
<p><strong>get-wmiobject Win32_LogicalDisk -computername Server001 |</strong></p>
<p>This is the standard cmdlette for accessing WMI in Powershell.  The number of available WMI classes is quite extensive.  In the above example, -computername would be followed by a valid computer name. The output of that is piped  into the  Select-Object cmdlette.</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">select __server, Name, Description, FileSystem, @{Label=&#8221;Size&#8221;;Expression={&#8220;{0:n0} MB&#8221; -f ($_.Size/1mb)}}, @{Label=&#8221;Free Space&#8221;;Expression={&#8220;{0:n0} MB&#8221; -f ($_.FreeSpace/1mb)}} |</span></p>
<p>Select-Object, in this one-liner aliased as <strong>select</strong>, allows us to choose which properties of the returned query we want to use.  By default the Win32_LogicalDisk class provides us with the following properties:</p>
<p>DeviceID     : C:</p>
<p>DriveType    : 3</p>
<p>ProviderName :</p>
<p>FreeSpace    : 10997723136</p>
<p>Size         : 21478666240</p>
<p>VolumeName   : C_Drive</p>
<p>We do two things differently with our one-liner. First we grab an extra property that is always available, but not always needed.  We are requesting the <strong>&#8220;__server&#8221;</strong> property.  This will be useful when we put everything in columns later on, and really useful when we are asking for the disk space on multiple servers.</p>
<p>The second thing we are doing differently is to apply formatting to the &#8220;Size: Property and &#8220;Free Space&#8221; property. If you notice above the output is in bytes.  We are use to thinking of hard drives in MB or GB, not bytes.  That is way too weird.  So we are going to created two calculated properties.  There is a calculated property for &#8220;freespace&#8221; and &#8220;size&#8221;.</p>
<p>The calculated property is much simpler than it might first appear. To specify a calculated property we need to create a hash table; that’s what the @{} syntax does for us.  Inside the curly braces we specify the two elements of our hash table: the property Label (in this case Size or Free Space) and the property Expression (that is, the script block we’re going to use to calculate the property value).  The Label property is easy enough to specify; we simply assign a string value to the Name, like so:</p>
<p><strong>Label=&#8221;Size&#8221; and Label=&#8221;Free Space&#8221;</strong></p>
<p>And, believe it or not, the <strong>Expression property</strong> (which is separated from the name by a semicolon) isn’t much harder to configure; the only difference is that Expression gets assigned a script block rather than a string value:</p>
<p>Expression={&#8220;{0:n0} MB&#8221; -f ($_.Size/1mb)}} and Expression={&#8220;{0:n0} MB&#8221; -f ($_.FreeSpace/1mb)}} are the expressions we are using.  So what actually is going on here?</p>
<p><strong>Using .NET to Format Numbers in Windows PowerShell</strong></p>
<p><strong> </strong></p>
<p>Powershell doesn’t have any built-in functions or cmdlettes for formatting numbers. But that’s OK; we don’t need any built-in functions or cmdlettes. Instead, we can use the .NET Framework formatting methods.</p>
<p>The heart-and-soul of our command is this little construction: “{0:N0}”. That’s a crazy-looking bit of code to be sure, but it’s also a bit of code that can easily be dissected:</p>
<p>The initial 0 (That&#8217;s a zero)  (the one that comes before the colon) represents the index number of the item to be formatted. For the time being, leave that at 0 and everything should work out just fine.</p>
<p>The N represents the type of format to be applied; in this case, the N is short for Numeric. Are there other types of formats we can apply? Yes there are, and we’ll show you a few of those in just a moment.</p>
<p>The second 0 (the one after the N) is known as the “precision specifier,” and, with the Numeric format, indicates the number of decimal places to be displayed. In this case we don’t want any decimal places, so we set this parameter to 0. Suppose we wanted to display three decimal places? No problem; this command takes care of that: &#8220;{0:N3}&#8221; -f $a. Run that command and you’ll end up with output that looks like this: 19,385,790,464.000.</p>
<p>That’s about all we have to do; after specifying the format type we tack on the –f (format) parameter, then follow that by indicating the value we want to format $_.FreeSpace and $_.Size.</p>
<p>In our one-liner we are dividing the number variables $_.size and $_.freespace by the Powershell constant mb. We could do kb or gb as well. It depends what output you want to see.</p>
<p>For a more extensive discussion on .net formatting, please go here:</p>
<p style="padding-left:30px;"><a title="http://technet.microsoft.com/en-us/library/ee692795.aspx" href="http://technet.microsoft.com/en-us/library/ee692795.aspx" target="_blank">http://technet.microsoft.com/en-us/library/ee692795.aspx</a></p>
<p style="padding-left:30px;"><a title="http://technet.microsoft.com/en-us/library/ee692795.aspx" href="http://technet.microsoft.com/en-us/library/ee692795.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx</a></p>
<p>This is the source I used for much of this information.</p>
<p>The final section of the one-liner outputs the results to the Out-Gridview window.  I have modified the &#8220;title&#8221; property so that it shows what we are attempting to do with the query.</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">| out-gridview -Title &#8220;Disk Space Scan Results&#8221;</span></p>
<p><span style="color:#0000ff;"> </span></p>
<p>&nbsp;</p>
<p><strong>The above information details how to find the disk space for one server.  Because the &#8220;computername&#8221; property of the Get-WmiObject cmdlette will accept an array, or a single string.  This allows us to check mutiple servers with the same one liner.  This can be done two ways.</strong></p>
<p>In the first method, the computer names can be directly type into the one liner:</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">get-wmiobject Win32_LogicalDisk -computername server1, server2, server3</span></p>
<p>In the second method the computer names can be read from a test file using the get-content cmdlette.</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">get-wmiobject Win32_LogicalDisk -computername (Get-Content c:\temp\computers.txt) `</span></p>
<p><span style="color:#0000ff;">select __server, Name, Description, FileSystem, @{Label=&#8221;Size&#8221;;Expression={&#8220;{0:n0} MB&#8221; -f ($_.Size/1mb)}},`</span></p>
<p><span style="color:#0000ff;"> @{Label=&#8221;Free Space&#8221;;Expression={&#8220;{0:n0} MB&#8221; -f ($_.FreeSpace/1mb)}}`</span></p>
<p><span style="color:#0000ff;"> | out-gridview -Title &#8220;Disk Space Scan Results&#8221;</span></p>
<p>I prefer the second method because you can gather the disk information on many servers very quickly.</p>
<p>Please let me know if you have any questions about this procedure.  I would be glad to explain anything, or answer any questions.</p>
<p>Thanks,</p>
<p>Patrick</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scriptingjournal.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scriptingjournal.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scriptingjournal.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scriptingjournal.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scriptingjournal.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scriptingjournal.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scriptingjournal.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scriptingjournal.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scriptingjournal.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scriptingjournal.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scriptingjournal.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scriptingjournal.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scriptingjournal.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scriptingjournal.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=79&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thescriptlad.com/2011/03/08/get-drivespace-on-one-or-multiple-computers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb8c6355d03ba59222ca8d70f4055bb8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">w4pwp</media:title>
		</media:content>
	</item>
		<item>
		<title>Test Multiple Network Locations with Test-Path</title>
		<link>http://thescriptlad.com/2011/02/28/powershell_test_published-docx/</link>
		<comments>http://thescriptlad.com/2011/02/28/powershell_test_published-docx/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 19:22:43 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[test-path]]></category>

		<guid isPermaLink="false">http://scriptingjournal.wordpress.com/?p=68</guid>
		<description><![CDATA[Frequently we relocate a large number of employee home folders in bulk and we need to verify that the move was successful, or we want to test the validity of a large number of network shared folders. This utility does that utilizing the Powershell test-path commandlette. If you want a basic understanding of how the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=68&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Frequently we relocate a large number of employee home folders in bulk and we need to verify that the move was successful, or we want to test the validity of a large number of network shared folders. This utility does that utilizing the Powershell <strong>test-path</strong> commandlette.</p>
<p>If you want a basic understanding of how the <strong>test-path</strong> commandlette works, type this in your Powershell console window:</p>
<p><em>get-help test-path –full</em></p>
<p>Here is a general description of what this script utility, <strong>Test-Paths.ps1</strong> does:</p>
<p><strong>.SYNOPSIS</strong></p>
<p>This script will test the validity of paths that are contained in the paths.ini file. Output is generated to a CSV file, and to Out-GridView.</p>
<p><strong>.DESCRIPTION</strong></p>
<p>The targets of the test-path command are pulled from the <strong>“paths.ini”</strong> file that is collocated with the test-paths.ps1 file.</p>
<p>Each target is tested using the Powershell test-path commandlette. Results are stored along with the path name in two output methods.</p>
<p>out-gridview and filename.csv</p>
<p><strong>.PARAMETERS </strong></p>
<p>-nogridview: Prevents the script from generating the Out-GridView window.</p>
<p>-noexport: Prevents the script from generating the exported CSV file.</p>
<p>-outfile filename.csv: Use an alternative name for the output file. CSV extension is best. The default if this switch is not added is <strong>testpathresult.csv</strong>.</p>
<p><strong>.EXAMPLES</strong></p>
<p>This will give two outputs. A file named testpathresult.csv and the out-gridview window:</p>
<p><span style="color:#000080;">.\test-paths.ps1</span></p>
<p>This example will give no out-gridview window, but will save a CSV file named patrick.csv:</p>
<p><span style="color:#000080;">.\test-paths.ps1 -nogridview -outfile patricks.csv</span></p>
<p>This example will give only the out-gridview window:</p>
<p><span style="color:#000080;">.\test-paths.ps1 –noexport</span></p>
<p>Here are a couple of examples with the script in action<strong>. In this first one I will get all failed status results for the test-path commands, but that is because I am using simulated directory paths</strong>.</p>
<p>Here are the contents of the paths.ini file which is collocated with the script:</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/02/image011.jpg"><img class="alignnone size-full wp-image-71" title="image011" src="http://scriptingjournal.files.wordpress.com/2011/02/image011.jpg?w=630" alt=""   /></a></p>
<p><strong>Figure 1: Contents of Paths.ini File</strong></p>
<p>Here are a few screen shots of the utility being run, and some of the selected output screen shots.</p>
<p><span style="color:#000080;">.\test-paths.ps1</span></p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/02/image003.png"><img class="alignnone size-full wp-image-69" title="image003" src="http://scriptingjournal.files.wordpress.com/2011/02/image003.png?w=630" alt=""   /></a></p>
<p><strong>Figure 2: Command Window Output</strong></p>
<p>You can see that the Powershell command window echoes the target currently being tested.</p>
<p>Since the above example did not use either the of the two exclusion switches, both <strong>out-gridview</strong> and a <strong>CSV</strong> file were generated. Here are images of both types of output:</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/02/image012.jpg"><img class="alignnone size-full wp-image-72" title="image012" src="http://scriptingjournal.files.wordpress.com/2011/02/image012.jpg?w=630" alt=""   /></a></p>
<p><strong>Figure 3: Out-gridview</strong></p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/02/image013.jpg"><img class="alignnone size-full wp-image-73" title="image013" src="http://scriptingjournal.files.wordpress.com/2011/02/image013.jpg?w=630" alt=""   /></a></p>
<p><strong>Figure 4: Testpathresult.CSV File</strong></p>
<p>Notice there are two columns in Figure 3: Accessible and HomeDirPath. In each of these the path tested was shown as <strong>False</strong> because the path was not found.</p>
<p>Here is another example, but this one excludes the export to the CSV file.</p>
<p><span style="color:#000080;">.\test-paths.ps1 –noexport</span></p>
<p>I added “c:windows” to the paths.ini file to show that the test-path can actually find a valid path. With this one we still see the out-gridview window, but no CSV file is generated. Notice that now we have a True in the Accessible column.</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/02/image014.jpg"><img class="alignnone size-full wp-image-74" title="image014" src="http://scriptingjournal.files.wordpress.com/2011/02/image014.jpg?w=630" alt=""   /></a></p>
<p><strong>Figure 5: True Path Now Found</strong></p>
<p>And finally, the last example where an alternate output file name is generated using the –outfile parameter:</p>
<p><span style="color:#000080;">.\test-paths.ps1 –outfile february28th.csv -nogridview</span></p>
<p>With this one no out-gridview window is generated, but the output file is unique and will not be overwritten the next time the utility is run.</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/02/image010.png"><img class="alignnone size-full wp-image-70" title="image010" src="http://scriptingjournal.files.wordpress.com/2011/02/image010.png?w=630" alt=""   /></a></p>
<p><strong>Figure 6: Alternate Output File Naming</strong></p>
<p>In summary, this utility provides an easy way to test a few, or thousands of network paths very easily.</p>
<p>It is run in a Windows Powershell environment. The target paths are inserted in the paths.ini text file, and the command is run as detailed above.</p>
<p>Let me know if you have any questions about this.</p>
<p>Thanks</p>
<p>Patrick Parkison</p>
<p><strong>Below is the code used in the test-paths.ps1 script.</strong></p>
<p><span style="color:#008000;"><strong>###################################################################################</strong></span></p>
<p><span style="color:#008000;">&lt;#</span></p>
<p><span style="color:#008000;">.Patrick Parkison</span></p>
<p><span style="color:#008000;">pp1071@att.com</span></p>
<p><span style="color:#008000;">.SYNOPSIS</span></p>
<p><span style="color:#008000;">This script will test the validity of paths that are contained in the paths.ini file. Output is generated to a CSV file, and to Out-GridView.</span></p>
<p><span style="color:#008000;">.DESCRIPTION</span></p>
<p><span style="color:#008000;">The targets of the test-path command are pulled from the “paths.ini” file that is co-located with the test-paths.ps1 file.</span></p>
<p><span style="color:#008000;">Each target is tested using the Powershell test-path commandlette. Results are stored along with the path name in two output methods.</span></p>
<p><span style="color:#008000;">out-gridview and filename.csv</span></p>
<p><span style="color:#008000;">.PARAMETER</span></p>
<p><span style="color:#008000;">-nogridview: Prevents the script from generating the Out-GridView window.</span></p>
<p><span style="color:#008000;">-noexport: Prevents the script from generating the exported CSV file.</span></p>
<p><span style="color:#008000;">-outfile: Use an alternative name for the output file. CSV extension is best. The default if this switch is not added is testpathresult.csv</span></p>
<p><span style="color:#008000;">.EXAMPLES</span></p>
<p><span style="color:#008000;">This will give two outputs. A file named testpathresult.csv and the out-gridview window:</span></p>
<p><span style="color:#008000;">.\test-paths.ps1</span></p>
<p><span style="color:#008000;">This example will give no out-gridview window, but will save a CSV file named patrick.csv:</span></p>
<p><span style="color:#008000;">.\test-paths.ps1 -nogridview -outfile patricks.csv</span></p>
<p><span style="color:#008000;">This example will give only the out-gridview window:</span></p>
<p><span style="color:#008000;">.\test-paths.ps1 -noexport</span></p>
<p><span style="color:#008000;">#&gt;</span></p>
<p><span style="color:#000000;">param([switch] $noGridview, [switch] $noExport, [string]$outfile = &#8220;testpathresult.csv&#8221;)</span></p>
<p><span style="color:#008000;">#Change the title bar of the script window. This is helpful for long running scripts.</span></p>
<p>$Host.UI.RawUI.WindowTitle = &#8220;Running test-path utility.&#8221;</p>
<p><span style="color:#008000;">#Makes an array, or a collection to hold all the object of the same fields.</span></p>
<p>$dataColl = @()</p>
<p><span style="color:#008000;">#Get location of the script. Info will be used for getting location of all test targetrs, and for saving output to the same folder.</span></p>
<p>function Get-ScriptPath</p>
<p>{</p>
<p style="padding-left:30px;">Split-Path $myInvocation.ScriptName</p>
<p>}</p>
<p><span style="color:#008000;">#ScriptPath will be used to place the output file.</span></p>
<p>$scriptPath = get-scriptpath</p>
<p><span style="color:#008000;">#Paths.ini is a text file containing a list of targets e.g. \servernamesharename</span></p>
<p>$sourcefile = $scriptPath + &#8220;paths.ini&#8221;</p>
<p><span style="color:#008000;">&lt;#</span></p>
<p><span style="color:#008000;">This is the output CSV file. It is overwritten each time the script is run.</span></p>
<p><span style="color:#008000;">If a historical record is desired, a date can be appended to the file name. See this reference on how to do that: </span><a href="http://thescriptlad.com/?s=date"><span style="color:#008000;">http://thescriptlad.com/?s=date</span></a></p>
<p><span style="color:#008000;">#&gt;</span></p>
<p>$outputfile = $scriptPath + &#8220;&#8221; + $outfile</p>
<p>foreach ($path in (gc $sourcefile)){</p>
<p style="padding-left:30px;">$dataObject = New-Object PSObject</p>
<p style="padding-left:30px;">Write-Host &#8220;Scanning: $path&#8221;</p>
<p style="padding-left:30px;">Add-Member -inputObject $dataObject -memberType NoteProperty -name &#8220;Accessible&#8221; -value (Test-Path $path )</p>
<p style="padding-left:30px;">Add-Member -inputObject $dataObject -memberType NoteProperty -name &#8220;HomeDirPath&#8221; -value $path</p>
<p style="padding-left:30px;">$dataColl += $dataObject</p>
<p>}</p>
<p><span style="color:#008000;">#This section is used to generate the out-gridview display.</span></p>
<p>if (!$noGridview)</p>
<p>{</p>
<p style="padding-left:30px;">$label = &#8220;Test-Path Results. Total Responses: &#8221; + $dataColl.count</p>
<p style="padding-left:30px;">$dataColl | Out-GridView -Title $label</p>
<p>}</p>
<p><span style="color:#008000;">#Output to the CSV file for use in Excel.</span></p>
<p>if (!$noExport)</p>
<p>{</p>
<p style="padding-left:30px;">$dataColl | Export-Csv -noTypeInformation -path $outputfile</p>
<p>}</p>
<p><span style="color:#008000;">#Restore the default command window title bar.</span></p>
<p>$Host.UI.RawUI.WindowTitle = $(get-location)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scriptingjournal.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scriptingjournal.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scriptingjournal.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scriptingjournal.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scriptingjournal.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scriptingjournal.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scriptingjournal.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scriptingjournal.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scriptingjournal.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scriptingjournal.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scriptingjournal.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scriptingjournal.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scriptingjournal.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scriptingjournal.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=68&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thescriptlad.com/2011/02/28/powershell_test_published-docx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb8c6355d03ba59222ca8d70f4055bb8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">w4pwp</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/image011.jpg" medium="image">
			<media:title type="html">image011</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/image003.png" medium="image">
			<media:title type="html">image003</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/image012.jpg" medium="image">
			<media:title type="html">image012</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/image013.jpg" medium="image">
			<media:title type="html">image013</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/image014.jpg" medium="image">
			<media:title type="html">image014</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/image010.png" medium="image">
			<media:title type="html">image010</media:title>
		</media:content>
	</item>
		<item>
		<title>Voice Spoken Weather Report</title>
		<link>http://thescriptlad.com/2011/02/26/voiced-weather-report/</link>
		<comments>http://thescriptlad.com/2011/02/26/voiced-weather-report/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 22:24:51 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[tts engine]]></category>
		<category><![CDATA[voice]]></category>

		<guid isPermaLink="false">http://scriptingjournal.wordpress.com/?p=62</guid>
		<description><![CDATA[Here is a Powershell script that is fun, and useful if you like to be able to get a spoken weather report quickly.  It uses the SAPI com object in Windows to convert text to voice. If you have more than one TTS engine on your PC, you will be able to modify it under [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=62&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is a Powershell script that is fun, and useful if you like to be able to get a spoken weather report quickly.  It uses the SAPI com object in Windows to convert text to voice. If you have more than one TTS engine on your PC, you will be able to modify it under the Windows Control Panel.</p>
<p>To start with you will need to create a function that will be used to convert text to voice.</p>
<p><span style="color:#000080;"><em>function say</em></span></p>
<p><span style="color:#000080;"><em>{</em></span></p>
<p style="padding-left:30px;"><span style="color:#000080;"><em>$Voice = new-object -com SAPI.SpVoice #Make a voice object using the com object.</em></span></p>
<p style="padding-left:30px;"><span style="color:#000080;"><em>$Voice.Speak( $Args[0], 0 )|out-null</em></span></p>
<p><span style="color:#000080;"><em>}</em></span></p>
<p>The second part of this script comes from /\/\o\/\/. You&#8217;ll find a detailed post on how to connect to a web-service to capture weather information.  That is located here:</p>
<p><a title="MOW'S Reference" href="http://thepowershellguy.com/blogs/posh/archive/2009/05/15/powershell-v2-get-weather-function-using-a-web-service.aspx" target="_blank">http://thepowershellguy.com/blogs/posh/archive/2009/05/15/powershell-v2-get-weather-function-using-a-web-service.aspx</a></p>
<p>What I&#8217;ve done is to put his work into a function that allows you to select a country or city based on command line parameters, and then speak the results over your computer speakers. <strong>If you select the -help parameter and use the -country countryname parameter, all of the cities for your country will be selected.</strong></p>
<p><strong>Here is that function:</strong></p>
<p><span style="color:#000080;"><em>Function Get-Weather ([switch]$help,$city,$country,$filter = &#8221;)</em></span></p>
<p><span style="color:#003366;"><em>{</em></span></p>
<p style="padding-left:30px;"><span style="color:#003366;"><em>$weather = New-WebServiceProxy -uri http://www.webservicex.com/globalweather.asmx?WSDL</em></span></p>
<p style="padding-left:30px;"><span style="color:#003366;"><em>if ($help)</em></span></p>
<p style="padding-left:30px;"><span style="color:#003366;"><em>{</em></span></p>
<p style="padding-left:60px;"><span style="color:#003366;"><em>write-host &#8220;Starting help.&#8221; </em></span></p>
<p style="padding-left:60px;"><span style="color:#003366;"><em>$xml = [xml]$weather.GetCitiesByCountry($Country)</em></span></p>
<p style="padding-left:60px;"><span style="color:#003366;"><em>$xml.NewDataSet.table | sort city | Out-GridView</em></span></p>
<p style="padding-left:30px;"><span style="color:#003366;"><em>} </em></span><br />
<span style="color:#003366;"><em> else </em></span></p>
<p style="padding-left:30px;"><span style="color:#003366;"><em>{</em></span></p>
<p style="padding-left:60px;"><span style="color:#003366;"><em>([xml]$weather.GetWeather($City,$country)).CurrentWeather</em></span></p>
<p style="padding-left:30px;"><span style="color:#003366;"><em>}</em></span></p>
<p><span style="color:#003366;"><em>}</em></span></p>
<p><span style="color:#000080;"><em> </em></span></p>
<p><strong>Now that the functions are out of the way, here is the &#8220;main&#8221; portion of the script.</strong></p>
<p><span style="color:#000080;"><em>#Main<br />
#Determine if help switch is active.</em></span></p>
<p><span style="color:#000080;"><em>switch ($help)</em></span></p>
<p style="padding-left:30px;"><span style="color:#000080;"><em>{</em></span></p>
<p style="padding-left:60px;"><span style="color:#000080;"><em> {$_ -eq $true }</em></span></p>
<p style="padding-left:60px;"><span style="color:#000080;"><em> { </em></span></p>
<p style="padding-left:90px;"><span style="color:#000080;"><em> get-weather -help -country $country</em></span></p>
<p style="padding-left:90px;"><span style="color:#000080;"><em> break</em></span></p>
<p style="padding-left:60px;"><span style="color:#000080;"><em>}</em></span></p>
<p style="padding-left:30px;"><span style="color:#000080;"><em>default</em></span></p>
<p style="padding-left:30px;"><span style="color:#000080;"><em>{</em></span></p>
<p style="padding-left:60px;"><span style="color:#000080;"><em> if ($full)#This is the full text output. No audio.</em></span></p>
<p style="padding-left:60px;"><span style="color:#000080;"><em> {</em></span></p>
<p style="padding-left:90px;"><span style="color:#000080;"><em> Get-Weather  -country $country -city $city</em></span></p>
<p style="padding-left:60px;"><span style="color:#000080;"><em> }</em></span></p>
<p style="padding-left:60px;"><span style="color:#000080;"><em> else #Audio output, streamlined for quicker information.</em></span></p>
<p style="padding-left:60px;"><span style="color:#000080;"><em> {</em></span></p>
<p style="padding-left:90px;"><span style="color:#000080;"><em>$currentWeather = get-weather -city $city</em></span></p>
<p style="padding-left:90px;"><span style="color:#000080;"><em> Write-Host $currentWeather </em></span></p>
<p style="padding-left:90px;"><span style="color:#000080;"><em> $currentTemperature = $currentWeather.temperature </em></span></p>
<p style="padding-left:90px;"><span style="color:#000080;"><em> $currentTemperature = $currentTemperature.split()</em></span></p>
<p style="padding-left:90px;"><span style="color:#000080;"><em> $currentSkyConditions = $currentWeather.SkyConditions</em></span></p>
<p style="padding-left:90px;"><span style="color:#000080;"><em> $wrsentence = &#8220;Here is the weather information you needed. In &#8221; + 				$city + &#8221; the temperature is &#8221; + [int]$currentTemperature[1] +				&#8221; degrees fahrenheit, and it is &#8221; + $currentSkyConditions</em></span></p>
<p style="padding-left:90px;"><span style="color:#000080;"><em> say $wrsentence </em></span></p>
<p style="padding-left:60px;"><span style="color:#000080;"><em> }</em></span></p>
<p style="padding-left:30px;"><span style="color:#000080;"><em>}</em></span></p>
<p><span style="color:#000080;"><em>}<br />
</em></span></p>
<p>I&#8217;ve used the default city of Memphis that I set up in the parameters, but it works just as well if I used the command line parameters.</p>
<p><strong>I&#8217;ve saved all of this in a script called get-weather.ps1</strong></p>
<p>Here is a sample using  Quebec, Canada</p>
<p><span style="color:#000080;"><em>.\get-weather  -country Canada -city Quebec</em></span></p>
<p>If  I am not sure of all of the city names that are available for Mexico, then I can type:</p>
<p><em><span style="color:#000080;">.\get-weather  -country Mexico -help</span></em></p>
<p><span style="color:#000000;">This will open up an out-grid view with all of the cities available in Mexico.</span></p>
<p><span style="color:#000000;">Since I set Memphis as the default city in the parameters, just typing the following will give me local weather information.</span></p>
<p><span style="color:#000000;"><span style="color:#003366;"><em>.\get-weather.ps1</em></span></span></p>
<p>If I want just screen output for a city, I can use something like the following:</p>
<p><span style="color:#003366;"><em>.\get-weather -full -country canada -city Quebec</em></span></p>
<p><span style="color:#000000;">Give this a try and see if it works. Let me know if you have any questions.</span></p>
<p><span style="color:#000000;">Thanks,</span></p>
<p><span style="color:#000000;">Patrick</span></p>
<p><em> </em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scriptingjournal.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scriptingjournal.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scriptingjournal.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scriptingjournal.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scriptingjournal.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scriptingjournal.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scriptingjournal.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scriptingjournal.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scriptingjournal.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scriptingjournal.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scriptingjournal.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scriptingjournal.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scriptingjournal.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scriptingjournal.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=62&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thescriptlad.com/2011/02/26/voiced-weather-report/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb8c6355d03ba59222ca8d70f4055bb8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">w4pwp</media:title>
		</media:content>
	</item>
		<item>
		<title>User Home Folder Size and other Information (without Quest)</title>
		<link>http://thescriptlad.com/2011/02/26/user-home-folder-size-and-other-information-without-quest/</link>
		<comments>http://thescriptlad.com/2011/02/26/user-home-folder-size-and-other-information-without-quest/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 20:30:12 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[non-quest]]></category>

		<guid isPermaLink="false">http://scriptingjournal.wordpress.com/?p=59</guid>
		<description><![CDATA[Frequently during my daily work I need to gather information on users that are contained in our Active Directory listing.  In a previous blog post, I had a script which does this work using a Quest commandlette.  Some environments don&#8217;t allow this, so a method to gather user data without using Quest is helpful to have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=59&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Frequently during my daily work I need to gather information on users that are  contained in our Active Directory listing.  In a previous blog post, I had a script which does this work using a Quest commandlette.  Some environments don&#8217;t allow this, so a method to gather user data without using Quest is helpful to have available.<br />
This script is used to quickly  gather information on a users home folder, SAM account name, their email  address, and the size of their home folder.</p>
<p>I use this a lot when I am  moving users home folders from one server to another. To save time I frequently  have the line that gathers home folder size remarked out with #.</p>
<p>The user  account names that I am searching for are contained in a text file  called<br />
accounts.txt. This file is contained in the same folder as this  script. The output is sent to the screen as well as a log file called  output.csv.</p>
<p><em>#************************************************************</em></p>
<p><em>$userArray =  @(&#8220;SAMID,HomeDirectory,EmailAdress,HomeFolderSize&#8221;)</em><br />
<em>$allUsers = gc  .\accounts.txt</em><br />
<em>$tempArray = @()</em><br />
<em>function  logfile($strData)</em><br />
<em>{</em><br />
<em>Out-File -filepath output.csv -inputobject $strData  -append</em><br />
<em>}</em><br />
<em>function getAccountInfo</em><br />
<em>{</em><br />
<em>$strName =  $currentUser</em><br />
<em>$strFilter =  &#8220;(&amp;(objectCategory=User)(samAccountName=$strName))&#8221;</em><br />
<em>#Get User AD  info</em><br />
<em>$objSearcher = New-Object  System.DirectoryServices.DirectorySearcher</em><br />
<em>$objSearcher.Filter =  $strFilter</em><br />
<em>$objPath = $objSearcher.FindOne()</em><br />
<em>$objUser =  $objPath.GetDirectoryEntry()</em><br />
<em>[string]$folder =  $objUser.homeDirectory</em><br />
<em>[string]$email = $objUser.mail</em><br />
<em>[string]$samID =  $objUser.sAMAccountName</em><br />
<em>[string]$folderSize=  getFolderSize($objUser.homeDirectory)</em><br />
<em>#$objUser.memberOf</em></p>
<p><em>$result =  &#8220;$samID,$folder,$email,$folderSize&#8221;</em><br />
<em>$result #This causes the output to steam  out, and be piped as the return from the function.</em><br />
<em>$folderSize = $null</em><br />
<em>$fs  = $null</em><br />
<em>}</em><br />
<em>function getFolderSize($strPath)</em><br />
<em>{</em><br />
<em>$fs = New-Object  -comobject Scripting.FileSystemObject</em><br />
<em>#Check validity of $strPath</em><br />
<em>if  ($fs.FolderExists($strPath))</em><br />
<em>{</em><br />
<em>[double]$tempSize =  ($fs.GetFolder($strPath).size) / 1024 / 1024</em><br />
<em>$tempSize = &#8216;{0:N}&#8217;  -f[double]$tempSize</em><br />
<em>$tempSize</em><br />
<em>}</em><br />
<em>else</em><br />
<em>{</em><br />
<em>$tempSize = &#8220;Bad folder  path!&#8221;</em><br />
<em>$tempSize</em><br />
<em>}</em><br />
<em>}</em><br />
<em>$header =  &#8220;SAMID,HomeDirectory,EmailAdress,HomeFolderSize&#8221;</em><br />
<em>Out-File -filepath  output.csv -inputobject $header</em><br />
<em>foreach ($currentUser in  $allUsers)</em><br />
<em>{</em><br />
<em>$tempOutput = getAccountInfo  $currentUser</em><br />
<em>$tempOutput</em><br />
<em>$userArray +=  [string[]]$tempOutput</em><br />
<em>logfile($tempOutput)</em><br />
<em>}</em></p>
<p><em>#************************************************************</em><br />
Let me know if you have any questions about this, or if  it is helpful.</p>
<p>Thanks<br />
Patrick</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scriptingjournal.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scriptingjournal.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scriptingjournal.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scriptingjournal.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scriptingjournal.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scriptingjournal.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scriptingjournal.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scriptingjournal.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scriptingjournal.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scriptingjournal.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scriptingjournal.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scriptingjournal.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scriptingjournal.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scriptingjournal.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=59&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thescriptlad.com/2011/02/26/user-home-folder-size-and-other-information-without-quest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb8c6355d03ba59222ca8d70f4055bb8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">w4pwp</media:title>
		</media:content>
	</item>
		<item>
		<title>User Home Folder Size and other Information (with Quest)</title>
		<link>http://thescriptlad.com/2011/02/26/user-home-folder-size-and-other-information/</link>
		<comments>http://thescriptlad.com/2011/02/26/user-home-folder-size-and-other-information/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 19:53:32 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[get-qaduser]]></category>
		<category><![CDATA[quest]]></category>
		<category><![CDATA[user information]]></category>

		<guid isPermaLink="false">http://scriptingjournal.wordpress.com/?p=51</guid>
		<description><![CDATA[Here is a function that can be used to quickly gather folder information about a user’s home folder. There is one stipulation. For this to work you must have the Quest Active Directory Snap-In configured for your Powershell session. This will apply to users contained within an Microsoft Active Directory structure. I have used the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=51&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is a function that can be used to quickly gather folder information about a user’s home folder.</p>
<p>There is one stipulation.</p>
<p>For this to work you must have the <strong>Quest Active Directory Snap-In</strong> configured for your Powershell session.<br />
This will apply to users contained within an Microsoft Active Directory structure.<br />
<strong>I have used the “^” in place of the “select-object” command</strong>. This is an alias that I use to make typing much faster. It is a symbol that I have never had a conflict on.</p>
<p>I have called the function <strong>GQUF</strong>. This is short for <strong>Get-QADUserFunction</strong>, but you may call it whatever you like of course.</p>
<p>Here is the syntax of the command. There are three options that are available when this command is run with the second command line switch.</p>
<p><strong>“GQUF userid –groups” or</strong></p>
<p><strong>“GQUF userid -explorer” or</strong></p>
<p><strong>“GQUF userid –size.”</strong></p>
<p>The –groups switch will detail all of the active directory groups in which the member is included.</p>
<p>The –explorer switch will open an explorer window pointed at the user’s home folder.</p>
<p>The –size switch will detail the total size of the user’s home folder.</p>
<p>Here is the code. See a screen shot at the bottom.</p>
<p><em>#*******************************</em></p>
<p><em> #This function looks up a user home drive and home directory</em></p>
<p><em>#Uses get-qaduser</em></p>
<p><em>function gquf</em></p>
<p><em>{</em></p>
<p><em> $UserID = $Args[0]</em><br />
<em> $Domain = $Args[1]</em></p>
<p><em> $result = Get-QADUser $Args[0] | Select-Object SamAccountName, homedirectory, homedrive, email, displayname # | ft -autosize</em></p>
<p><em> #$result | ft -autosize</em></p>
<p><em> Write-Host &#8220;Display Name:&#8221; $result.displayname -foregroundcolor green</em></p>
<p><em> Write-Host &#8220;Email Address:&#8221; $result.email -foregroundcolor green</em></p>
<p><em> Write-Host &#8220;HomeDir:&#8221; $result.homedrive $result.homedirectory -foregroundcolor green</em></p>
<p><em> Write-Host &#8220;&#8221;</em></p>
<p><em> Write-Host &#8220;Permissions for &#8220;$result.homedirectory -foregroundcolor Yellow</em></p>
<p><em> get-aclf $result.homedirectory</em></p>
<p><em> switch ($Args[1])</em></p>
<p><em> {</em></p>
<p><em> {$_ -eq &#8220;-groups&#8221;} </em></p>
<p><em> {</em></p>
<p><em> write-host &#8220;Member Of:&#8221;</em></p>
<p><em> (Get-QADUser $Args[0] | ^ memberof).memberof | sort</em></p>
<p><em> }</em></p>
<p><em> {$_ -eq &#8220;-explorer&#8221;} </em></p>
<p><em> {</em></p>
<p><em> explorer $result.homedirectory</em></p>
<p><em> }</em></p>
<p><em> {$_ -eq &#8220;-size&#8221;} </em></p>
<p><em> {</em></p>
<p><em> Write-Host &#8220;Calculating the size of the homefolder&#8230;&#8221; -foregroundcolor red</em></p>
<p><em> $fs New-Object -comobject Scripting.FileSystemObject</em></p>
<p><em> $tempSize $fs.GetFolder($result.homedirectory).size/1024/1024</em></p>
<p><em> $tempSize &#8216;{0:N}&#8217; -f [double]$tempSize</em></p>
<p><em> Write-Host &#8220;$tempSize MB&#8221;</em></p>
<p><em>} </em></p>
<p><em> }</em></p>
<p><em>}<br />
#*******************************</em></p>
<p>Here is the screen shot for the –size switch. Sensitive information has been blocked out.</p>
<p><a href="http://scriptingjournal.files.wordpress.com/2011/02/image001.jpg"><img class="alignnone size-full wp-image-52" title="image001" src="http://scriptingjournal.files.wordpress.com/2011/02/image001.jpg?w=630" alt=""   /></a></p>
<p>Thank You,</p>
<p>Patrick</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scriptingjournal.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scriptingjournal.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scriptingjournal.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scriptingjournal.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scriptingjournal.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scriptingjournal.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scriptingjournal.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scriptingjournal.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scriptingjournal.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scriptingjournal.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scriptingjournal.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scriptingjournal.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scriptingjournal.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scriptingjournal.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=51&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thescriptlad.com/2011/02/26/user-home-folder-size-and-other-information/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb8c6355d03ba59222ca8d70f4055bb8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">w4pwp</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/image001.jpg" medium="image">
			<media:title type="html">image001</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a Folder Named After a Date</title>
		<link>http://thescriptlad.com/2011/02/26/creating-a-folder-named-after-a-date/</link>
		<comments>http://thescriptlad.com/2011/02/26/creating-a-folder-named-after-a-date/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 19:34:47 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[One-liners]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[dated folders]]></category>
		<category><![CDATA[dir]]></category>
		<category><![CDATA[get-date]]></category>
		<category><![CDATA[md]]></category>

		<guid isPermaLink="false">http://scriptingjournal.wordpress.com/?p=43</guid>
		<description><![CDATA[I like to create folders on the fly for logging  purposes, as well as for keeping track of re-occurring actions, like scanning for disk usage on a given date. The following PowerShell command is useful for creating a folder with a name in the format YYYYMMDD. $folderName = &#8220;folder1_&#8221; + (Get-Date -uFormat  &#8221;%Y%m%d&#8221;) This command makes [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=43&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I like to create folders on the fly for logging  purposes, as well as for keeping track of re-occurring actions, like scanning for disk usage on a given  date.</p>
<p>The following PowerShell command is useful for creating a folder with a name  in the format YYYYMMDD.</p>
<p><strong>$folderName = &#8220;folder1_&#8221; + (Get-Date -uFormat  &#8221;%Y%m%d&#8221;)</strong><br />
This command makes a folder call<strong> folder1_20110226</strong>.</p>
<p>Another technique is do make the folder, and assign the date to the name all at once.</p>
<p>md (&#8220;folder2_&#8221; + (Get-Date -uFormat  &#8221;%Y%m%d&#8221;)).</p>
<p>Below you will see both techniques used, and then the old <strong>DIR</strong> command just to show that they were created successfully.</p>
<div id="attachment_44" class="wp-caption alignnone" style="width: 543px"><a href="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601795641.jpg"><img class="size-full wp-image-44" title="Make folders with date names" src="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601795641.jpg?w=630" alt=""   /></a><p class="wp-caption-text">Make Folders with Date Names.</p></div>
<p>Instead of the <strong>DIR</strong> command I could have used the Powershell commandlette <strong>Get-ChildItem folder*</strong>, and it would have worked just as well.  I like DIR because I am use to it, and because it is less typing.</p>
<p>That&#8217;s all for this entry. Have a nice day.</p>
<p>Thanks,</p>
<p>Patrick</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scriptingjournal.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scriptingjournal.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scriptingjournal.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scriptingjournal.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scriptingjournal.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scriptingjournal.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scriptingjournal.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scriptingjournal.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scriptingjournal.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scriptingjournal.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scriptingjournal.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scriptingjournal.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scriptingjournal.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scriptingjournal.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=43&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thescriptlad.com/2011/02/26/creating-a-folder-named-after-a-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb8c6355d03ba59222ca8d70f4055bb8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">w4pwp</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601795641.jpg" medium="image">
			<media:title type="html">Make folders with date names</media:title>
		</media:content>
	</item>
		<item>
		<title>Retrieving Shares in Powershell with WMI</title>
		<link>http://thescriptlad.com/2011/02/26/retrieving-shares-in-powershell-with-wmi/</link>
		<comments>http://thescriptlad.com/2011/02/26/retrieving-shares-in-powershell-with-wmi/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 12:36:56 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://scriptingjournal.wordpress.com/?p=22</guid>
		<description><![CDATA[Powershell one liners are a great way to work with Windows Management Instrumentation (WMI).  One of the WMI features I use the most is Win32_Share. It is a fast and easy way to retrieve share information. In this blog entry I would like to explore the capabilities of WMI by developing a WIN32_Share utility. To begin [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=22&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Powershell one liners are a great way to work with Windows Management Instrumentation (WMI).  One of the WMI features I use the most is Win32_Share. It is a fast and easy way to retrieve share information.</p>
<p>In this blog entry I would like to explore the capabilities of WMI by developing a WIN32_Share utility. To begin let&#8217;s look at the most simple command available.</p>
<p><strong>Get-WmiObject win32_share</strong></p>
<div id="attachment_27" class="wp-caption alignnone" style="width: 640px"><a href="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601794590.jpg"><img class="size-full wp-image-27" title="Basic WMI Win32_Share Command" src="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601794590.jpg?w=630&#038;h=88" alt="" width="630" height="88" /></a><p class="wp-caption-text">Basic WMI Win32_Share Command</p></div>
<p>You&#8217;ll see from the image above that we get back three types of information from this WMI query. Name, Path, and Description. It may not be readily visible, but we also get back several types of shares.  Above we see administrative shares, printer, and shares, and regular file shares. As a system administrator that is interested in managing the files shares available to my user I want to work with only file shares now.  We can add some syntax to filter the type of share that is returned. To do that we need to know the share type.</p>
<p>Here is a modified version of the basic command we used above:</p>
<p><strong>Get-WmiObject win32_share | Select-Object name, path, description, type | Format-Table -autosize</strong></p>
<p>I used the Powershell commandlette <strong>select-objec</strong>t to request four specific properties to be returned from the WMI query. They are name, path, description, and type.  Also, I&#8217;ve added the text &#8220;<strong>Format-Table -autosize</strong>&#8221; to make it all fit neatly on the screen. Here is the result of the query:</p>
<div id="attachment_32" class="wp-caption alignnone" style="width: 640px"><a href="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601794732.jpg"><img class="size-full wp-image-32" title="GWMI WIN32_Share with Select-Object" src="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601794732.jpg?w=630&#038;h=103" alt="" width="630" height="103" /></a><p class="wp-caption-text">GWMI WIN32_Share with Select-Object</p></div>
<p>Now to make it even more useful, we only want the shares that would be accessed by our users. They don&#8217;t need access to the admin shares (type 2147483648), or the shared printer (type 1). To filter on the type property we can use the Powershell commandlette <strong>where-object</strong>:</p>
<p><strong>Get-WmiObject win32_share | Select-Object name, path, description, type | Where-Object { $_.type  -eq &#8217;0&#8242;}| Format-Table -autosize</strong></p>
<div id="attachment_33" class="wp-caption alignnone" style="width: 640px"><a href="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601794874.jpg"><img class="size-full wp-image-33" title="GWMI Win32_Share with Type Filtering" src="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601794874.jpg?w=630&#038;h=44" alt="" width="630" height="44" /></a><p class="wp-caption-text">GWMI Win32_Share with Type Filtering</p></div>
<p>Finally we can use the <strong>sort-object</strong> commandlette to sort the WMI query based on any property we want:</p>
<p><strong>PS&gt;$ Get-WmiObject win32_share | Select-Object name, path, description, type | `&gt;&gt; Where-Object { $_.type  -eq &#8217;0&#8242;}| Sort-Object path | ft -autosize&gt;&gt;</strong></p>
<div id="attachment_34" class="wp-caption alignnone" style="width: 640px"><a href="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601795015.jpg"><img class="size-full wp-image-34" title="WMI Win32_Share with Sort" src="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601795015.jpg?w=630&#038;h=103" alt="" width="630" height="103" /></a><p class="wp-caption-text">WMI Win32_Share with Sort</p></div>
<p>One great feature of Powershell version 2.0 is the <strong>out-gridview</strong> commandlette. It allows you to sort and filter using a dotnet gridview. Here is the command a screen capture of the output. Notice how the actual command is much short as we are filtering and sorting in the resulting gridview object:</p>
<p><strong>Get-WmiObject win32_share | Select-Object name, path, description, type | Out-GridView</strong>.</p>
<div id="attachment_35" class="wp-caption alignnone" style="width: 640px"><a href="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601795156.jpg"><img class="size-full wp-image-35" title="WMI Win32_Share with Out-gridview" src="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601795156.jpg?w=630&#038;h=211" alt="" width="630" height="211" /></a><p class="wp-caption-text">WMI Win32_Share with Out-GridView</p></div>
<p>So, that&#8217;s it for now. Next time we will expand this further to see how we can pull back the file shares from multiple servers at once.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/scriptingjournal.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/scriptingjournal.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/scriptingjournal.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/scriptingjournal.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/scriptingjournal.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/scriptingjournal.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/scriptingjournal.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/scriptingjournal.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/scriptingjournal.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/scriptingjournal.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/scriptingjournal.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/scriptingjournal.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/scriptingjournal.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/scriptingjournal.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thescriptlad.com&amp;blog=10397023&amp;post=22&amp;subd=scriptingjournal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thescriptlad.com/2011/02/26/retrieving-shares-in-powershell-with-wmi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/eb8c6355d03ba59222ca8d70f4055bb8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">w4pwp</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601794590.jpg" medium="image">
			<media:title type="html">Basic WMI Win32_Share Command</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601794732.jpg" medium="image">
			<media:title type="html">GWMI WIN32_Share with Select-Object</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601794874.jpg" medium="image">
			<media:title type="html">GWMI Win32_Share with Type Filtering</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601795015.jpg" medium="image">
			<media:title type="html">WMI Win32_Share with Sort</media:title>
		</media:content>

		<media:content url="http://scriptingjournal.files.wordpress.com/2011/02/pp1071_1298601795156.jpg" medium="image">
			<media:title type="html">WMI Win32_Share with Out-gridview</media:title>
		</media:content>
	</item>
	</channel>
</rss>
