<?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>Sentiment &#187; PowerShell</title>
	<atom:link href="http://wouter.shush.com/tag/powershell/feed" rel="self" type="application/rss+xml" />
	<link>http://wouter.shush.com</link>
	<description>About Life, the Universe, and Everything...</description>
	<lastBuildDate>Tue, 07 Feb 2012 19:27:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Gather IIS logs from your IIS servers</title>
		<link>http://wouter.shush.com/2011/11/gather-iis-logs-from-your-iis-servers?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gather-iis-logs-from-your-iis-servers</link>
		<comments>http://wouter.shush.com/2011/11/gather-iis-logs-from-your-iis-servers#comments</comments>
		<pubDate>Wed, 16 Nov 2011 12:54:48 +0000</pubDate>
		<dc:creator>wooter</dc:creator>
				<category><![CDATA[Internet Information Server]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[iis]]></category>
		<category><![CDATA[Logfiles]]></category>

		<guid isPermaLink="false">http://wouter.shush.com/?p=389</guid>
		<description><![CDATA[I needed a quick way to gather all IIS logfile locations in several SharePoint farms. IIS has a nasty way to reference to numbers instead of names in their logging directory structure, so you need to watch the Advanced Settings &#8230; <a href="http://wouter.shush.com/2011/11/gather-iis-logs-from-your-iis-servers">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--:en-->I needed a quick way to gather all IIS logfile locations in several SharePoint farms. IIS has a nasty way to reference to numbers instead of names in their logging directory structure, so you need to watch the Advanced Settings panel in IIS to figure out which logging directory is for which website.</p>
<p>This could be done easier, I thought. And so thought many before me.</p>
<p><!--:--><span id="more-389"></span><!--:en-->This is a slight modification of <a href="http://www.indented.co.uk/index.php/2010/01/12/powershell-iis-and-log-settings/" target="_blank">the script by Chris Dent</a>, because I needed different results to link site name (which <em>IISWebServerSetting</em> saves as <em>ServerComment</em>) to the specific logfile directory (which is a mishmash of <em>LogFileDirectory</em> and <em>Name</em>).</p>
<pre>Function Get-IISLogSetting {
    param(
       [String[]]$Servers = $Env:Computername
    );

    $Servers | %{
        $Server = $_ ;
        Write-Progress "Scaning" $Server;
        $WMI = New-Object Management.ManagementScope("\\$Server\root\MicrosoftIISv2");
        $WMI.Options.Authentication = "PacketPrivacy";
        $Query = New-Object Management.ObjectQuery("SELECT Name, ServerComment, LogFileDirectory, LogFileTruncateSize, LogType, LogFilePeriod FROM IIsWebServerSetting");
        $Searcher = New-Object Management.ManagementObjectSearcher($WMI, $Query);
        Trap [UnauthorizedAccessException] {
              Write-Error "$($Server): Unable to connect or Access is denied";
              continue;
        }
        $result = $Searcher.Get();
        #$Host.EnterNestedPrompt();
        $result | Select-Object @{
            n = 'Server';
            e = { $Server; }
        }, @{
            n = 'Website';
            e = { $_.ServerComment; }
        }, @{
            n = 'Log Path';
            e = { "{0}\{1}" -f $_.LogFileDirectory, $_.Name.Replace("/",""); }
        }
    }
}</pre>
<p>Usage:</p>
<pre>Get-IISLogSetting [-servers server1,server2,server3,...]</pre>
<p><!--:--></p>
]]></content:encoded>
			<wfw:commentRss>http://wouter.shush.com/2011/11/gather-iis-logs-from-your-iis-servers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding members to groups with +1500 members in PowerShell</title>
		<link>http://wouter.shush.com/2007/10/adding-members-to-groups-with-1500-members-in-powershell?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-members-to-groups-with-1500-members-in-powershell</link>
		<comments>http://wouter.shush.com/2007/10/adding-members-to-groups-with-1500-members-in-powershell#comments</comments>
		<pubDate>Fri, 19 Oct 2007 07:27:37 +0000</pubDate>
		<dc:creator>wooter</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[ADSI]]></category>
		<category><![CDATA[Windows 2003]]></category>

		<guid isPermaLink="false">http://wouter.shush.com/it-stuff/adding-members-to-groups-with-1500-members-in-powershell</guid>
		<description><![CDATA[The Windows Active Directory does not really have hard limits when it comes to group memberships. There are however soft limits. Any ADSI or WMI query to a list of your group memberships will turn out to 1000 members in &#8230; <a href="http://wouter.shush.com/2007/10/adding-members-to-groups-with-1500-members-in-powershell">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--:en-->The Windows Active Directory does not really have <a title="Active Directory limits" href="http://blogs.technet.com/mcs-ireland-infrastructure/archive/2006/10/14/active-directory-limits.aspx" target="_blank">hard limits</a> when it comes to group memberships. There are however soft limits.</p>
<p>Any ADSI or WMI query to a list of your group memberships will turn out to 1000 members in Windows 2000 mode, or 1500 in Windows 2003 native mode. Only by using <a title="List large groups" href="http://www.rlmueller.net/DocumentLargeGroup.htm" target="_blank">ADO range limits</a>, you can go by this soft limit.</p>
<p>This shouldn&#8217;t pose a problem when you are just adding members to an already big group. However, it does.<!--:--><span id="more-36"></span><!--:en--></p>
<pre lang="powershell" line="1">$userOU = [ADSI] "LDAP://cn=myUser,ou=Users,dc=contoso,dc=com"
$groupOU = [ADSI] "LDAP://cn=myGroup,ou=Users,dc=contoso,dc=com"
<strong>$groupOU.Member = $groupOU.Member + $userOU.distinguishedName
</strong>$groupOU.SetInfo()
</pre>
<p>Adding the myUser user to the myGroup group will work fine if the group member count is below 1500. Once above, your group will suddenly loose an amount of members until you are left with a group of just 1500 members, and then added by the new member.</p>
<p>What actually happens is self-explanatory when reading the code: the group members is the group member list plus the new member. When the group member list only returns 1500 members, and then you add one member, you are left with 1501 members, and not your original amount of members + 1.</p>
<p>A workaround is this:</p>
<pre lang="powershell" line="1">$ADS_PROPERTY_APPEND = 3
$userOU = [ADSI] "LDAP://cn=myUser,ou=Users,dc=contoso,dc=com"
$groupOU = [ADSI] "LDAP://cn=myGroup,ou=Users,dc=contoso,dc=com"
<strong>$groupOU.putEx($ADS_PROPERTY_APPEND, "member", @($userOU.distinguishedname))</strong>
$groupOU.SetInfo()</pre>
<p>In this workaround, we are going to use <a title="HOW TO: Use ADSI to Set LDAP Directory Attributes" href="http://support.microsoft.com/kb/260251" target="_blank">putEx</a> to append a member to a group, instead of loading the full member list (with a limit of 1500) and then adding a new member.</p>
<p><a title="ADSI and group membership - what am I doing wrong - Neil Chambers " href="http://www.eggheadcafe.com/software/aspnet/30327382/adsi-and-group-membership.aspx" target="_blank">Source</a>.<!--:--></p>
]]></content:encoded>
			<wfw:commentRss>http://wouter.shush.com/2007/10/adding-members-to-groups-with-1500-members-in-powershell/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excel automation with Powershell</title>
		<link>http://wouter.shush.com/2007/08/excel-automation-with-powershell?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=excel-automation-with-powershell</link>
		<comments>http://wouter.shush.com/2007/08/excel-automation-with-powershell#comments</comments>
		<pubDate>Thu, 02 Aug 2007 16:05:19 +0000</pubDate>
		<dc:creator>wooter</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[regional settings]]></category>
		<category><![CDATA[scripting guy]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://wouter.shush.com/wordpress/2007/09/16/excel-automation-with-powershell/</guid>
		<description><![CDATA[Powershell is Microsoft&#8217;s answer of decent shell scripting on the Windows platform. Equipped with the functions you would expect from VBScript, it behaves as an Unix shell script would. All commands can work from the command line, or as a &#8230; <a href="http://wouter.shush.com/2007/08/excel-automation-with-powershell">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--:en--><a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx">Powershell</a> is Microsoft&#8217;s answer of decent shell scripting on the Windows platform.  Equipped with the functions you would expect from VBScript, it behaves as an Unix shell script would.  All commands can work from the command line, or as a set of instructions in a file.</p>
<p>Adding to the basic shell functions one would expect, such as file and directory manipulation, reading and writing text files, manipulating strings with regular expressions, Powershell also integrates with .NET 2.0 and higher to communicate with other functions, such as accessing the System.Windows.Forms object to make neat forms equipped with all the controls you would expect in a compiled application, or in this case: manipulating Excel workbooks.</p>
<p>Using Excel together with PowerShell can be very easy.  Too bad the documentation is sparse on this topic, and the official documentation makes no mention of a workaround that is needed when using Excel with PowerShell on a machine which is not configured with regional settings set to EN-us.<!--:--><span id="more-6"></span><!--:en--></p>
<p>We start off creating an Excel object, as described in the Scripting Guy post:</p>
<pre lang="powershell" line="1">$objExcel = New-Object -comobject Excel.Application
$objExcel.Visible = $True
$objWorkbook = $objExcel.Workbooks.Add()
$objWorksheet = $objWorkbook.Worksheets.Item(1)
$objWorksheet.Cells.Item(1,1) = "A value in cell A1."
$objWorkbook.SaveAs("C:ScriptsTest.xls")
$objExcel.Quit()</pre>
<p>This little bit wil start Excel, add a worksheet, inset a string in cell A1, and save the Excel worksheet to a file, before quitting.  Unless your machine is not set up with regional settings EN-us.  Then you are greeted with the next message:</p>
<p><code>Exception calling "Add" with "0" argument(s): "Old format or invalid type library. (Exception from HRESULT: 0x80028018<br />
(TYPE_E_INVDATAREAD))"<br />
At line:1 char:39<br />
+ $objWorkbook = $objExcel.Workbooks.Add( &lt; &lt;&lt;&lt; ) </code></p>
<p>When looking for this Error, you will run into threads regarding other scripting and programming languages.  Most notably, KB320369 has some information.</p>
<p>Ok, there is a workaround. See what this code does:</p>
<pre lang="powershell" line="1">function Invoke([object]$m, [string]$method, $parameters)
{
$m.PSBase.GetType().InvokeMember(
$method, [Reflection.BindingFlags]::InvokeMethod, $null, $m, $parameters,$ciUS)
} 

$ciUS = [System.Globalization.CultureInfo]'en-US'

$objExcel = New-object -com Excel.Application
$objExcel.visible = $True
$ci = [System.Globalization.CultureInfo]'en-us'
$objWorkbook = Invoke $objExcel.Workbooks Add
$objWorksheet = $objWorkbook.Worksheets.Item(1)
$objWorksheet.Cells.Item(1,1) = "A value in cell A1."
Invoke $objWorkbook SaveAs "C:ScriptsTest.xls" > $null
Invoke $objWorkbook Close 0 > $null
$objExcel.Quit()</pre>
<p>Still an error!</p>
<p><code>Exception setting "Item": "Exception from HRESULT: 0x800A03EC"<br />
At C:scriptingtest.ps1:15 char:25<br />
+ $objWorksheet.Cells.Item( &lt; &lt;&lt;&lt; 1,1) = "A value in cell A1." </code></p>
<p>Modify the above code a bit, with this line instead of line 14:</p>
<pre lang="powershell" line="14">$objWorksheet.Cells.Item(1,1).FormulaLocal = "A value in cell A1." </pre>
<p>The result?  An Excel-file with data!</p>
<p>If you want to open an Excel-file instead of creating a new one, use the following as a replacement for line 12:</p>
<pre lang="powershell" line="12">$objWorkbook = Invoke $objExcel.Workbooks Open"c:ScriptsTest.xls" </pre>
<p>And if you want to save the Excel file to the existing name, add this before line 16:</p>
<pre lang="powershell" line="16">Invoke $objWorkbook Save > $null </pre>
<p><!--:--></p>
]]></content:encoded>
			<wfw:commentRss>http://wouter.shush.com/2007/08/excel-automation-with-powershell/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: wouter.shush.com @ 2012-02-08 01:24:42 -->
