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

<channel>
	<title>Michael Phillips Blog &#187; Scripting</title>
	<atom:link href="http://nukeitmike.com/blog/tag/scripting/feed" rel="self" type="application/rss+xml" />
	<link>http://nukeitmike.com/blog</link>
	<description>My place to speak about things</description>
	<lastBuildDate>Thu, 29 Jul 2010 20:57:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using Powershell to get logon script path from Active Directory</title>
		<link>http://nukeitmike.com/blog/2010/07/29/using-powershell-to-get-logon-script-path-from-active-directory/</link>
		<comments>http://nukeitmike.com/blog/2010/07/29/using-powershell-to-get-logon-script-path-from-active-directory/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 20:57:31 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://nukeitmike.com/blog/2010/07/29/using-powershell-to-get-logon-script-path-from-active-directory/</guid>
		<description><![CDATA[If you want to know what logon script users are getting, this is an easy way to get that information: Import-Module -Name ActiveDirectory Get-ADUser -Filter * -SearchBase &#34;OU=YourOUName,DC=YourDomain,DC=COM&#34; -properties ScriptPath &#124; Export-Csv &#34;c:\script\ADUser.csv&#34; Note: In order for this to work, you have to have the ActiveDirectory Module loaded.&#160;]]></description>
			<content:encoded><![CDATA[<p>If you want to know what logon script users are getting, this is an easy way to get that information:</p>
<blockquote><p>Import-Module -Name ActiveDirectory </p>
<p>Get-ADUser -Filter * -SearchBase &quot;OU=YourOUName,DC=YourDomain,DC=COM&quot; -properties ScriptPath | Export-Csv &quot;c:\script\ADUser.csv&quot;</p>
</blockquote>
<p>Note: In order for this to work, you have to have the ActiveDirectory Module loaded.&#160; </p>
]]></content:encoded>
			<wfw:commentRss>http://nukeitmike.com/blog/2010/07/29/using-powershell-to-get-logon-script-path-from-active-directory//feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Not recognized as a cmdlet&#8230;</title>
		<link>http://nukeitmike.com/blog/2010/03/25/not-recognized-as-a-cmdlet/</link>
		<comments>http://nukeitmike.com/blog/2010/03/25/not-recognized-as-a-cmdlet/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 13:07:03 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://nukeitmike.com/blog/2010/03/25/not-recognized-as-a-cmdlet/</guid>
		<description><![CDATA[I have been working on a simple little script to copy a file and then launch a program.&#160; I am sure that there are a lot of ways to do it, but I decided to use PowerShell, and this is what I came up with: $CheckForFile = &#34;H:\custom.ini&#34; $FileToCopy = &#34;c:\IT\custom.ini&#34; $CopyFileTo = &#34;H:\&#34; $PathTest [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a simple little script to copy a file and then launch a program.&#160; I am sure that there are a lot of ways to do it, but I decided to use PowerShell, and this is what I came up with:</p>
<blockquote><p>$CheckForFile = &quot;H:\custom.ini&quot;     <br />$FileToCopy = &quot;c:\IT\custom.ini&quot;      <br />$CopyFileTo = &quot;H:\&quot; </p>
<p>$PathTest = Test-Path $CheckForFile      <br />If ($PathTest -eq &quot;false&quot;)      <br />&#160;&#160;&#160; {      <br />&#160;&#160;&#160; Copy-Item $FileToCopy $CopyFileTo      <br />&#160;&#160;&#160; } </p>
<p>#uses the Invoke-Item command to launch the application     <br />Invoke-Item &quot;C:\Program Files\executable to launch.exe&quot;</p>
</blockquote>
<p>This is for use in a Citrix/Terminal Server environment, so I want to be able to call this script like this: PowerShell copythenlaunch.ps1</p>
<p>When I tested that, I got this:</p>
<blockquote><p>C:\IT&gt;powershell copythenlaunch.ps1     <br />The term &#8216;copythenlaunch.ps1&#8242; is not recognized as a cmdlet, function, operable      <br /> program, or script file. Verify the term and try again.      <br />At line:1 char:18      <br />+ copythenlaunch.ps1 &lt;&lt;&lt;&lt;</p>
</blockquote>
<p>I kept thinking there was some problem with the install of PowerShell (I am running this particular script on a Windows 2003 Server) or that I had some illegal character in the name (it had a number in it originally) or some other simple problem.&#160; Finally I did a search and came across this little bit of conversation:</p>
<blockquote><p>re: Power and Pith<a name="1380970"></a></p>
</blockquote>
<blockquote><p>I just started with PowerShell.</p>
<p>Wanted to run some test scripts from you download.</p>
<p>When I tpye in Beep.ps1 I get &quot;The term &#8216;Beep.1&#8242; is not recognized&#8230;..&quot;</p>
<p>What Am I doing wrong?</p>
<p>Friday, December 29, 2006 3:17 PM by <a>MikeL</a></p>
<h6><a href="http://blogs.msdn.com/powershell/archive/2006/10/21/Power-and-Pith.aspx#1381442">#</a> re: Power and Pith<a name="1381442"></a></h6>
<p>&gt; When I tpye in Beep.ps1 I get &quot;The term &#8216;Beep.1&#8242; is not recognized&#8230;..&quot;</p>
<p>&gt; What Am I doing wrong?</p>
<p>You are relying upon a traditional bad shell behaviour that has been a security nightmere for decades.</p>
<p>In PowerShell, you have to be explicit if you want to run a command in the current directory.&#160; Type &quot;.\beep.ps1&quot;</p>
<p>Jeffrey Snover [MSFT]</p>
<p>Windows PowerShell/MMC Architect</p>
<p>Visit the Windows PowerShell Team blog at:&#160;&#160;&#160; <a href="http://blogs.msdn.com/PowerShell">http://blogs.msdn.com/PowerShell</a></p>
<p>Visit the Windows PowerShell ScriptCenter at:&#160; <a href="http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx">http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx</a></p>
<p>Friday, December 29, 2006 5:19 PM by <a href="http://blogs.msdn.com/user/Profile.aspx?UserID=29278">PowerShellTeam</a></p>
<h6><a href="http://blogs.msdn.com/powershell/archive/2006/10/21/Power-and-Pith.aspx#1865770">#</a> re: Power and Pith<a name="1865770"></a></h6>
<p><strong>Thank You for supplying the &quot;.\*&quot; information.&#160; I have been racking my brain for almost two days wondering what I was doing wrong.&#160; And to think it was as simple as using the PROPER .\yourscripthere.ps1 format.</strong></p>
<p>Thank you very very much</p>
</blockquote>
<p>Ditto on the thanks…</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2006/10/21/Power-and-Pith.aspx">Windows PowerShell Blog : Power and Pith</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nukeitmike.com/blog/2010/03/25/not-recognized-as-a-cmdlet//feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Confirm Preference</title>
		<link>http://nukeitmike.com/blog/2010/03/04/powershell-confirm-preference/</link>
		<comments>http://nukeitmike.com/blog/2010/03/04/powershell-confirm-preference/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 03:47:39 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://nukeitmike.com/blog/2010/03/04/powershell-confirm-preference/</guid>
		<description><![CDATA[I seem to run into an issue when I run some PowerShell scripts where I get prompted at each line of the script for confirmation.&#160; That can get really annoying, so I have to look up how to prevent that behavior.&#160; Thankfully, there is already some good information out there on how to do that: [...]]]></description>
			<content:encoded><![CDATA[<p> I seem to run into an issue when I run some PowerShell scripts where I get prompted at each line of the script for confirmation.&#160; That can get really annoying, so I have to look up how to prevent that behavior.&#160; Thankfully, there is already some good information out there on how to do that: </p>
<blockquote><p>When confirmation is turned on by $ConfirmPreference, you can turn it off for any individual cmdlet invocation using &quot;-Confirm:$false&quot;.&#160; You can also use &quot;-Confirm:$false&quot; to turn off default confirmation for high impact cmdlets such as Removing a Mailbox.&#160; Another way to turn off confirmation is by setting $ConfirmPreference to &quot;None&quot;; you can limit the effect by setting $script:ConfirmPreference etc, see &quot;get-help about_scope&quot; for more details.</p>
</blockquote>
<p>For more details and options besides just turning it off, go see the original post:</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2006/12/15/confirmpreference.aspx">Windows PowerShell Blog : ConfirmPreference</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nukeitmike.com/blog/2010/03/04/powershell-confirm-preference//feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Servers in Domain</title>
		<link>http://nukeitmike.com/blog/2010/02/24/servers-in-domain/</link>
		<comments>http://nukeitmike.com/blog/2010/02/24/servers-in-domain/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 03:24:25 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://nukeitmike.com/blog/2010/02/24/servers-in-domain-2/</guid>
		<description><![CDATA[At some point, I had a desire to list all the computer accounts for any server OS in Active Directory.  I am pretty sure that I did a search and found the script below, but I don’t remember where, so whoever wrote it doesn’t get credit this time… $strCategory = &#8220;computer&#8221; $strOperatingSystem = &#8220;Windows*Server*&#8221; $objDomain [...]]]></description>
			<content:encoded><![CDATA[<p>At some point, I had a desire to list all the computer accounts for any server OS in Active Directory.  I am pretty sure that I did a search and found the script below, but I don’t remember where, so whoever wrote it doesn’t get credit this time…</p>
<blockquote><p>$strCategory = &#8220;computer&#8221;<br />
$strOperatingSystem = &#8220;Windows*Server*&#8221;</p>
<p>$objDomain = New-Object System.DirectoryServices.DirectoryEntry</p>
<p>$objSearcher = New-Object System.DirectoryServices.DirectorySearcher<br />
$objSearcher.SearchRoot = $objDomain</p>
<p>$objSearcher.Filter = (&#8220;OperatingSystem=$strOperatingSystem&#8221;)</p>
<p>$colProplist = &#8220;name&#8221;<br />
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}</p>
<p>$colResults = $objSearcher.FindAll()<br />
Write-Host $colResults.count<br />
foreach ($objResult in $colResults)<br />
    {<br />
    $objComputer = $objResult.Properties;<br />
    $objComputer.name<br />
    }</p></blockquote>
<p>If you change the $strOperatingSystem = “Windows*Server*” to something like $strOperatingSystem = “Windows*”  it will return all computer accounts that have “Windows” in the Name field on the Operating System tab of the properties of the AD object:</p>
<p><a href="http://nukeitmike.com/blog/wp-content/uploads/2010/02/image.png"><img title="image" src="http://nukeitmike.com/blog/wp-content/uploads/2010/02/image_thumb.png" border="0" alt="image" width="644" height="263" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://nukeitmike.com/blog/2010/02/24/servers-in-domain//feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using XML in your PowerShell scripting</title>
		<link>http://nukeitmike.com/blog/2009/09/22/using-xml-in-your-powershell-scripting/</link>
		<comments>http://nukeitmike.com/blog/2009/09/22/using-xml-in-your-powershell-scripting/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 03:07:19 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://nukeitmike.com/blog/2009/09/22/using-xml-in-your-powershell-scripting/</guid>
		<description><![CDATA[I have written a lot of scripts that use .txt files to read or store data, but I have a need to read some information from an .xml file.  This could be done by treating the file as a simple txt file, but it would require some pretty good filtering that is already a part [...]]]></description>
			<content:encoded><![CDATA[<p>I have written a lot of scripts that use .txt files to read or store data, but I have a need to read some information from an .xml file.  This could be done by treating the file as a simple txt file, but it would require some pretty good filtering that is already a part of the xml file.  A quick search helped me locate this article:</p>
<blockquote><p><a title="http://blogs.msdn.com/kalleb/archive/2008/07/19/using-powershell-to-read-xml-files.aspx" href="http://blogs.msdn.com/kalleb/archive/2008/07/19/using-powershell-to-read-xml-files.aspx">http://blogs.msdn.com/kalleb/archive/2008/07/19/using-powershell-to-read-xml-files.aspx</a></p></blockquote>
<p>Which contained the key to helping me with what I needed to do.  The specific piece I needed was in Lesson 2:</p>
<blockquote><p>Lesson 2:<br />
Read data from an XML-file.<br />
The XML-file that I&#8217;m going to read from has the following structure:<br />
&lt;Users&gt;<br />
  &lt;User&gt;<br />
    &lt;Name&gt;Kalle&lt;/Name&gt;<br />
&lt;/User&gt;<br />
  &lt;User&gt;<br />
    &lt;Name&gt;Becker&lt;/Name&gt;<br />
  &lt;/User&gt;<br />
&lt;/Users&gt;<br />
Reading data from an XML-file is really easy in PowerShell! Use this command to load the file into an variable:<br />
PS C:\Tmp&gt; <em>[xml]$userfile = Get-Content Accounts.xml </em></p>
<p>When the xml-file is loaded you can type <em>&#8220;$userfile.U</em>&#8221; and press tab to get auto completion!! It&#8217;s a breeze.</p></blockquote>
<p>The trick is that you have to actually READ what is in front of you.  The key here is to let PowerShell know that you are reading an xml file, and that is done by placing<strong> [xml]</strong> prior to getting the content.  I missed that the first six times I read this and couldn’t figure out why I wasn’t getting the results I expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://nukeitmike.com/blog/2009/09/22/using-xml-in-your-powershell-scripting//feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitoring drive space</title>
		<link>http://nukeitmike.com/blog/2009/09/04/monitoring-drive-space/</link>
		<comments>http://nukeitmike.com/blog/2009/09/04/monitoring-drive-space/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 21:25:29 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[General Info]]></category>
		<category><![CDATA[Operational Excellence]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[storage]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://nukeitmike.com/blog/2009/09/04/monitoring-drive-space/</guid>
		<description><![CDATA[One of the things that we spend a lot of time on is trying to keep track of what servers have enough free space.&#160; We have a lot of different tools to check drive space, and we even use some of them from time to time.&#160; We have a pretty complicated system created by Rickey [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that we spend a lot of time on is trying to keep track of what servers have enough free space.&#160; We have a lot of different tools to check drive space, and we even use some of them from time to time.&#160; We have a pretty complicated system created by <a href="http://www.whitworth.org/" target="_blank">Rickey</a> that creates a nice webpage, with highlighting for problem areas (percentage change from day to day, current percent free, etc.)&#160; It even puts the info into a database for historical reporting.</p>
<p>We don’t store or report on VMs currently, mainly because we were trying to keep track of total REAL disk used.&#160; VMs often don’t use as much as they think they do, so that would skew the results, as well as the fact that we are reporting on the hosts.&#160; </p>
<p>All of that is the reason that <a href="http://pburch.com/blog" target="_blank">Patrick</a> asked me to come up with some other tool to use for the VMs so I happened to find a few pieces of PowerShell script that I managed to put together to do a pretty good job of providing some of the info we wanted, and I thought I would share that with the 2 people who read my blog.&#160; <img src='http://nukeitmike.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&#160;</p>
<blockquote><p>$servers = Get-Content servers.txt </p>
<p>#Open Excel and create a new workbook and worksheet     <br />$ExcelSheet=New-Object -comobject Excel.application&#160;&#160;&#160; <br />$WorkBook=$ExcelSheet.WorkBooks.add(1)&#160;&#160;&#160;&#160; <br />$WorkSheet=$WorkBook.WorkSheets.item(1)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p>
<p>#Header row     <br />$WorkSheet.cells.item(1,1)=”Computer Name”&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />$WorkSheet.cells.item(1,2)=”Disk Device ID”&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />$WorkSheet.cells.item(1,3)=”Volume Name”&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />$WorkSheet.cells.item(1,4)=”Size (GB)”&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />$WorkSheet.cells.item(1,5)=”Free Space (GB)”      <br />$WorkSheet.cells.item(1,6)=”Space Used (GB)”      <br />$WorkSheet.cells.item(1,7)=”Percent Used” </p>
<p>$i=2 </p>
<p>ForEach ($ComputerName in $servers)     <br />{&#160;&#160;&#160; <br />&#160;&#160;&#160; echo &quot;Server Name : &quot;, $ComputerName      <br />&#160;&#160;&#160; $Disks = gwmi –computername $ComputerName win32_logicaldisk -filter &quot;drivetype=3&quot; </p>
<p>&#160;&#160;&#160; foreach ($Disk in $Disks)      <br />&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $Size = &quot;{0:0.0}&quot; -f ($Disk.Size/1GB)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $FreeSpace = &quot;{0:0.0}&quot; -f ($Disk.FreeSpace/1GB)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $Used = ([int64]$Disk.size &#8211; [int64]$Disk.freespace)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $SpaceUsed = &quot;{0:0.0}&quot; -f ($Used/1GB)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $Percent = ($Used * 100.0)/$Disk.Size      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $Percent = &quot;{0:N0}&quot; -f $Percent      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $WorkSheet.cells.item($i,1)=$ComputerName      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $WorkSheet.cells.item($i,2)=$Disk.deviceid      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $WorkSheet.cells.item($i,3)=$Disk.volumename      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $WorkSheet.cells.item($i,4)=$Size      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $WorkSheet.cells.item($i,5)=$FreeSpace      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $WorkSheet.cells.item($i,6)=$SpaceUsed      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $WorkSheet.cells.item($i,7)=$Percent </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $i=$i+1&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; }      <br />}      <br />#Show the results      <br />$ExcelSheet.visible=$true</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://nukeitmike.com/blog/2009/09/04/monitoring-drive-space//feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
