<?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>..::\\ www.christiano.ch //::.. &#187; PowerShell</title>
	<atom:link href="http://www.christiano.ch/wordpress/category/microsoft/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christiano.ch/wordpress</link>
	<description>christiano.ch blog - personal knowledge base, news, memoires et cetera</description>
	<lastBuildDate>Thu, 02 Sep 2010 04:54:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<meta xmlns="http://www.w3.org/1999/xhtml" name="robots" content="noindex,follow" />
		<item>
		<title>PowerShell: About SessionConfiguration and how to change them</title>
		<link>http://www.christiano.ch/wordpress/2010/04/24/powershell-about-sessionconfiguration-and-how-to-change-them/</link>
		<comments>http://www.christiano.ch/wordpress/2010/04/24/powershell-about-sessionconfiguration-and-how-to-change-them/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 21:18:31 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/?p=929</guid>
		<description><![CDATA[Remote Access Without Admin Privileges In PowerShell v.2, remote access is available only to users who hold local administrator privileges. So, even if you do have appropriate remote access to a machine, , you cannot remotely access the system if you are not an Admin. This is not a technical limitation, though, just a safe [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Remote Access Without Admin Privileges</strong></p>
<p>In PowerShell v.2, remote access is available only to users who hold local administrator privileges. So, even if you do have appropriate remote access to a machine, , you cannot remotely access the system if you are not an Admin. This is not a technical limitation, though, just a safe default. You should use this line to change it :</p>
<p><strong>Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/04/24/powershell-about-sessionconfiguration-and-how-to-change-them/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell: Generate PC Lists using Foreach-Object and -f Operator</title>
		<link>http://www.christiano.ch/wordpress/2010/04/24/powershell-generate-pc-lists-using-foreach-object-and-f-operator/</link>
		<comments>http://www.christiano.ch/wordpress/2010/04/24/powershell-generate-pc-lists-using-foreach-object-and-f-operator/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 21:10:36 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/?p=921</guid>
		<description><![CDATA[Generate PC Lists One easy way of creating lists of PC names or IP address ranges etc is a simple pipeline like this: 1..40 &#124; Foreach-Object { &#8216;PC-W7-A{0:000}&#8217; -f $_ } Use the -f operator to format the number. In this example, it will always be three-digit.]]></description>
			<content:encoded><![CDATA[<p>Generate PC Lists</p>
<p>One easy way of creating lists of PC names or IP address ranges etc is a simple pipeline like this:</p>
<p><strong>1..40 | Foreach-Object { &#8216;PC-W7-A{0:000}&#8217; -f $_ }</strong></p>
<p>Use the -f operator to format the number. In this example, it will always be three-digit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/04/24/powershell-generate-pc-lists-using-foreach-object-and-f-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell: Sort-Object</title>
		<link>http://www.christiano.ch/wordpress/2010/04/24/powershell-sort-object/</link>
		<comments>http://www.christiano.ch/wordpress/2010/04/24/powershell-sort-object/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 21:08:19 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/?p=919</guid>
		<description><![CDATA[You can use Sort-Object to sort simple variable types. Have a look at the following: &#8216;Tom&#8217;, &#8216;Chris&#8217;, &#8216;Judy&#8217;, &#8216;Alan&#8217; &#124; Sort-Object Input can come from a different command. If you’d like to get seven random lottery numbers, you should try this: 1..49 &#124; Get-Random -Count 7 &#124; Sort-Object You’ll find that when you feed complex [...]]]></description>
			<content:encoded><![CDATA[<p>You can use Sort-Object to sort simple variable types. Have a look at the following:</p>
<p><strong>&#8216;Tom&#8217;, &#8216;Chris&#8217;, &#8216;Judy&#8217;, &#8216;Alan&#8217; | Sort-Object<br />
</strong></p>
<p>Input can come from a different command. If you’d like to get seven random lottery numbers, you should try this:</p>
<p><strong>1..49 | Get-Random -Count 7 | Sort-Object</strong></p>
<p>You’ll find that when you feed complex objects into Sort-Object, you should specify the object property you want to sort on (or else Sort-Object will pick one by itself):</p>
<p><strong>Get-ChildItem $env:windir | Sort-Object Length</strong></p>
<p>Here are some more examples:</p>
<p><strong>Get-HotFix | Sort-Object InstalledOn</p>
<p>Get-ComputerRestorePoint | Sort-Object Description</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/04/24/powershell-sort-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Exchange 2007 / 2010 &#8211; Statistics using Exchange Management Shell (EMS)</title>
		<link>http://www.christiano.ch/wordpress/2010/03/14/microsoft-exchange-2007-2010-statistics-using-exchange-management-shell-ems/</link>
		<comments>http://www.christiano.ch/wordpress/2010/03/14/microsoft-exchange-2007-2010-statistics-using-exchange-management-shell-ems/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 09:14:10 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[Exchange Server]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Exchange]]></category>
		<category><![CDATA[Statistics]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2010/03/14/microsoft-exchange-2007-2010-statistics-using-exchange-management-shell-ems/</guid>
		<description><![CDATA[Using Microsoft Exchange 2007 / 2010 Management Shell (PowerShell with extensions), you can pull out some very exciting statistics. That was never that easy in the pre Exchange 2007 era. Let’s start with some easy stuff.. Get the number of Public Folders Get-PublicFolder -Recurse &#124; Measure-Object Get the sum / number of Mails / Object [...]]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="676">Using Microsoft Exchange 2007 / 2010 Management Shell (PowerShell with extensions), you can pull out some very exciting statistics. That was never that easy in the pre Exchange 2007 era.</td>
<td valign="top" width="10"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2010/03/Logo_ExchangeSvr.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Logo_ExchangeSvr" border="0" alt="Logo_ExchangeSvr" src="http://www.christiano.ch/wordpress/wp-content/uploads/2010/03/Logo_ExchangeSvr_thumb.png" width="160" height="90" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-898"></span>
<p>Let’s start with some easy stuff..</p>
<p><strong>Get the number of Public Folders</strong></p>
<p><code>Get-PublicFolder -Recurse | Measure-Object</code></p>
<p><strong>Get the sum / number of Mails / Object in all Public Folders</strong></p>
<p><code>Get-PublicFolderStatistics | Measure-Object -Property ItemCount -Sum</code></p>
<p><strong>Get the number of Mailboxes</strong></p>
<p><code>Get-Mailbox | Measure-Object</code></p>
<p><strong>Get the number of sent messages / emails within a date range</strong></p>
<p><code>Get-MessageTrackingLog -Start &quot;29.11.2009&quot; -End &quot;30.12.2009&quot; -ResultSize Unlimited | Measure-Object</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/03/14/microsoft-exchange-2007-2010-statistics-using-exchange-management-shell-ems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell: Creating large dummy files with .NET</title>
		<link>http://www.christiano.ch/wordpress/2010/03/13/powershell-creating-large-dummy-files-with-net/</link>
		<comments>http://www.christiano.ch/wordpress/2010/03/13/powershell-creating-large-dummy-files-with-net/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 13:23:02 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2010/03/13/powershell-creating-large-dummy-files-with-net/</guid>
		<description><![CDATA[Ok, this one’s is cool i think. Whenever i needed a large dummy file, i opened up notepad, write ASDFASDFASDFA CTRL-A, CTRL-C, CTRL-V,CTRL-V,CTRL-V,CTRL-V. CTRL-A, CTRL-C, CTRL-V,CTRL-V,CTRL-V,CTRL-V,CTRL-V.. Then i saved the file, opened up a CMD-Shell and wrote copy dummyFile.txt+dummyFile.txt+dummyFile.txt until the file was large enough.. ok, there’s fsutil.exe which does the same in a much [...]]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="666">Ok, this one’s is cool i think. Whenever i needed a large dummy file, i opened up notepad, write ASDFASDFASDFA CTRL-A, CTRL-C, CTRL-V,CTRL-V,CTRL-V,CTRL-V. CTRL-A, CTRL-C, CTRL-V,CTRL-V,CTRL-V,CTRL-V,CTRL-V.. Then i saved the file, opened up a CMD-Shell and wrote copy dummyFile.txt+dummyFile.txt+dummyFile.txt until the file was large enough.. ok, there’s fsutil.exe which does the same in a much more efficient manner.. OR, unleash the Power of .NET – no, you don’t have to start programming using Visual Studio, just open up PowerShell.. </td>
<td valign="top" width="10"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2010/03/Logo_PowerShell1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Logo_PowerShell" border="0" alt="Logo_PowerShell" src="http://www.christiano.ch/wordpress/wp-content/uploads/2010/03/Logo_PowerShell_thumb1.png" width="160" height="125" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-895"></span>
<p>Ok, the goal is to have a 1gb large dummy file .. </p>
<p>first we declare a string variable called file: </p>
<p><code>PS C:\&gt; $file = &quot;$env:temp\dummyFile.txt&quot;</code></p>
<p>no we create on object of type Io.File    <br /><code>PS C:\&gt; $objFile = [io.file]::Create($file)</code></p>
<p>on the object, we call the void SetLength parameterized with 1gb&#160; <br /><code>PS C:\&gt; $objFile.SetLength(1gb)</code></p>
<p>no we call the close method and the file is written    <br /><code>PS C:\&gt; $objFile.Close()</code></p>
<p>using get-item $file we list the file we just created:</p>
<p><code>PS C:\&gt; Get-Item $file </code><code>Directory: C:\Users\&lt;removed&gt;\AppData\Local\Temp </code></p>
<p><code>Mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LastWriteTime&#160;&#160;&#160;&#160; Length Name      <br />----&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; -------------&#160;&#160;&#160;&#160; ------ ----       <br />-a---&#160;&#160;&#160;&#160;&#160;&#160;&#160; 13.03.2010&#160;&#160;&#160;&#160; 14:07 1073741824 dummyFile.txt </code></p>
<p><code>PS C:\&gt;</code></p>
<p>Ok, finally we can call an ii (Invoke-Item) to open the Path where the dummyFile resides in Windows Explorer. </p>
<p>To get the Path from a File, we can use Get-ChildItem (Get-ChildItems returns a FileInfo Object/Class). This object has a DirectoryName Property. </p>
<p>We declare an Object $path</p>
<p><code>$path = Get-ChildItem $file</code></p>
<p>Finally we call the mentioned ii (Invoke-Item) to open the path in Windows Explorer.</p>
<p><code>ii $path.DirectoryName</code></p>
<p><strong><em>The complete Script </em></strong></p>
<p><code>$file = &quot;$env:temp\dummyFile.txt&quot;      <br />$objFile = [io.file]::Create($file)       <br />$objFile.SetLength(1gb)       <br />$objFile.Close()       <br />$path = Get-ChildItem $file       <br />ii $path.DirectoryName</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/03/13/powershell-creating-large-dummy-files-with-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell: Running PowerShell Scripts as Scheduled Task</title>
		<link>http://www.christiano.ch/wordpress/2010/03/10/powershell-running-powershell-scripts-as-scheduled-task/</link>
		<comments>http://www.christiano.ch/wordpress/2010/03/10/powershell-running-powershell-scripts-as-scheduled-task/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 06:04:39 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scheduled Task]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2010/03/10/powershell-running-powershell-scripts-as-scheduled-task/</guid>
		<description><![CDATA[Schtasks.exe &#8211; Enables an administrator to create, delete, query, change, run, and end scheduled tasks on a local or remote computer. Running Schtasks.exe without arguments displays the status and next run time for each registered task. If you have jobs that need to execute regularly, you can manage them with a PowerShell script and make [...]]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="671">Schtasks.exe &#8211; Enables an administrator to create, delete, query, change, run, and end scheduled tasks on a local or remote computer. Running Schtasks.exe without arguments displays the status and next run time for each registered task.          <br /> 
<p>If you have jobs that need to execute regularly, you can manage them with a PowerShell script and make it a scheduled task:</p>
</td>
<td valign="top" width="10"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2010/03/Logo_PowerShell.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Logo_PowerShell" border="0" alt="Logo_PowerShell" src="http://www.christiano.ch/wordpress/wp-content/uploads/2010/03/Logo_PowerShell_thumb.png" width="160" height="125" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-888"></span>
<p>To create a scheduled task do.</p>
<p><code>schtasks /CREATE /TN CheckHealthScript /TR &quot;powershell.exe -noprofile -executionpolicy Unrestricted -file %public%\checkhealth.ps1&quot; /IT /RL HIGHEST /SC DAILY</code></p>
<p>To get a list of scheduled tasks / enumerate scheduled tasks do:</p>
<p><code>schtasks /query</code></p>
<p><strong>Links</strong></p>
<p><a title="Running PowerShell Scripts as Scheduled Task" href="http://powershell.com/cs/blogs/tips/archive/2010/03/09/running-powershell-scripts-as-scheduled-task.aspx" target="_blank">Running PowerShell Scripts as Scheduled Task</a></p>
<p><a title="About Scheduled Tasks on MSDN" href="http://msdn.microsoft.com/en-us/library/bb736357%28VS.85%29.aspx" target="_blank">About Scheduled Tasks on MSDN</a></p>
<p><a title="About Scheduled Tasks on Technet" href="http://technet.microsoft.com/en-us/library/bb490996.aspx" target="_blank">About Scheduled Tasks on Technet</a></p>
<p>&#160;</p>
<p><strong><em>Script to enumerate / list scheduled tasks on a list of servers..</em></strong></p>
<p> <code>$Version=&quot;v8.4.28 Aaron Dodd&quot;   <br />$Description=&quot;Generate CSV of scheduled tasks in the environment&quot;    </p>
<p>#------------------------------------------------------------------------------    <br /># Settings / Variables    <br />#------------------------------------------------------------------------------    <br />If (Test-Path &quot;QueryScheduledTasks.config&quot;) {    <br />$cfg=[xml](get-content &quot;QueryScheduledTasks.config&quot;)    <br />} Else {    <br />Write-Host &quot;!! ERROR !! - Config file not found&quot;    <br />Write-Host &quot;A file with the same name as this script, ending in .config, must exist in the same directory as this script.&quot;    <br />exit    <br />}    </p>
<p>$ServerList = Import-Csv $cfg.configuration.ServerList.name    <br />$FinalReport=$cfg.configuration.FinalReport.name    <br />$TempDir=$cfg.configuration.TempFolder.name    <br />$TempReport=$TempDir + &quot;\temp.csv&quot;    <br />$ErrorActionPreference=$cfg.configuration.ErrorAction.value    <br />#------------------------------------------------------------------------------    </p>
<p>#------------------------------------------------------------------------------    <br /># Process tasks    <br />#------------------------------------------------------------------------------    <br />ForEach ($Server in $ServerList) {    <br />schtasks /QUERY /S $Server.Name /FO CSV /V &gt; $TempReport    <br />$TempCsv += Import-Csv $TempReport    <br />}    <br />Remove-Item $TempReport    <br />$TempCsv | Export-Csv $FinalReport -notype    <br />#----------------------------------------------------------------</code>
<p>found here =&gt; <a title="http://blog.geekpoet.net/2008/04/powershell-script-to-report-on-all.html" href="http://blog.geekpoet.net/2008/04/powershell-script-to-report-on-all.html" target="_blank">http://blog.geekpoet.net/2008/04/powershell-script-to-report-on-all.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/03/10/powershell-running-powershell-scripts-as-scheduled-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell: Delete specific files recursively / recursive</title>
		<link>http://www.christiano.ch/wordpress/2010/02/19/powershell-delete-specific-files-recursively-recursive/</link>
		<comments>http://www.christiano.ch/wordpress/2010/02/19/powershell-delete-specific-files-recursively-recursive/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 12:26:14 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Get-ChildItem]]></category>
		<category><![CDATA[Remove-Item]]></category>
		<category><![CDATA[Where-Object]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2010/02/19/powershell-delete-specific-files-recursively-recursive/</guid>
		<description><![CDATA[Okay, this post I&#8217;m going to write down for my personal notes but also for you.. Ever needed to delete a specific file, in my case in need to delete (remove-item) all *.pdb files in one of my Visual Studio Solution.. recursive of course. To get a list of Files use the Get-ChildItem CmdLet. Extend [...]]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="644">Okay, this post I&#8217;m going to write down for my personal notes but also for you..          <br />Ever needed to delete a specific file, in my case in need to delete (remove-item) all *.pdb files in one of my Visual Studio Solution.. recursive of course.           <br />To get a list of Files use the <strong><em>Get-ChildItem</em></strong> CmdLet. Extend that command using the <strong><em>–rec</em></strong> or <strong><em>–recurse</em></strong> parameter – so you’ll get all the files recursively, starting from the current path / directory.</td>
<td valign="top" width="30"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2010/02/Logo_PowerShell.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Logo_PowerShell" border="0" alt="Logo_PowerShell" src="http://www.christiano.ch/wordpress/wp-content/uploads/2010/02/Logo_PowerShell_thumb.png" width="160" height="125" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-860"></span>
<p>Now, we don’t need all the file, but all the files with a specific extension. We’ll use the <strong><em>Where-Object </em></strong>to achieve this. Well if you do <strong><em>Get-ChildItem</em></strong> you’ll get something like:</p>
<p><em><strong>PS D:\DEMO&gt; Get-ChildItem </strong></em></p>
<p><em>&#160;&#160;&#160; Directory: D:\DEMO </em></p>
<p><em>Mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LastWriteTime&#160;&#160;&#160;&#160; Length Name     <br />&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;-&#160;&#160;&#160;&#160; &#8212;&#8212; &#8212;-      <br />d&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160; 19.02.2010&#160;&#160;&#160;&#160; 13:16&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DEMO Folder      <br />-a&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 19.02.2010&#160;&#160;&#160;&#160; 13:17&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 18 someFile.ext </em></p>
<p><em>PS D:\DEMO&gt;</em></p>
<p>&#160;</p>
<p>So, how to get only files with a specific extension? Easy, using <strong><em>Get-Member </em></strong>we can list all properties of <strong><em>Get-ChildItem</em></strong>.</p>
<p><em><strong>PS D:\DEMO&gt; Get-ChildItem | Get-Member </strong></em></p>
<p><em>&#160;&#160; TypeName: System.IO.DirectoryInfo </em></p>
<p><em>Name&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MemberType&#160;&#160;&#160;&#160; Definition     <br />&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;-&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;-      <br />Mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CodeProperty&#160;&#160; System.String Mode{get=Mode;}      <br />Create&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Method&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.Void Create(System.Security.AccessControl.DirectorySecurity director&#8230;      <br />&#8230;      <br />&#8230;      <br /><strong>Extension&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Property&#160;&#160;&#160;&#160;&#160;&#160; System.String Extension {get;}</strong></em>    <br /><em>FullName&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Property&#160;&#160;&#160;&#160;&#160;&#160; System.String FullName {get;}     <br />&#8230;      <br />&#8230; </em></p>
<p><em>PS D:\DEMO&gt;</em></p>
<p>&#160;</p>
<p>When we want to search for a specific File Type, the Extension Property comes in very handy. </p>
<p>So, to get a list of all, let’s say *.tmp files recursively, we’ll write:</p>
<p><em><strong>PS D:\DEMO&gt; Get-ChildItem -Rec | Where {$_.Extension -match &quot;tmp&quot;} </strong></em></p>
<p><em>&#160;&#160;&#160; Directory: D:\DEMO </em></p>
<p><em>Mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LastWriteTime&#160;&#160;&#160;&#160; Length Name     <br />&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;-&#160;&#160;&#160;&#160; &#8212;&#8212; &#8212;-      <br />-a&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 19.02.2010&#160;&#160;&#160;&#160; 13:22&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 12 demo.tmp </em></p>
<p><em>&#160;&#160;&#160; Directory: D:\DEMO\DEMO Folder </em></p>
<p><em>Mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LastWriteTime&#160;&#160;&#160;&#160; Length Name     <br />&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;-&#160;&#160;&#160;&#160; &#8212;&#8212; &#8212;-      <br />-a&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 19.02.2010&#160;&#160;&#160;&#160; 13:22&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 12 dem32.tmp      <br />-a&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 19.02.2010&#160;&#160;&#160;&#160; 13:22&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 12 demo2.tmp </em></p>
<p><em>PS D:\DEMO&gt;</em></p>
<p>&#160;</p>
<p>Now, let’s delete all of these *.tmp files using Remove-Item</p>
<p><em><strong>PS D:\DEMO&gt; Get-ChildItem -Rec | Where {$_.Extension -match &quot;tmp&quot;} | Remove-Item</strong></em></p>
<p>and they are all gone!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/02/19/powershell-delete-specific-files-recursively-recursive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell: Remote Access Without Admin Privileges</title>
		<link>http://www.christiano.ch/wordpress/2010/01/29/remote-access-without-admin-privileges/</link>
		<comments>http://www.christiano.ch/wordpress/2010/01/29/remote-access-without-admin-privileges/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 06:37:51 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2010/01/29/remote-access-without-admin-privileges/</guid>
		<description><![CDATA[In PowerShell v.2, remote access is available only to users who hold local administrator privileges. So, even if you do have appropriate remote access to a machine, , you cannot remotely access the system if you are not an Admin. This is not a technical limitation, though, just a safe default. You should use this [...]]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="614">In PowerShell v.2, remote access is available only to users who hold local administrator privileges. So, even if you do have appropriate remote access to a machine, , you cannot remotely access the system if you are not an Admin. This is not a technical limitation, though, just a safe default.          </td>
<td valign="top" width="60"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2010/01/Logo_PowerShell.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Logo_PowerShell" border="0" alt="Logo_PowerShell" src="http://www.christiano.ch/wordpress/wp-content/uploads/2010/01/Logo_PowerShell_thumb.png" width="180" height="141" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-853"></span>
<p>You should use this line to change it :</p>
<p><strong><em>Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI</em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/01/29/remote-access-without-admin-privileges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell: Enabling PowerShell v2 Remotely</title>
		<link>http://www.christiano.ch/wordpress/2009/11/20/powershell-enabling-powershell-v2-remotely/</link>
		<comments>http://www.christiano.ch/wordpress/2009/11/20/powershell-enabling-powershell-v2-remotely/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 06:25:12 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2009/11/20/powershell-enabling-powershell-v2-remotely/</guid>
		<description><![CDATA[Looking for how to configure the local computer for remote management using Microsoft PowerShell? Set-WSManQuickConfig &#8211; This command sets the required configuration to enable remote management of the local computer. By default, this command creates a WS-Management listener on HTTP. Setting up the brand new PowerShell v.2 remotely in a domain environment is easy: simply [...]]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="626">Looking for how to configure the local computer for remote management using Microsoft PowerShell?         <br /><strong><em>Set-WSManQuickConfig</em></strong> &#8211;
<p>This command sets the required configuration to enable remote management of the local computer. By default, this command creates a WS-Management listener on HTTP.</p>
</td>
<td valign="top" width="48"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2009/11/Logo_PowerShell.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Logo_PowerShell" border="0" alt="Logo_PowerShell" src="http://www.christiano.ch/wordpress/wp-content/uploads/2009/11/Logo_PowerShell_thumb.png" width="150" height="118" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-780"></span>
<p>Setting up the brand new PowerShell v.2 remotely in a domain environment is easy: simply run   <br /><strong><em>       <br />Set-WSManQuickConfig</em></strong>    </p>
<p>As long as you have proper privileges to run this command, it does everything automatically: it runs the WinRM service, sets up a PowerShell listener and a firewall exception. To play with remotely, run this on every computer you want to connect to as it is required on both ends. Then, run any command remotely like this:    </p>
<p><strong><em>Invoke-Command { Stop-Process Spooler -force -whatif } -computername test123</em></strong>    </p>
<p>You should note&#160; that remote by default requires Kerberos authentication, so it will only work in a domain environment. You learn how to configure WSMan appropriately to make it work in simple peer-to-peer environments, in another tip.</p>
<p>&#160;</p>
<p>Here’s another Blog Post from <a title="Tobias @powershell.com" href="http://powershell.com/cs/members/Tobias/default.aspx" target="_blank">Tobias @powershell.com</a></p>
<p>&#160;</p>
<h3>Test-Driving Remoting In Windows 7</h3>
<p>&#160;</p>
<p>Remoting is among one of the most popular and powerful new PowerShell V2 features. What this means is that starting with PowerShell V2 (and starting with Windows 7 only because downlevel OS will support V2 remoting only in a future update), you can connect to other PowerShell V2 machines and run commands, scripts and jobs remotely. Very cool. </p>
<p>Unless you work in a configured AD-Environment, setting up and test-driving remoting isn&#8217;t that easy, though. By default, in a peer-to-peer environment,&#160; remoting is dead. I&#8217;d like to show you today in three easy steps how to set up a test peer-to-peer environment that you can use to play, show off and demo V2 remoting. </p>
<p>&#160;&#160;&#160; * This will show you how to set up the &quot;new&quot; V2 remoting using WinRM which requires PowerShell V2 on both ends.   <br />&#160;&#160;&#160; * Yes, there are other remoting techniques such as the old DCOM which will continue to work and neither require WinRM nor PS V2 (for example, use Get-WMIObject -computerName 10.10.10.10 to connect to that machine using classic DCOM) </p>
<p>&#160;</p>
<h3>What you need to make it happen&#8230; </h3>
<p>&#160;</p>
<p>To play with V2 remoting in a peer-to-peer scenario, this is what you need: </p>
<p>Ingredients: </p>
<p>&#160;&#160;&#160; * 2x Windows 7 (one of which can be running inside Windows Virtual PC if you like)   <br />&#160;&#160;&#160; * both machines may not be joined to a domain(!) </p>
<p>&#160;</p>
<h3>Things are turned off out-of-the-box&#8230; </h3>
<p>&#160;</p>
<p>First of all, figure out the IP addresses assigned to both machines and make sure they can reach each other via network. In this example, I will be using machine A with 192.168.2.105 and machine B with 192.168.2.107, so make sure you replace the IP addresses with yours. </p>
<p>If you&#8217;d like to establish a remote connection from machine A to machine B, you would use Enter-PSSession, but if you try like this: </p>
<p><em><strong>Enter-PSSession 192.168.2.107 </strong></em></p>
<p>the cmdlet will bark at you and come up with all kinds of reasons in red letters stating why what you are trying to do is absolutely ridiculous. </p>
<p>The simple fact is: the mechanism behind remoting which is called WinRM has not yet been set up to accept a remoting connection nor is it likely that the WinRM service is running at all yet. WinRM is secure by default, so you need to start it and open doors manually. What it also means is that you and only you will be liable if things go wrong and you trash your corporate infrastructure. So to prevent this from becoming a career-limiting move, you should set up a separate test environment to play with.</p>
<p>&#160;</p>
<h3>Step 1: Enable WinRM on both machines </h3>
<p>The first thing you want to do is call Set-WSManQuickConfig. This is actually your door-opener, and to successfully launch this command, you will need to (a) have admin privs and (b) be sure you do want to open the doors. Specifically, the command does the following: </p>
<p>&#160;&#160;&#160; * It makes sure the WinRM service is running and sets the startmode to Automatic so WinRM will be started automatically in the future. This enabled the computer to be connected via WinRM   <br />&#160;&#160;&#160; * It sets up a WinRM &quot;listener&quot; which is listening to incoming WinRM requests via http: from any IP address    <br />&#160;&#160;&#160; * It sets up a firewall exception so incoming WinRM requests aren&#8217;t rejected by your firewall any longer and make it to the WinRM service </p>
<p>As you can see, these really are door-openers, and unless you are working with a test system&#160; in your closet, you may want to find out more about the possible security implications. Note also that Set-WSManQuickConfig might return an Access Denied if you try and run it on a machine that is domain-joined. Everything you read here applies to a simple peer-to-peer scenario only. Domain-joined machines are a different ballgame because they use Kerberos to securely authenticate requests and chances are in a domain-based environment you do not need all of this anyway because your IT department has decided for you. </p>
<p>Once you ran Set-WSManQuickConfig on both machines, your Enter-PSSession command still fails because again, for security reasons, WinRM rejects requests unless they are guarded by Kerberos or an equally safe mechanism. However, if you did everything right, both machines can now at least use WinRM to talk to each other: </p>
<p><em><strong>Test-WSMan 192.168.2.107 </strong></em></p>
<p>This should return some protocol information.</p>
<p>&#160;</p>
<h3>Step 2: Add Computers to TrustedHosts list </h3>
<p>&#160;</p>
<p>Next, since you are working in a basic peer-to-peer environment, you need to convince WinRM that it is actually safe to accept requests from the other machine. You do this by adding the machine IPs to the list of so called &quot;trusted hosts&quot; &#8211; or, if you want to open the door even more, simply add a &quot;*&quot; to that list and allow any IP to talk to the machine. So on both machines, execute this: </p>
<p><em><strong>Set-Item WSMan:\localhost\client\trustedhosts * –force</strong></em>    </p>
<h3>Step 3: Enjoy! </h3>
<p>&#160;</p>
<p>Once you did this last step, you are up and running. When you now enter </p>
<p><strong><em>Enter-PSSession 192.168.2.107</em></strong> </p>
<p>after a couple of seconds of finger crossing (while WinRM sets up the remote PS session), you see the PS prompt of the remote system and now can work remotely on&#160; that machine. Everything is working fine now, and you can also explore all the other fine remoting features. Dunno which remoting features there are? Hang in, we&#8217;ll be back shortly with more examples! </p>
<p>Oh, by the way, this will only work if you have created the same user account with the same password on both machines (remember, we are in a peer-to-peer environment here). Of course, the user on machine A initiating the connection needs to have admin privs on the target machine. To authenticate as someone else, use -credential (Get-Credential) as parameter. </p>
<p>ff you are wondering how to leave the remoting session you just opened, simply type: </p>
<p><strong><em>exit-pssession </em></strong></p>
<p>&#160;</p>
<h1>Links</h1>
<p>&#160;</p>
<p><a title="http://technet.microsoft.com/en-us/library/dd819520.aspx" href="http://technet.microsoft.com/en-us/library/dd819520.aspx" target="_blank">Set-WSManQuickConfig on Microsoft Technet</a></p>
<p><a title="Test Driving Remoting in Windows 7" href="http://powershell.com/cs/blogs/tobias/archive/2009/08/29/test-driving-remoting-in-windows-7.aspx" target="_blank">Test Driving Remoting in Windows 7</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2009/11/20/powershell-enabling-powershell-v2-remotely/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing Individual WMI Instances</title>
		<link>http://www.christiano.ch/wordpress/2009/10/28/accessing-individual-wmi-instances/</link>
		<comments>http://www.christiano.ch/wordpress/2009/10/28/accessing-individual-wmi-instances/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 14:26:28 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2009/10/28/accessing-individual-wmi-instances/</guid>
		<description><![CDATA[Did you know, accessing individual WMI Instances and their Namespaces is pretty easy as 1-2-3.. You always get back all instances of a given WMI class when using Get-WMIObject. However, what if you just wanted to get a specific instance? Or you just wanted to find out how much space is left on drive C:? [...]]]></description>
			<content:encoded><![CDATA[<table style="width: 675px;" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td width="490" valign="top">
<h1>Did you know, accessing individual WMI Instances and their Namespaces is pretty easy as 1-2-3..</h1>
<p><br class="spacer_" /></p>
<p>You always get back all instances of a given WMI class when using Get-WMIObject. However, what if you just wanted to get a specific instance? Or you just wanted to find out how much space is left on drive C:? The next line gives you all drives:</p>
</td>
<td width="184" valign="top"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2009/10/Logo_PowerShell.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Logo_PowerShell" src="http://www.christiano.ch/wordpress/wp-content/uploads/2009/10/Logo_PowerShell_thumb.png" border="0" alt="Logo_PowerShell" width="240" height="188" /></a></td>
</tr>
</tbody>
</table>
<p><span id="more-710"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-WMIObject</span> Win32_LogicalDisk <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span> Name<span style="color: pink;">,</span> FreeSpace</pre></div></div>

<p>The trick is to use casting and WMI paths. The following line will provide specifically the C: drive:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span><span style="color: #008080;">wmi</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">'Win32_LogicalDisk=&quot;C:&quot;'</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span> Name<span style="color: pink;">,</span> Freespace <span style="color: #008080; font-style: italic;">-autosize</span></pre></div></div>

<p>To simply get the free bytes, use this:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">wmi</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">'Win32_LogicalDisk=&quot;C:&quot;'</span><span style="color: #000000;">&#41;</span>.FreeSpace</pre></div></div>

<p>What happens here is a simple conversion. You specify text, then you ask PowerShell to convert it to a WMI object using [wmi], which is actually is a type accelerator, a shortcut. This is a way to find out the real .NET type it refers to:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span><span style="color: #008080;">wmi</span><span style="color: #000000;">&#93;</span>.FullName</pre></div></div>

<p>Of course, PowerShell cannot convert any string to a WMI object. You will need to specify the exact WMI object path, which is unique for each WMI object and contains the class name and so called key properties. Here is how you find out the object path for a Service:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> Win32_Service <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span> Name<span style="color: pink;">,</span> __Path <span style="color: #008080; font-style: italic;">-wrap</span></pre></div></div>

<p>You can omit the PC name and WMI namespace for local objects in the standard WMI namespace. So to access a given Service directly, do this:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span><span style="color: #008080;">wmi</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">'Win32_Service=&quot;WSearch&quot;'</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span> <span style="color: pink;">*</span></pre></div></div>

<p>Why not use Get-Service? You could, but WMI is returning a lot more information about a service:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Service</span> WSearch <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span> <span style="color: pink;">*</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2009/10/28/accessing-individual-wmi-instances/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
