<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-3859053332094757531</atom:id><lastBuildDate>Tue, 15 Dec 2009 01:40:02 +0000</lastBuildDate><title>Quick and Dirty Scripting</title><description>A blog that focuses on automating system administration tasks for Linux, Windows, and VMware ESX</description><link>http://www.bjd145.org/scripting_blog.html</link><managingEditor>noreply@blogger.com (Brian Denicola)</managingEditor><generator>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-6603978098354988775</guid><pubDate>Sun, 08 Nov 2009 02:38:00 +0000</pubDate><atom:updated>2009-12-14T17:40:02.400-08:00</atom:updated><title>SharePoint Trending with Google APIs</title><description>At my day job, I manager a fairly large SharePoint deployment. We currently have about 450GB of content spread across 6-7 content databases. Needlessly to say, because  SharePoint stores all of its information inside SQL Server database and Microsoft’s recommendation for no larger than 100GB content databases, trending our growth is very important to our team. For a while, we have been taking snapshots of the content database’s size, storing the information in Excel and generating Pivot table and charts.  This worked fine but I wanted better.  I’ve always liked the way Google’s Finance pages looked so I was excited to learn that you can use those same APIs in your own site.  I think I’ve come up with a pretty neat solution by utilizing the SharePoint object model ,PowerShell, a little jQuery,  Google’s APIs and an awesome course from EndUserSharepoint (Url - &lt;a href="http://www.endusersharepoint.com/"&gt;http://www.endusersharepoint.com&lt;/a&gt;, Twitter - @ESUP) .  I’m always open for suggestions or improvements so after you read my posting, please let me know what you think.&lt;div class="ExternalClass81E201677E3D4F98A98C1B249071A6CA"&gt; &lt;p&gt;Enough chit chat. Let’s get into how this works. To get this working for you, you’ll need three things:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;A SharePoint List to store the size of the SharePoint databases  &lt;/li&gt;&lt;li&gt;A PowerShell script to populate the list on a nightly basis  &lt;/li&gt;&lt;li&gt;A Web Part page with a Content Editor Web part + jQuery and the SharePoint List to generate the graph&lt;/li&gt;&lt;/ol&gt; &lt;h3&gt;SharePoint List&lt;/h3&gt; &lt;p&gt;This easiest thing to create. Its just a custom SharePoint list with the following columns.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Web Application – the name of the SharePoint web application. I typically rename the default Name field.  &lt;/li&gt;&lt;li&gt;Database Name – the name of the of the Content Database.  &lt;/li&gt;&lt;li&gt;Database Size – a number field that will store the size of the database. The one thing that I do not like about the number field is that it inserts commas into the number. I debated about making this a string field but I decided to just handle this with a little jQuery  &lt;/li&gt;&lt;li&gt;Date – this will hold the date the database snapshot was taken. I give it a default value of today’s date and only select date, not date/time.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;A couple other things to note about the list:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;You will need to grant your SharePoint farm account contribute access to the list. This is because the PowerShell script will run as the Farm account. In a locked down environment like mine the only account that can access the databases is the Farm account.  &lt;/li&gt;&lt;li&gt;To keep the list from growing too large, I setup an IRM  policy to delete  a list item 90 days  after the item is created. This keeps my list nice and trim automatically. &lt;/li&gt;&lt;/ol&gt; &lt;h3&gt;PowerShell Script&lt;/h3&gt; &lt;p&gt;The PowerShell script utilizes the SharePoint object model so it has to run on one of the SharePoint servers in your farm. I choose my Central Admin server but it can be any server in the farm.  The idea of the script to is to loop through every Web Application and gather the size of each Content Database associated with it and then upload the information to the SharePoint list. Its pretty straight forward except for one issue with SharePoint Content Database names when working with PowerShell. This discussion thread goes into good detail on how to get around it - &lt;a title="http://groups.google.com/group/microsoft.public.windows.powershell/browse_thread/thread/16c06d92b2385325" href="http://groups.google.com/group/microsoft.public.windows.powershell/browse_thread/thread/16c06d92b2385325"&gt;http://groups.google.com/group/microsoft.public.windows.powershell/browse_thread/thread/16c06d92b2385325&lt;/a&gt;.&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;style&gt;&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode, .externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode pre&lt;br /&gt;{font-size:small;color:black;font-family:consolas, &amp;quot;courier new&amp;quot;, courier, monospace;background-color:#ffffff;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode pre&lt;br /&gt;{margin:0em;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode .rem&lt;br /&gt;{color:#008000;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode .kwrd&lt;br /&gt;{color:#0000ff;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode .str&lt;br /&gt;{color:#006080;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode .op&lt;br /&gt;{color:#0000c0;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode .preproc&lt;br /&gt;{color:#cc6633;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode .asp&lt;br /&gt;{background-color:#ffff00;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode .html&lt;br /&gt;{color:#800000;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode .attr&lt;br /&gt;{color:#ff0000;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode .alt&lt;br /&gt;{background-color:#f4f4f4;width:100%;margin:0em;}&lt;br /&gt;.externalclass81e201677e3d4f98a98c1b249071a6ca .csharpcode .lnum&lt;br /&gt;{color:#606060;}&lt;br /&gt;&lt;/style&gt;  &lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt; &lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; . ..\SharePointFunctions.ps1&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;#Powershell had an issue with the SPContentDatabase assembly function Name and DiskSizeRequired. This is a work around&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;#See http://groups.google.com/group/microsoft.public.windows.powershell/browse_thread/thread/16c06d92b2385325 for more information &lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; $nameMethod = [Microsoft.Sharepoint.Administration.SPContentDatabase].getMethod(&lt;span style="color: rgb(0, 96, 128);"&gt;"get_Name"&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; $diskMethod = [Microsoft.Sharepoint.Administration.SPContentDatabase].getMethod(&lt;span style="color: rgb(0, 96, 128);"&gt;"get_DiskSizeRequired"&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt; set-variable -option constant -name TrendingList -value &lt;span style="color: rgb(0, 96, 128);"&gt;"Trending-SPDatabase"&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt; set-variable -option constant -name TrendingSite  -value &lt;span style="color: rgb(0, 96, 128);"&gt;"http://tis-collaboration.jpmchase.net/ti/shareddotnet"&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt; set-variable -option constant -name WebApplication  -value &lt;span style="color: rgb(0, 96, 128);"&gt;"Web Application"&lt;/span&gt; &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt; set-variable -option constant -name DatabaseName -value &lt;span style="color: rgb(0, 96, 128);"&gt;"Database Name"&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt; set-variable -option constant -name DatabaseSize  -value &lt;span style="color: rgb(0, 96, 128);"&gt;"Database Size (MB)"&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt; $MB = 1024*1024&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;#Function main - Where all of the fun is&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; main() {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;#Loop through all WebApplications&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;     get-SPWebApplications -name * | % {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;#Don't need to display information on the Central Admin site&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;( -not $_.IsAdministrationWebApplication ) {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;                         &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;             $strWebApp = $_.Name.TrimStart()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;                     &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;#Display information about the content database attached to this WebApp&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;             $ContentDatabaseCollection = $_.ContentDatabases&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;             &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;             $ContentDatabaseCollection | % {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;     &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;                 $newlistitem  = @{}&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;                 $newlistitem[$WebApplication] = $strWebApp&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;                 $newlistitem[$DatabaseName] = $nameMethod.Invoke($_, &lt;span style="color: rgb(0, 96, 128);"&gt;"instance,public"&lt;/span&gt;, $null, $null, $null)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;                 $newlistitem[$DatabaseSize] = [math]::round( ($diskMethod.Invoke($_, &lt;span style="color: rgb(0, 96, 128);"&gt;"instance,public"&lt;/span&gt;, $null, $null, $null) / $MB), 0)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;                 &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;                 add-toSpList -url $TrendingSite -list $TrendingList -entry $newlistitem &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;             }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt;         }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum41"&gt;  41:&lt;/span&gt;     }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum42"&gt;  42:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum43"&gt;  43:&lt;/span&gt; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum44"&gt;  44:&lt;/span&gt; main&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;The variables TrendingSite, TrendingList, WebApplication, DatabaseName, DatabaseSize will need to be updated for your environment.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The function get-SPWebApplication will return a list  Web Application objects. You can limit the list to a specific Web Application by replacing “–name *” with “–name $name_of_web_application”&lt;/p&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; get-SPWebApplication( [string] $name )&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     $WebServiceCollection = new-object microsoft.sharepoint.administration.SpWebServiceCollection( get-SPFarm )&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     $WebServiceCollection | % { $WebApplications += $_.WebApplications }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; ( $webApplications | where { $_.Name.ToLower() &lt;span style="color: rgb(204, 102, 51);"&gt;-like&lt;/span&gt; &lt;span style="color: rgb(0, 96, 128);"&gt;"*"&lt;/span&gt;+$name.ToLower()+&lt;span style="color: rgb(0, 96, 128);"&gt;"*"&lt;/span&gt; } | select -Unique )&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; get-SPFarm()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt; {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; [microsoft.sharepoint.administration.spfarm]::&lt;span style="color: rgb(0, 0, 255);"&gt;local&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;To add the information to the SharePoint List, we have to pass a hash table with name/value pairs to the function add-toSpList.  We also have to pass the URL of the Site that hosts the list and the List name.&lt;/p&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 97.5%; direction: ltr; max-height: 200px; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; add-toSpList ( [Object] $url, [string] $list, [HashTable] $entry)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt;( $url.GetType().Name &lt;span style="color: rgb(204, 102, 51);"&gt;-eq&lt;/span&gt; &lt;span style="color: rgb(0, 96, 128);"&gt;"String"&lt;/span&gt;)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         $site = new-object Microsoft.SharePoint.SPSite($url)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         $web = $site.OpenWeb()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     }&lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         $web = $url&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     $splist = $web.Lists[$list]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     $newitem = $splist.items.Add() &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;     $entry.Keys.GetEnumerator() | % {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         $newitem[$_] = $entry[$_]&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;     }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;     &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;     $newitem.update() &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;     $web.Dispose()&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;     $site.Dispose() &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt; }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;Now that we have to entire script, all you have to do is schedule it to run as often as you wish via the Windows Scheduler.  Make sure you run the script as the SharePoint Farm Admin.&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;SharePoint WebPart Page + jQuery&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;Now the fun begins.  I owe a ton of thanks to the EndUserSharepoint.com team as I used a lot of their work as a basis for what I’m trying to do.    First, what you need to do is add a Web Part page to your site.  On this page, add a Content Editor Web Part and the SharePoint List that you created earlier.  For the list, I filtered the view to only display one database name. I also only selected he database name, size, and date columns.  If I have more than one database (or web application) then I will need to create a page for each.  The view should look something like this:&lt;/p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.bjd145.org/uploaded_images/blog_1-737493.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 592px; height: 166px;" src="http://www.bjd145.org/uploaded_images/blog_1-737490.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Next you have to get jQuery working with your site, and this means adding code to the Content Editor Web Part.  I would suggest heading over to EndUserSharepoint.com (&lt;a title="http://www.endusersharepoint.com/?s=jquery+for+everyone" href="http://www.endusersharepoint.com/?s=jquery+for+everyone"&gt;http://www.endusersharepoint.com/?s=jquery+for+everyone&lt;/a&gt;) for more information on jQuery, but basically jQuery is a collection of JavaScript functions and objects that make JavaScript coding a lot easier.  You need to load the jQuery engine and thankfully Google hosts it for you. All you need to do is link to their URL in your code. This is what I done for this to work.  Google also hosts the visualization APIs that we need to generate the graph. If you want to learn more about the available APIs and samples on how to use them, head over to &lt;a title="http://code.google.com/apis/visualization/" href="http://code.google.com/apis/visualization/"&gt;http://code.google.com/apis/visualization/&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;The code for the Content Editor Web Part +  jQuery is as follows: (PS: This has to be added via the CEWP’s source button, not the Rich Text Editor.)&lt;/p&gt;&lt;br /&gt;&lt;div   style="border: 1px solid silver; margin: 20px 0px 10px; padding: 4px; overflow: auto; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 98.39%; direction: ltr; height: 598px; max-height: 200px; cursor: text;font-family:'Courier New',courier,monospace;font-size:8pt;" id="codeSnippetWrapper"&gt;&lt;br /&gt;&lt;div    style="border-style: none; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;" id="codeSnippet"&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &amp;lt;script type=&lt;span style="color: rgb(0, 96, 128);"&gt;"text/javascript"&lt;/span&gt; src=&lt;span style="color: rgb(0, 96, 128);"&gt;"https://www.google.com/jsapi"&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; &amp;lt;script type=&lt;span style="color: rgb(0, 96, 128);"&gt;"text/javascript"&lt;/span&gt;&amp;gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     google.load(&lt;span style="color: rgb(0, 96, 128);"&gt;'visualization'&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;'1'&lt;/span&gt;, {packages: [&lt;span style="color: rgb(0, 96, 128);"&gt;'annotatedtimeline'&lt;/span&gt;]});&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt; drawVisualization() {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; dataList = $(&lt;span style="color: rgb(0, 96, 128);"&gt;"td.ms-vb2 div"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; dateList = $(&lt;span style="color: rgb(0, 96, 128);"&gt;"td.ms-vb2 nobr"&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; dateArray = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Array();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;       $.each(dateList, &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt;(i,e)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;       {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; y = $(e).text();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         dateArray[i] = y;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;       });&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; data = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; google.visualization.DataTable();&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;       data.addColumn(&lt;span style="color: rgb(0, 96, 128);"&gt;'date'&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;'Date'&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;       data.addColumn(&lt;span style="color: rgb(0, 96, 128);"&gt;'number'&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;'Size'&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;       data.addRows(dataList.length);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;       &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;       $.each(dataList, &lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt;(i,e)&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;       {&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; x= $(e).text().replace(&lt;span style="color: rgb(0, 96, 128);"&gt;","&lt;/span&gt;,&lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;          data.setValue(i, 0, &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Date(dateArray[i]) );&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;          data.setValue(i, 1, parseInt(x * 1048576) );&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;       });&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;       &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 255);"&gt;var&lt;/span&gt; annotatedtimeline = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; google.visualization.AnnotatedTimeLine(document.getElementById(&lt;span style="color: rgb(0, 96, 128);"&gt;'trending'&lt;/span&gt;));&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;       annotatedtimeline.draw(data, {&lt;span style="color: rgb(0, 96, 128);"&gt;'displayAnnotations'&lt;/span&gt;: &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;});&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;     }&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;     &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;     google.setOnLoadCallback(drawVisualization);&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;  &lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: rgb(244, 244, 244); width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt; &amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;pre    style="border-style: none; margin: 0em; padding: 0px; overflow: visible; text-align: left; line-height: 12pt; background-color: white; width: 100%; direction: ltr;font-family:'Courier New',courier,monospace;font-size:8pt;color:black;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt; &amp;lt;div id=&lt;span style="color: rgb(0, 96, 128);"&gt;"trending"&lt;/span&gt; style=&lt;span style="color: rgb(0, 96, 128);"&gt;"width: 100%; height: 400px;"&lt;/span&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/pre&gt;&lt;!--CRLF--&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;Well there you go.  Once you have everything in place you should have a page the looks similar to this:&lt;/p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.bjd145.org/uploaded_images/blog_2-786119.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 609px; height: 272px;" src="http://www.bjd145.org/uploaded_images/blog_2-786116.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I hope that everyone has enjoyed this post and I always look forward to any feedback.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-6603978098354988775?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2009/11/sharepoint-trending-with-google-apis.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>9</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-756669104060656744</guid><pubDate>Fri, 16 Oct 2009 04:31:00 +0000</pubDate><atom:updated>2009-10-15T21:39:57.682-07:00</atom:updated><title>Time zone Clocks with SharePoint using jQuery</title><description>&lt;p&gt;I work with a lot people who are spread across the global so we are always trying to find out what is their local time. While Google has a great query that will convert time for you, I wanted to see if I could create a SharePoint page that will list the times in all the zones that we have people on the team.  I found a great blog post on ‘Path to Sharepoint’ (&lt;a title="http://pathtosharepoint.wordpress.com/2009/01/09/world-clock/" href="http://pathtosharepoint.wordpress.com/2009/01/09/world-clock/"&gt;http://pathtosharepoint.wordpress.com/2009/01/09/world-clock/&lt;/a&gt;) did exactly what I wanted. The one catch was that he used a lot of JavaScript to convert the calculated text column to HTML. I wondered if jQuery could make it easier.  This is what I came up with . . . &lt;/p&gt;&lt;pre style="border: 1px solid rgb(206, 206, 206); padding: 5px; overflow: auto; background-color: rgb(251, 251, 251); min-height: 40px; width: 700px;"&gt;&lt;pre   style="margin: 0em; background-color: rgb(251, 251, 251); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:10px;"&gt;  1: &amp;lt;script type="&lt;span style="color: rgb(139, 0, 0);"&gt;text/javascript&lt;/span&gt;" src="&lt;span style="color: rgb(139, 0, 0);"&gt;http://www.google.com/jsapi&lt;/span&gt;"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:10px;"&gt;  2: &amp;lt;script type="&lt;span style="color: rgb(139, 0, 0);"&gt;text/javascript&lt;/span&gt;"&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; background-color: rgb(251, 251, 251); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:10px;"&gt;  3:     &lt;span style="color: rgb(0, 128, 0);"&gt;//load jQuery&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:10px;"&gt;  4:     google.load("&lt;span style="color: rgb(139, 0, 0);"&gt;jquery&lt;/span&gt;", "&lt;span style="color: rgb(139, 0, 0);"&gt;1.3.2&lt;/span&gt;");&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; background-color: rgb(251, 251, 251); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:10px;"&gt;  5: &amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:10px;"&gt;  6:&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; background-color: rgb(251, 251, 251); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:10px;"&gt;  7: &amp;lt;script type="&lt;span style="color: rgb(139, 0, 0);"&gt;text/javascript&lt;/span&gt;"&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre   style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%;font-family:consolas,'Courier New',courier,monospace;font-size:10px;"&gt;  8: $(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt;() {&lt;br /&gt;&lt;/pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="10px" style="margin: 0em; background-color: rgb(251, 251, 251); width: 100%;"&gt;  9:     $("&lt;span style="color: rgb(139, 0, 0);"&gt;td.ms-stylebody:contains('DIV')&lt;/span&gt;").each(&lt;span style="color: rgb(0, 0, 255);"&gt;function&lt;/span&gt;(){&lt;br /&gt;&lt;/pre&gt;&lt;pre face="consolas,'Courier New',courier,monospace" size="10px" style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%;"&gt; 10:         $(&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;).html($(&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;).text());&lt;br /&gt;&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(251, 251, 251); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px;"&gt; 11:     });&lt;br /&gt;&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px;"&gt; 12: });&lt;br /&gt;&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(251, 251, 251); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px;"&gt; 13: &amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;There are a couple requirements for this to work.&lt;/p&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;The list view was set to boxed.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The calculated column had this equation: &lt;/li&gt;&lt;pre style="border: 1px solid rgb(206, 206, 206); padding: 5px; overflow: auto; background-color: rgb(251, 251, 251); min-height: 40px; width: 700px;"&gt;&lt;pre style="margin: 0em; background-color: rgb(251, 251, 251); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px;"&gt;="&lt;span style="color: rgb(139, 0, 0);"&gt;&amp;lt;DIV id='calchtml'&amp;gt;&amp;lt;embed src='http://www.clocklink.com/clocks/5001-blue.swf?TimeZone=&lt;/span&gt;"&amp;amp;TimeZone&amp;amp;"&lt;span style="color: rgb(139, 0, 0);"&gt;'&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="margin: 0em; background-color: rgb(255, 255, 255); width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 10px;"&gt;width=&lt;span style="color: rgb(0, 128, 0);"&gt;'250' height='70' wmode='transparent' type='application/x-shockwave-flash'&amp;gt;&amp;lt;/DIV&amp;gt;"&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;/ol&gt;&lt;br /&gt;&lt;p&gt;If you follow the instructions at ‘Path to SharePoint’ and use this jQuery you should get something like this:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.bjd145.org/uploaded_images/clock-733791.png"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 107px;" src="http://www.bjd145.org/uploaded_images/clock-733789.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-756669104060656744?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2009/10/time-zone-clocks-with-sharepoint-using.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-6377526587696495105</guid><pubDate>Thu, 10 Apr 2008 02:13:00 +0000</pubDate><atom:updated>2008-04-09T19:57:41.940-07:00</atom:updated><title>Powershell Script to Create Sharepoint Web Application</title><description>Microsoft Sharepoint 2007 has a very nice web-based UI to create Web Applications, but there is one catch. The UI creates the backend database on the fly. In a lot of companies, this is the role of a DBA, and only they are allowed to create a new database. In a way this makes sense due to the fact that the DBAs must maintain the intergity of the database server. Microsoft has provided a switch within the stsadm command to create a new Web Application with an existing database, but I thought I could come up with a way to do it using Powersell.&lt;br /&gt;&lt;br /&gt;What I wanted to do was to supply a script with an XML configuration that would create 1-N Web Applications with 1-N Sites. The XML looks like the following:&lt;br /&gt;&lt;blockquote&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&lt;sharepoint&gt;&lt;/sharepoint&gt;&lt;/span&gt;&lt;sharepoint&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&amp;lt;Sharepoint&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    &amp;lt;WebApplication name="Test Site #1" hostheader="http://portal.example.net"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &amp;lt;AppPoolName&amp;gt;WebApp-Portal&amp;lt;/AppPoolName&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &amp;lt;AppPoolUser&amp;gt;Domain\myServiceAccount&amp;lt;/AppPoolUser&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &amp;lt;AppPoolPass&amp;gt;test1235&amp;lt;/AppPoolPass&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &amp;lt;Port&amp;gt;80&amp;lt;/Port&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &amp;lt;DatabaseServer&amp;gt;DBS-SERVER-NAME\MOSS&amp;lt;/DatabaseServer&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &amp;lt;DatabaseName&amp;gt;WSS_Content_Potal&amp;lt;/DatabaseName&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &amp;lt;RootDirectory&amp;gt;d:\inetpub\wwwroot\wss\portal&amp;lt;/RootDirectory&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &amp;lt;Sites&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            &amp;lt;Site Path="/"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                &amp;lt;Title&amp;gt;Root Site&amp;lt;/Title&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                &amp;lt;Description&amp;gt;Root Site&amp;lt;/Description&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                &amp;lt;Type&amp;gt;STS#1&amp;lt;/Type&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                &amp;lt;AdminAccount&amp;gt;DOMAIN\Administrator&amp;lt;/AdminAccount&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                &amp;lt;AdminName&amp;gt;Administrator1&amp;lt;/AdminName&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;                &amp;lt;AdminEmail&amp;gt;root@jexample.net&amp;lt;/AdminEmail&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            &amp;lt;/Site&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        &amp;lt;/Sites&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    &amp;lt;/WebApplication&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    &amp;lt;WebApplication&amp;gt;&amp;lt;/WebApplication&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&amp;lt;/Sharepoint&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;webapplication name="Test Site #1" hostheader="http://wssportal.jpmchase.net"&gt;&lt;sites&gt;&lt;site path="/"&gt;&lt;/site&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&lt;webapplication&gt;&lt;/webapplication&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/sites&gt;&lt;/webapplication&gt;&lt;/sharepoint&gt;&lt;/blockquote&gt;The first thing that needs to be done is load the Sharepoint .NET assembly and attach to the local farm&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(51, 102, 255);"&gt;&lt;br /&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")&lt;br /&gt;$farm = [microsoft.sharepoint.administration.spfarm]::local&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Then  load the XML configuration file and loop through all Web Applications.&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(51, 102, 255);"&gt;&lt;br /&gt;function main()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;$moss = "Sharepoint"&lt;br /&gt;$cfg = [xml](gc $cfgFile)&lt;br /&gt;&lt;br /&gt;if( $? -eq $false ) {&lt;br /&gt;  Write-Host "Could not cleanly parase XML file. Exiting . . ."&lt;br /&gt;  return $false&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Write-Host "Found Sharepoint Farm on Local Host  . . "&lt;br /&gt;&lt;br /&gt;Write-Host "Using $cfgFile file . . ."&lt;br /&gt;&lt;br /&gt;$cfg.$moss.WebApplication | % {&lt;br /&gt;&lt;br /&gt;  createWebApp( $_ )&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;main&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Surprisingly to create new Web Application, all you need to do is create a Powershell object of type SPWebApplicationBuilder, assign the proper variables, create and then provision.  The command can take up to 10 minutes to complete so be patient.&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(51, 102, 255);"&gt;&lt;br /&gt;function createWebApp( [object] $cfg )&lt;br /&gt;{&lt;br /&gt;$webAppBuilder = $nul&lt;br /&gt;$webAppBuilder =  new-object _&lt;br /&gt;    microsoft.sharepoint.administration.SPWebApplicationBuilder($farm)&lt;br /&gt;&lt;br /&gt;$secureString = ConvertTo-SecureString $cfg.AppPoolPass -asPlainText -force&lt;br /&gt;&lt;br /&gt;$webAppBuilder.Port = $cfg.port&lt;br /&gt;$webAppBuilder.ApplicationPoolId =  $cfg.AppPoolName&lt;br /&gt;$webAppBuilder.ApplicationPoolUsername = $cfg.AppPoolUser&lt;br /&gt;$webAppBuilder.ApplicationPoolPassword = $secureString&lt;br /&gt;&lt;br /&gt;$webAppBuilder.HostHeader = $cfg.hostheader&lt;br /&gt;$webAppBuilder.ServerComment = $cfg.name&lt;br /&gt;$webAppBuilder.DatabaseServer = $cfg.DatabaseServer&lt;br /&gt;$webAppBuilder.DatabaseName = $cfg.DatabaseName&lt;br /&gt;$webAppBuilder.RootDirectory = $cfg.RootDirectory&lt;br /&gt;&lt;br /&gt;if( $cfg.AllowAnonymous.ToString().ToLower() -eq "true" ) {&lt;br /&gt;  $webAppBuilder.AllowAnonymousAccess = $true&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Write-Host "Will now Provision this Web Application."&lt;br /&gt;Write-Host "This may take up to 10 minutes. . ."&lt;br /&gt;$webApp = $webAppBuilder.Create()&lt;br /&gt;$webApp.Provision()&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Finally, loop through all Sites that are listed in the XML and add them to the Web Application.&lt;br /&gt;&lt;blockquote style="color: rgb(51, 102, 255);"&gt;&lt;br /&gt;  $cfg.Sites.Site | % {&lt;br /&gt;      $title = $_.SiteTitle.ToString()&lt;br /&gt;      $path = $_.Path.ToString()&lt;br /&gt;&lt;br /&gt;      rite-Host "Will now Provision Site - $title ($path). "&lt;br /&gt;      Write-Host "This may take up to 10 minutes. . ."&lt;br /&gt;&lt;br /&gt;      $webApp.Sites.Add( $_.Path,&lt;br /&gt;               $_.Title,&lt;br /&gt;               $_.Description,&lt;br /&gt;               1033,&lt;br /&gt;               $_.Type,&lt;br /&gt;               $_.AdminAccount,&lt;br /&gt;               $_.AdminName,&lt;br /&gt;               $_.AdminEmail)&lt;br /&gt;  }&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;See easy as 1, 2, 3 . . .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-6377526587696495105?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2008/04/powershell-script-to-create-sharepoint.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-5658306511518351106</guid><pubDate>Mon, 11 Feb 2008 05:08:00 +0000</pubDate><atom:updated>2008-02-11T06:09:34.941-08:00</atom:updated><title>Powershell Scriptblocks</title><description>One of the interesting features that is, I believe, little know in Powershell is the scriptblock.  What is a scriptblock? The way that I define it is a function or block of code that is assigned to a variable.  Why do you need to know about this?  I've found it most useful when using Powershell to create a GUI.  You have to assign an action to an element on the GUI (like a Button). But the action can not be a function. It must be a script block.  You can define the block as a variable or  define it within the {} of the Add_Click method of the System.Windows.Forms.Button object.&lt;br /&gt;&lt;span style="font-family:monospace;"&gt;&lt;br /&gt;&lt;/span&gt;Now I'm probably completely wrong with this, and if I am I would love to learn more about it.  So please let me know! I want to cover how to create GUIs in Powershell in couple weeks so I will be building off this blog post.&lt;br /&gt;&lt;br /&gt;So how do you create a Script block. Its easy as assigning a variable to a anything within {}.&lt;br /&gt;&lt;br /&gt;A simple case would be something like&lt;br /&gt;&lt;blockquote style="color: rgb(51, 102, 255);"&gt;PS C:\temp&gt; $x = { Write-Host "Hello, World!" }&lt;br /&gt;&lt;br /&gt;PS C:\temp&gt; $x.GetType()&lt;br /&gt;&lt;br /&gt;IsPublic IsSerial Name                                     BaseType&lt;br /&gt;-------- -------- ----                                     --------&lt;br /&gt;True     False    ScriptBlock                              System.Object&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you just call the variable, it will return the block definition&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(51, 102, 255);"&gt;PS C:\temp&gt; $x&lt;br /&gt;Write-Host "Hello, World!"&lt;/blockquote&gt;&lt;br /&gt;To invoke the scriptblock, you need to call the Inovke() method of the script&lt;br /&gt;&lt;br /&gt;&lt;blockquote style="color: rgb(51, 102, 255);"&gt;PS C:\temp&gt; $x.Invoke()&lt;br /&gt;Hello, World!&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Within the scriptblock, you can do whatever you want to do. It can be multiple lines, you can even call functions from within the block.  For example:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;PS C:\temp&gt; function y () {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&gt;&gt; Write-Host "Within function y"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&gt;&gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&gt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;PS C:\temp&gt; y&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Within function y&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;PS C:\temp&gt; $x = {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&gt;&gt; Write-Host "Within scriptblock x"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&gt;&gt; y&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&gt;&gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&gt;&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;PS C:\temp&gt; $x.Invoke()&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Within scriptblock x&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Within function y&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Here are all of the methods that Scriptblocks provides within Powershell&lt;br /&gt;&lt;blockquote style="color: rgb(51, 102, 255);"&gt;&lt;br /&gt;PS C:\temp&gt; $x | Get-Member&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; TypeName: System.Management.Automation.ScriptBlock&lt;br /&gt;&lt;br /&gt;Name             MemberType Definition&lt;br /&gt;----             ---------- ----------&lt;br /&gt;Equals           Method     System.Boolean Equals(Object obj)&lt;br /&gt;GetHashCode      Method     System.Int32 GetHashCode()&lt;br /&gt;GetType          Method     System.Type GetType()&lt;br /&gt;get_IsFilter     Method     System.Boolean get_IsFilter()&lt;br /&gt;Invoke           Method     System.Collections.ObjectModel.Collection`1[[System.Management.Automation.PSObject, Syst...&lt;br /&gt;InvokeReturnAsIs Method     System.Object InvokeReturnAsIs(Params Object[] args)&lt;br /&gt;set_IsFilter     Method     System.Void set_IsFilter(Boolean value)&lt;br /&gt;ToString         Method     System.String ToString()&lt;br /&gt;IsFilter         Property   System.Boolean IsFilter {get;set;}&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;I hope this gives you an introduction into scriptblocks. Next time, hopefully, we can cover the TCL/TK-like feature of Powershell - its GUI.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-5658306511518351106?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2008/02/one-of-interesting-features-that-is-i.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-1433455108993136975</guid><pubDate>Wed, 16 Jan 2008 21:29:00 +0000</pubDate><atom:updated>2008-01-16T13:40:39.539-08:00</atom:updated><title>Q&amp;D Ping Function for Powershell</title><description>&lt;span style="color: rgb(51, 102, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;By default, Powershell does not have any built in functionality to send an ICMP ping to see if a remote computer is alive on and on the network.   But never fear because Powershell is based off .NET.  This means  it is very easy to implement a Ping function that you can add to a Powershell library file (along with other functions that I have blogged about previously).   The function is pretty straight forward. All that you really new to do is to create two .NET objects - Ping and PingReply.  My ping function only looks to see if a success was returned by ICMP. I am not looking for round trip time or to handle non-successful.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function Ping (  [string] $strComputer )&lt;br /&gt;{&lt;br /&gt;  $timeout=120;&lt;br /&gt;  trap { continue; }&lt;br /&gt;  &lt;br /&gt;  $ping = new-object System.Net.NetworkInformation.Ping &lt;br /&gt;  $reply = new-object System.Net.NetworkInformation.PingReply&lt;br /&gt;&lt;br /&gt;  $reply = $ping.Send($strComputer, $timeout);&lt;br /&gt;  if( $reply.Status -eq "Success"  ) &lt;br /&gt;  {&lt;br /&gt;     return $true;&lt;br /&gt;  }&lt;br /&gt;  return $false;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Again that's it.  The trap command will just ignore any errors that are throw by the $ping.Send command.  If anyone has questions than you can always email me at brian@bjd145.org.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-1433455108993136975?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2008/01/q-ping-function-for-powershell.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-1320459165659516628</guid><pubDate>Mon, 07 Jan 2008 04:54:00 +0000</pubDate><atom:updated>2008-01-06T20:54:29.700-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>powershell</category><category domain='http://www.blogger.com/atom/ns#'>windows</category><title>Powershell and XML Configuration Files</title><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;One of the things that I almost always create when I am developing a script is a configuration file. Utilizing XML for a configuration file format is very easy with Powershell.&amp;nbsp; The first thing that you need to do is to layout your XML file. I typically don't create a DTD or verify the XML schema because well, only my scripts will be using the XML configuration file.&amp;nbsp; Not completely within spec, but I've learn to live with it. The XML does need to be well formed with proper closing brackets, root node, etc in order for Powershell to read the XML but that is the only restriction.&lt;/p&gt; &lt;p&gt;The most common XML file that I create includes a list of servers and some attribute about those servers. A simple&amp;nbsp; example that of a test application that is made up of three web servers and a database server. The way that I would create the XML would be as follows:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font color="#000080"&gt;&amp;lt;test_app_servers&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;dbs server="vm-dbs1" dbsname="eut"/&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;web dir="d$\inetpub\wwwroot"&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;server&amp;gt;vm-test1&amp;lt;/server&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;server&amp;gt;vm-test2&amp;lt;/server&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;server&amp;gt;vm-test3&amp;lt;/server&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/web&amp;gt;&amp;lt;/test_app_servers&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Now the important part, how does Powershell read the XML.&amp;nbsp; The code is very straight forward. You use the get-content command and cast the file as XML.&amp;nbsp; The command is:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font color="#000080"&gt;$cfgFile = ".\test_app_config.xml"&lt;br&gt;$root = "test_app_servers"&lt;br&gt;$cfg = [xml] ( gc $cfgFile )&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Now once you have the configuration saved in the variable $cfg then how do you use it?&amp;nbsp; Powershell stores the information in a tree format so it is easy to get at. Some samples of how to get at the data include:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font color="#000080"&gt;$strDbsName = $cfg.$root.dbs.dbsname&lt;/font&gt; &lt;p&gt;&lt;font color="#000080"&gt;$strDbsServer = $cfg.$root.dbs.server&lt;/font&gt; &lt;p&gt;&lt;font color="#000080"&gt;$strWebDir = $cfg.$root.web.dir&lt;/font&gt; &lt;p&gt;&lt;font color="#000080"&gt;$cfg.$root.web.server | % { &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $strWebServer = $_&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Content of &lt;/font&gt;&lt;a href="file://\\$strWebServer\$strWebDir"&gt;&lt;font color="#000080"&gt;\\$strWebServer\$strWebDir&lt;/font&gt;&lt;/a&gt;&lt;font color="#000080"&gt;"&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dir &lt;/font&gt;&lt;a href="file://\\$strWebServer\$strWebDir"&gt;&lt;font color="#000080"&gt;\\$strWebServer\$strWebDir&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;&lt;font color="#000080"&gt;}&lt;/font&gt;&lt;/blockquote&gt; &lt;p&gt;And that is all you should need to know in order to utilize XML as a configuration file with Powershell&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-1320459165659516628?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2008/01/powershell-and-xml-configuration-files.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-1616842501609331367</guid><pubDate>Thu, 27 Dec 2007 17:22:00 +0000</pubDate><atom:updated>2007-12-27T09:22:48.189-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>powershell</category><category domain='http://www.blogger.com/atom/ns#'>vmware powershell</category><title>Update to VMware's Powershell Toolkit</title><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Just wanted to throw this out there for anyone using VMware's Powershell toolkit. They released a new CTP on 12/26. The file version is 68764.&amp;nbsp; They've added a bunch of new commands such as Get-Inventory, New/Get-OSCustomizationSpec, Add-VMHost, Move-Datacenter, Move-Cluster, Find-EntityViews, etc . . &lt;/p&gt; &lt;p&gt;I need to find some time to play with these new commands. I do know that the base Get-VIServer and Get-VMHost do work with ESX 3.5 which is nice to see as well.&lt;/p&gt; &lt;p&gt;Until I have more scripts to share. . . &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-1616842501609331367?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2007/12/update-to-vmware-powershell-toolkit.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-2589308881352341097</guid><pubDate>Mon, 03 Dec 2007 03:53:00 +0000</pubDate><atom:updated>2007-12-02T20:12:33.617-08:00</atom:updated><title>How to Find all Domain Computers Using Powershel</title><description>I'm asked a lot to find out something from all the servers in my Active Directory domain. Like "Tell me the free space on all servers in the domain" or "List all of the error events from Microsoft's Event Viewer for servers in the domain." These two questions can be answered very easily using WMI and Powershell,namely the get-WMIobject function. But how to get all of the server names? Using VBScript, this can be accomplished by using ADSI. But the code is hard to follow and I never really got a hang of using the ADSI calls. But why uses that when there is a great tool made already.  dsquery.  dsquery is tool written by Microsoft to query Active Directory (http://technet2.microsoft.com/WindowsServer/en/Library/46ba1426-43fd-4985-b429-cd53d3046f011033.mspx). Using this and combined with Powershell is Quick and Dirty but as always gets the job done.&lt;br /&gt;&lt;br /&gt;So how do you use it?   First the basic . . .&lt;br /&gt;&lt;br /&gt;dsquery computer "ou=Domain Controllers,DC=example,DC=com" will find all servers in the Organizational Unit Domain Controllers. dsquery has a option 'server' which will do the same thing (dsquery servers)&lt;br /&gt;&lt;br /&gt;The return result is . . .&lt;br /&gt;"CN=DC03,OU=Domain Controllers,DC=example,DC=com"&lt;br /&gt;"CN=DC02,OU=Domain Controllers,DC=example,DC=com"&lt;br /&gt;"CN=DC01,OU=Domain Controllers,DC=example,DC=com"&lt;br /&gt;&lt;br /&gt;To return all computers, just do  ....&lt;br /&gt;dsquery computer -limit 0  - The limit 0 tells dsquery not to limit the number of systems it returns. I believe the default is 100.&lt;br /&gt;&lt;br /&gt;dsquery can also be used to find servers in the domain . . . .&lt;br /&gt;dsquery computer -name "*WEB*"  will return &lt;br /&gt;"CN=DRWEB01,OU=Web,OU=Disaster Recovery,OU=Machines,OU=Shared Applications,DC=example,DC=com"&lt;br /&gt;"CN=DEV-WEB01,OU=Development,OU=Machines,OU=Shared Applications,DC=example,DC=com"&lt;br /&gt;"CN=STG-WEB01,OU=Stage,OU=Machines,OU=Shared Applications,DC=example,DC=com"&lt;br /&gt;"CN=STG-WEB02,OU=Stage,OU=Machines,OU=Shared Applications,DC=example,DC=com"&lt;br /&gt;"CN=PRD-WEB01,OU=Production,OU=Machines,OU=Shared Applications,DC=example,DC=com"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So can this be used with Powershell.  As long as dsquery is located in the path where powershell can call it from, just write a function such as this&lt;br /&gt;&lt;br /&gt;function GetDomainServers {&lt;br /&gt;        return @( dsquery computer -limit 0 -o rdn | % { $_.Split("`"")[1] } )&lt;br /&gt;} &lt;br /&gt;The -o rdn means to just return the server name. The server name will be in quotes which is why the return values are piped into Split("`""). This will split the server name into 3 parts. We just want the second value. This is combined to form an array which is returned.&lt;br /&gt;&lt;br /&gt;In other words,&lt;br /&gt;dsquery computer -limit 0 -o rdn  returns "PRD-WEB01". &lt;br /&gt;The powershell command Split("`"") will split the value on ".  &lt;br /&gt;This returns &lt;br /&gt;"&lt;br /&gt;PRD-WEB01&lt;br /&gt;"&lt;br /&gt;&lt;br /&gt;To call this function, its as easy as $servers = GetDomainServers.&lt;br /&gt;&lt;br /&gt;Well that's it. As always, I would love to hear feed back from anyone who finds these posts interesting and helpful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-2589308881352341097?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2007/12/how-to-find-all-domain-computers-using.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-6866760815411203567</guid><pubDate>Wed, 28 Nov 2007 18:44:00 +0000</pubDate><atom:updated>2008-03-25T08:54:08.593-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>batch sql</category><title>Restoring A Database with  transaction logs</title><description>&lt;p&gt;I've been often asked to restore a database to another server and have all transactions logs applied to it up to a certain point. Using SQL Server 2005, you could setup Transaction Log shipping and it works very well, or you could copy the files over manually then apply them manually using SQL Server Enterprise Studio. Well I'm lazy so I came up with this simple script to do the work for me . . .&lt;/p&gt;&lt;p&gt;This script will ask for the database name to be restored as well as the directory where the transaction logs , drop any existing database of that name, restore the database and its transaction logs. It will not setup your database backups (full or transaction) nor will it replicate them over. I do have scripts for this but a tool like SyncBackSE works just as well. Oh this is a Windows batch script that utilizes osql which comes with SQL Server 2005.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;@echo off &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;set BAKFILE=%1&lt;br /&gt;set DBSNAME=%2&lt;br /&gt;set LOGDIR=%3&lt;/span&gt; &lt;p&gt;&lt;span style="color:#0000ff;"&gt;IF NOT DEFINED BAKFILE (GOTO HELP)&lt;br /&gt;IF NOT DEFINED DBSNAME (GOTO HELP)&lt;br /&gt;IF NOT DEFINED LOGDIR (GOTO HELP) &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;echo Using the following variables to restore the database&lt;br /&gt;echo Database Backup file - %BAKFILE%&lt;br /&gt;echo Database Name - %DBSNAME%&lt;br /&gt;echo Trans Log Directory - %LOGDIR%&lt;br /&gt;choice /M "Do you want to continue" &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;IF ERRORLEVEL 2 ( GOTO END) &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;set DATADIR=d:\DATA&lt;br /&gt;set SQL=%TMP%\restore.sql&lt;br /&gt;set OUT=.\restore_results.txt &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;IF EXIST %SQL% ( del %SQL% ) &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;IF NOT EXIST %BAKFILE% (&lt;br /&gt;echo %BAKFILE does not exist. Must exit.&lt;br /&gt;GOTO END&lt;br /&gt;) &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;echo USE [MASTER] &amp;gt; %SQL%&lt;br /&gt;echo GO &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo ALTER DATABASE %DBS% SET SINGLE_USER WITH ROLLBACK_IMMEDIATE &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo GO &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo DROP DATABASE %DBS% &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo GO &amp;gt;&amp;gt; %SQL%&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;echo RESTORE DATABASE [%DBSNAME%] &amp;gt; %SQL%&lt;br /&gt;echo FROM DISK = '%BAKFILE%' &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo WITH NORECOVERY &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo GO &amp;gt;&amp;gt; %SQL% &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;for /f "tokens=* delims= " %%a in ('dir /b /a-d /od %LOGDIR%\*.trn') do (&lt;br /&gt;echo RESTORE LOG [%DBSNAME%] &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo FROM DISK = '%LOGDIR%\%%a' &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo WITH NORECOVERY &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo GO &amp;gt;&amp;gt; %SQL%&lt;br /&gt;set LAST=%%a&lt;br /&gt;) &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;echo RESTORE LOG [%DBSNAME%] &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo FROM DISK = '%LOGDIR%\%LAST%' &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo WITH RECOVERY &amp;gt;&amp;gt; %SQL%&lt;br /&gt;echo GO &amp;gt;&amp;gt; %SQL% &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;osql -E -w 5000 -i %SQL% -o %OUT%&lt;br /&gt;GOTO END &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;:HELP&lt;br /&gt;echo.&lt;br /&gt;echo Usage: restore_dbs.bat [BAKFILE] [DBSNAME] [LOG DIR]&lt;br /&gt;echo.&lt;br /&gt;echo.&lt;br /&gt;echo BAKFILE - The full path to a recent backup file of the database&lt;br /&gt;echo DBSNAME - Name of the new database&lt;br /&gt;echo LOG DIR - The full path to a directory that contains all the recent tanslogs&lt;br /&gt;echo *The LOG DIR should not contain any transaction logs older than BAKFILE&lt;br /&gt;echo.&lt;br /&gt;echo Eg: restore.bat d:\Backups\SampleDBS_backup_200705222201.bak SampleDBS d:\Temp&lt;br /&gt;echo. &lt;/span&gt;&lt;p&gt;&lt;span style="color:#0000ff;"&gt;:END&lt;br /&gt;IF EXIST %SQL% ( del %SQL% ) &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-6866760815411203567?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2007/11/restoring-database-with-transaction.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>3</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-8677150168867840951</guid><pubDate>Mon, 26 Nov 2007 14:11:00 +0000</pubDate><atom:updated>2007-11-26T06:11:58.669-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>powershell</category><category domain='http://www.blogger.com/atom/ns#'>vmware powershell</category><category domain='http://www.blogger.com/atom/ns#'>vmware</category><title>VMware's Very Cool Get-Stat Command</title><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Today I want to briefly show&amp;nbsp; you the power of the VMware's Get-State command.&amp;nbsp; With it you can grab statistics on any VI entity - ESX Host, Virtual Machine, or Resource Pool.&amp;nbsp; To use it, all you need to do is supply the entity you want to monitor and which statistics do you want to grab (common, CPU, memory, disk, or network). So let's get some stats on an ESX host.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&amp;nbsp;&lt;font color="#0000ff"&gt;$&lt;em&gt;vc = Get-VIServer "vc1.example.com"&lt;/em&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;$esx = Get-VIHost "esx1.example.com"&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;Get-Stat $esx -Memory -maxsamples 3 -realtime&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;MetricId&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Timestamp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value Unit&lt;br&gt;---------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----- ----&lt;br&gt;mem.vmmemctl.average 11/26/2007 1:52:2...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 KB&lt;br&gt;mem.vmmemctl.average 11/26/2007 1:52:0...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 KB&lt;br&gt;mem.vmmemctl.average 11/26/2007 1:51:4...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 KB  &lt;p&gt;Value&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 21.49&lt;br&gt;Timestamp&amp;nbsp;&amp;nbsp; : 11/26/2007 1:52:20 PM&lt;br&gt;MetricId&amp;nbsp;&amp;nbsp;&amp;nbsp; : mem.usage.average&lt;br&gt;Unit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : %&lt;br&gt;Description : Memory usage as percentage of total configured or available memory&lt;br&gt;Entity&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : VMware.VimAutomation.Client20.VMHostImpl  &lt;p&gt;Value&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 21.49&lt;br&gt;Timestamp&amp;nbsp;&amp;nbsp; : 11/26/2007 1:52:00 PM&lt;br&gt;MetricId&amp;nbsp;&amp;nbsp;&amp;nbsp; : mem.usage.average&lt;br&gt;Unit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : %&lt;br&gt;Description : Memory usage as percentage of total configured or available memory&lt;br&gt;Entity&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : VMware.VimAutomation.Client20.VMHostImpl  &lt;p&gt;Value&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 21.49&lt;br&gt;Timestamp&amp;nbsp;&amp;nbsp; : 11/26/2007 1:51:40 PM&lt;br&gt;MetricId&amp;nbsp;&amp;nbsp;&amp;nbsp; : mem.usage.average&lt;br&gt;Unit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : %&lt;br&gt;Description : Memory usage as percentage of total configured or available memory&lt;br&gt;Entity&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : VMware.VimAutomation.Client20.VMHostImpl  &lt;p&gt;mem.active.average&amp;nbsp;&amp;nbsp; 11/26/2007 1:52:2...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 78988 KB&lt;br&gt;mem.active.average&amp;nbsp;&amp;nbsp; 11/26/2007 1:52:0...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 78988 KB&lt;br&gt;mem.active.average&amp;nbsp;&amp;nbsp; 11/26/2007 1:51:4...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 78988 KB&lt;br&gt;mem.granted.average&amp;nbsp; 11/26/2007 1:52:2...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2097504 KB&lt;br&gt;mem.granted.average&amp;nbsp; 11/26/2007 1:52:0...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2097504 KB&lt;br&gt;mem.granted.average&amp;nbsp; 11/26/2007 1:51:4...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2097504 KB &lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;Get-Stat $esx -common -maxsamples 1 -realtime&lt;/font&gt;&lt;/em&gt; &lt;p&gt;MetricId&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Timestamp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value Unit&lt;br&gt;---------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----- ----&lt;br&gt;cpu.usage.average&amp;nbsp;&amp;nbsp;&amp;nbsp; 11/26/2007 2:05:4...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.86 %  &lt;p&gt;Value&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 297&lt;br&gt;Timestamp&amp;nbsp;&amp;nbsp; : 11/26/2007 2:05:40 PM&lt;br&gt;MetricId&amp;nbsp;&amp;nbsp;&amp;nbsp; : cpu.usagemhz.average&lt;br&gt;Unit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : MHz&lt;br&gt;Description : CPU usage in MHz over the collected interval. For hosts this can be represented on a per Virtual Machine&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basis as a stacked graph&lt;br&gt;Entity&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : VMware.VimAutomation.Client20.VMHostImpl  &lt;p&gt;mem.usage.average&amp;nbsp;&amp;nbsp;&amp;nbsp; 11/26/2007 2:05:4...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 21.48 %  &lt;p&gt;Value&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 105&lt;br&gt;Timestamp&amp;nbsp;&amp;nbsp; : 11/26/2007 2:05:40 PM&lt;br&gt;MetricId&amp;nbsp;&amp;nbsp;&amp;nbsp; : disk.usage.average&lt;br&gt;Unit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : KBps&lt;br&gt;Description : Aggregated storage performance statistics. For hosts this can be represented on a per Virtual Machine bas&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; is as a stacked graph&lt;br&gt;Entity&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : VMware.VimAutomation.Client20.VMHostImpl &lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;And finally,&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;$stats = Get-Stat $esx -common -maxsamples 1 -realtime&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;$stats. GetType()&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;IsPublic IsSerial Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BaseType&lt;br&gt;-------- -------- ----&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --------&lt;br&gt;True&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; True&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Object[]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Array &lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;Since the object returned to you is an array,this allows you to store and manipulate the return results - like&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;$stats[2]&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;MetricId&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Timestamp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value Unit&lt;br&gt;---------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----- ----&lt;br&gt;mem.usage.average&amp;nbsp;&amp;nbsp;&amp;nbsp; 11/26/2007 2:07:0...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 21.48 %&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;or $stats[2].Value&lt;/font&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;21.48&lt;/p&gt; &lt;p&gt;&lt;font color="#0000ff"&gt;&lt;em&gt;These values can then be piped into a table or graph to display the results.&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Next week, I want to go back to something basic in Powershell - XML configuration. Powershell makes parsing XML documents very easy and I want to show how you can use this to create XML configuration files.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-8677150168867840951?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2007/11/vmware-very-cool-get-stat-command.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-2115172269848295235</guid><pubDate>Wed, 21 Nov 2007 23:06:00 +0000</pubDate><atom:updated>2007-11-21T15:06:57.589-08:00</atom:updated><title>First post using Windows Live Writer</title><description>&lt;p&gt;This is a posting using Microsoft Live Writer which means this will be a short post.&lt;/p&gt; &lt;p&gt;Just want to say Happy Thanksgiving!!!!&lt;/p&gt; &lt;p&gt;Brian&lt;/p&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-2115172269848295235?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2007/11/first-post-using-windows-live-writer.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-3859753814899934719</guid><pubDate>Wed, 14 Nov 2007 17:04:00 +0000</pubDate><atom:updated>2007-11-14T09:24:01.437-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>vmware powershell</category><title>Creating a VM from a Template using Powershell</title><description>Yesterday, I posted that I was having issues creating a new VM from a template while using VMware's Powershell commands.  It must have been the weather or something because today, it seems to be working without any issues.   The following is how you can create a new VM from a template using Powershell. I did notice one interesting thing that I want to ask VMware about which I will mention at the end of this entry.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;PS C:\Temp&gt; $vc = Get-VIServer "vc.example.com"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;There were one or more problems with the server certificate:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;* The certificate's CN name does not match the passed value.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;PS C:\Temp&gt; $t = Get-Template -Server $vc&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;PS C:\Temp&gt; $t[0]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Name                 Id&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;----                 --&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;ESX3-WIN2K3SP2-ST... VirtualMachine-vm-23637&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;PS C:\Temp&gt; $esx = Get-VMHost -Name "esx1.example.com"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;PS C:\Temp&gt; $esx&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Name                 Id&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;----                 --&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;esx1.example.com   HostSystem-host-7523&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;PS C:\Temp&gt; New-VM -Host $esx -Template $t[0]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;cmdlet New-VM at command pipeline position 1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Supply values for the following parameters:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Name: vm-1&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;At this point, a  Powershell progress bar appears and the progress of the deployment can be tracked.  &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;The shell's focus is not returned until after the deployment is complete. &lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;The interesting thing is, that I can CTRL-C and cancel this Powershell command but the template continues to be deployed from within VirtualCenter.  I am not sure how VMware will handle this situation but I would expect the deployment to be canceled once I cancel the Powershell command. I would love to hear any one else's thoughts on this matter as well. &lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-3859753814899934719?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2007/11/creating-vm-from-template-using.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-2595099621527228826</guid><pubDate>Tue, 13 Nov 2007 14:38:00 +0000</pubDate><atom:updated>2007-11-14T06:23:35.444-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>vmware powershell</category><title>Creating a Virtual Machine with Powershell</title><description>Sorry for the delay in posting this week. I had out-of-town guests in all weekend so everything has been turned upside down.  I would like to continue from last week and show how easy it is to create a new virtual machine with Powershell. Again you'll need the VMware Powershell management Snap-in before you have access to these commands.&lt;br /&gt;&lt;br /&gt;To Create a Virtual Machine, you need to do the following:&lt;br /&gt;1. Connect to your Virtual Center server -&lt;br /&gt;&lt;ul&gt;&lt;li&gt;$vc = Get-VIServer -Server "vc.example.com"&lt;/li&gt;&lt;/ul&gt;2. Connect to the ESX Host where you want to create the VM -&lt;br /&gt;&lt;ul&gt;&lt;li&gt;$esx = Get-VMHost -Server $vc -Name "esx.example.com"&lt;/li&gt;&lt;/ul&gt;3.  Create the virtual machine -&lt;br /&gt;&lt;ul&gt;&lt;li&gt;$vm = New-VM $esx&lt;br /&gt;&lt;/li&gt;&lt;li&gt;This will create a VM with a 4GB hard drive and 256MB of RAM.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;The network will be the first Network Label sorted alphabetically&lt;/li&gt;&lt;/ul&gt;4.  If you want, you can specify options while you are creating the VM or you can use the Set-VM to modify the VM's specifications.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Set-VM $vm -MemoryMB 2048 -NumCPU 4 -Network "Local Lan"&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;Proceed with update of the following parameters of virtual machine with name 'blah'?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;New MemoryMB: 2048MB&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;New NumCPU: 4&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;New Networks: LAN-1,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;I tried to create a new VM from a template with the following steps, but I continually got an error while doing so. I guess this just goes to show that VMware is still developing this code and it has some ways to go.&lt;br /&gt;&lt;br /&gt;1. Get all templates that VC knows about&lt;br /&gt;&lt;ul&gt;&lt;li&gt;$t = Get-Templates -Server $vc&lt;/li&gt;&lt;/ul&gt;2. Create new virtual machine from the first template&lt;br /&gt;&lt;ul&gt;&lt;li&gt;$vm = New-VM -Host $y -Template $t[0]&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;cmdlet New-VM at command pipeline position 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Supply values for the following parameters:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Name: blah2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;New-VM : The operation for the entity vm-3179 failed with the following message: "A specified parameter was not correct&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;If someone could show me what I am doing wrong, that would be great.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-2595099621527228826?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2007/11/creating-virtual-machine-with.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>7</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-3254110789419905772</guid><pubDate>Tue, 06 Nov 2007 04:53:00 +0000</pubDate><atom:updated>2007-11-14T06:24:16.220-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>powershell</category><category domain='http://www.blogger.com/atom/ns#'>vmware</category><title>PowerShell and VMware Managment</title><description>I know that I just blogged yesterday about sending emails with PowerShell, BASH, and VBScript, but I got a chance today to install VMware's PSSnapin for Powershell.  From the looks of this beta, its going to be a very powerful product that almost anyone can write scripts for.  What an example.&lt;br /&gt;&lt;br /&gt;I wrote a script in Perl using VMware's Perl SDK to display any VM Snapshot that a supplied VirtualCenter knows about. The code to do this in Perl is as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre  style="color: rgb(0, 0, 0);font-family:courier new;"&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;use strict;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;use warnings;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;use Getopt::Long;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;use VMware::VIRuntime;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;use Term::ReadKey;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;my %opts = (server =&gt; undef,&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);"&gt; username =&gt; undef,&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;GetOptions (\%opts,&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;"server=s",&lt;/span&gt;&lt;span style="color: rgb(51, 102, 255);"&gt; "username=s");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;if( !defined ($opts{server} &amp;amp;&amp;amp; $opts{username}) ) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;   help();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;   exit (1);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;ReadMode('noecho');&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;print "Enter $opts{username}\'s password: ";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;my $password = ReadLine(0);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;chomp $password;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;ReadMode('normal');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;# login&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;my $url = "https://" . $opts{server}. "/sdk/vimService";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Vim::login(service_url =&gt; $url, user_name =&gt; $opts{username}, password =&gt; $password);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;# get VirtualMachine views for all powered on VM's&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;my $vm_views = Vim::find_entity_views(view_type =&gt; 'VirtualMachine');&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;# snapshot each VM&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;my $i;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;foreach (@$vm_views) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt; if( defined $_-&gt;snapshot ) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;  print "-------------------------------------------------------------\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;  print $_-&gt;name . " has at least one snapshot defined  . . . \n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;  foreach $i (0 .. $#{$_-&gt;snapshot-&gt;rootSnapshotList} ) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;     print "\t" . $_-&gt;snapshot-&gt;rootSnapshotList-&gt;[$i]-&gt;name . " @ " . $_-&gt;snapshot-&gt;rootSnapshotList-&gt;[$i]-&gt;createTime . "\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;  print "-------------------------------------------------------------\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;# logout&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Vim::logout();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;sub help {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;   my $help_text = &lt;&lt;'END';  USAGE:    query_snapshot.pl --server &lt;/span&gt;&lt;virtual center=""&gt;&lt;span style="color: rgb(51, 102, 255);"&gt; --user &lt;/span&gt;&lt;user login=""&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;   query_snapshot.pl --server vc1 --user administrator&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;END&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;   print $help_text;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/user&gt;&lt;/virtual&gt;&lt;/pre&gt;&lt;br /&gt;Now using Powershell and the VMware Snapin:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);font-family:courier new;" &gt; Add-PSSnapin VMware.VimAutomation.Core&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);font-family:courier new;" &gt; Get-VIServer vc1.example.com&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(102, 51, 255);font-family:courier new;" &gt; Get-VM | % { $_.Name; Get-Snapshots $_ }&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;That's it. Everything is provided for you like Authentication, handling XML returned by VirutalCenter's Web Services, etc . . . The Perl SDK is very powerful as well, but you have to do a lot more coding to get things done.  With the PowerShell snapin, the script is all of three lines. Now the snapin is only in beta testing right now so things can change in the future.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-3254110789419905772?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2007/11/powershell-and-vmware-managment.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-3480005991510750299</guid><pubDate>Mon, 05 Nov 2007 04:00:00 +0000</pubDate><atom:updated>2007-11-08T20:54:55.170-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>powershell</category><category domain='http://www.blogger.com/atom/ns#'>linux</category><category domain='http://www.blogger.com/atom/ns#'>email</category><category domain='http://www.blogger.com/atom/ns#'>windows</category><category domain='http://www.blogger.com/atom/ns#'>vbscript</category><title>Sending email via a Script</title><description>One of the most basic tasks that any system administrator needs to accomplish while writing scripts is to send e-mail. Typically this is to send results of script itself or of some event.&lt;br /&gt;&lt;br /&gt;The easiest way to send email is if you are using Linux. Almost all Linux servers have the mail command installed by default. This command can be used by a BASH script to send your mail. The problem with the mail program is that it doesn't send attachments.   To send attachments, you'll need mutt.  Mutt can be installed via apt-get or yum or via tar balls, on all Linux systems.  To send an email via Mutt, you simply need to have the following line in your script&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;mutt -s $subject -c $ccpt_list -a $attachfile $rcpt_list &lt; $email  &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;The variables defined include:&lt;br /&gt;1. A subject ($subject)&lt;br /&gt;2. A receipt list ($rcpt_list). This is defined in BASH as rcpt_list=someone@company.com.&lt;br /&gt;3. The body of the email is stored in the variable/file $email. $email is a file on the server that is piped into the Mutt command. It is defined as  email=/tmp/email.tmp echo Hello World &gt;&gt; $email&lt;br /&gt;4. OPTIONAL: An attach file. The variable $attachefile holds the path location of the file to attache&lt;br /&gt;5. OPTIONAL: An CC list of email address.&lt;br /&gt;--&lt;br /&gt;&lt;br /&gt;Over in the Microsoft world, there isn't a command line mail program built into any Windows server, but VBScript is. All that you need to send email via VBScript is the following:&lt;br /&gt;&lt;br /&gt;&lt;pre style="color: rgb(51, 102, 255);"&gt;Const SMTP_SERVER = "SMTP mail server address"&lt;br /&gt;Const SMTP_PORT = 25&lt;br /&gt;&lt;br /&gt;Set objMessage = CreateObject("CDO.Message")&lt;br /&gt;objMessage.Sender = sSender 'Email address of sender&lt;br /&gt;objMessage.To = sRecipients 'Comma separate list of people who will receive the email&lt;br /&gt;objMessage.Subject = sSubject 'The subject of the email&lt;br /&gt;objMessage.Textbody = sBody 'The body of the email.&lt;br /&gt;&lt;br /&gt;'This is optional.  sAttachment is the fully qualified path to the file to attach&lt;br /&gt;objMessage.AddAttachment sAttachment&lt;br /&gt;&lt;br /&gt;objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2&lt;br /&gt;objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTP_SERVER&lt;br /&gt;objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTP_PORT&lt;br /&gt;objMessage.Configuration.Fields.Update&lt;br /&gt;&lt;br /&gt;objMessage.send&lt;br /&gt;&lt;/pre&gt;---&lt;br /&gt;&lt;br /&gt;With Powershell just being released from Microsoft, you can write a function to send email and include that function in all scripts that need to send email. The function could look something like this:&lt;br /&gt;&lt;br /&gt;&lt;pre style="color: rgb(51, 102, 255);"&gt;function send-email($s,$b,$to) {&lt;br /&gt;  $from = "send@company.com"; //Who will be sending the email&lt;br /&gt;  $domain  = "smtp.company.com"; //SMTP server to send the message&lt;br /&gt;&lt;br /&gt;  $mail = new-object System.Net.Mail.MailMessage;&lt;br /&gt;&lt;br /&gt;  for($i=0; $i -lt $to.Length; $i++) {&lt;br /&gt;     $mail.To.Add($to[$i]);&lt;br /&gt;  }&lt;br /&gt;  $mail.From = new-object System.Net.Mail.MailAddress($from);&lt;br /&gt;  $mail.Subject = $s;&lt;br /&gt;  $mail.Body = $b;&lt;br /&gt;&lt;br /&gt;  $smtp = new-object System.Net.Mail.SmtpClient($domain);&lt;br /&gt;  $smtp.Send($mail);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To call this function, you just need to do the following:&lt;br /&gt;&lt;br /&gt;&lt;pre style="color: rgb(51, 102, 255);"&gt;$SUBJECT="This is the subject";&lt;br /&gt;$EMAILADDR=@("person1@company.com","person2@company.com");&lt;br /&gt;$BODY="Hello World";&lt;br /&gt;send-email -s $SUBJECT -b $BODY -to $EMAILADDR&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Sending email is pretty easy and I know that there are  a lot of places on the Web that already so you how to send email. Hopefully, though we can build off this to build much more complex scripts.  I received an email from VMware concerning their Powershell interface to ESX. I am planning on next week to show how to write some simple scripts to manage an ESX build out with Powershell and we'll be using the send-email functions.&lt;br /&gt;&lt;br /&gt;Well this ends my first real blog post. I hope someone out there finds these scripts/functions useful and I will write more next week.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-3480005991510750299?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2007/11/sending-email-via-script.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-3859053332094757531.post-7791067697237181122</guid><pubDate>Mon, 29 Oct 2007 16:41:00 +0000</pubDate><atom:updated>2007-10-29T09:49:28.147-07:00</atom:updated><title>First Post!</title><description>Hi. My name is Brian Denicola  and this is the first post for what I hope will be a weekly blog that focuses on scripting for system administrators.  I have working in the IT world for the past 10 years and have been automating tasks for most of them. This blog will focus on getting things done using any language available. But I'll mainly focus on Windows batch scripting, Bash scripting, VBscript, Perl, and Powershell. Every once in a while I might throw in a how to script for ASP.NET or SQL. I I won't be going into too much theory of the language, rather I hope to show how to get things done in Windows, Linux, or even VMware ESX. And I hope this will become a site where others can post how they do things as well.&lt;br /&gt;&lt;br /&gt;Well that is all for now. Next time I will be show you how to send e-mail via powershell. I'll start simple and go from there.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3859053332094757531-7791067697237181122?l=www.bjd145.org%2Fscripting_blog.html' alt='' /&gt;&lt;/div&gt;</description><link>http://www.bjd145.org/2007/10/first-post.html</link><author>noreply@blogger.com (Brian Denicola)</author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></item></channel></rss>
