<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-31227280</id><updated>2012-01-19T09:29:39.430-08:00</updated><title type='text'>Windows PowerShell</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>61</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-31227280.post-6617002161558751797</id><published>2012-01-19T09:21:00.000-08:00</published><updated>2012-01-19T09:29:39.446-08:00</updated><title type='text'>WMI - HyperV</title><content type='html'>Get-WmiObject -Namespace ROOT -Query 'SELECT * FROM __Namespace'  | Select Name&lt;br /&gt;$vSmsvc = Get-WmiObject -Namespace ROOT\Virtualization -Class Msvm_VirtualSwitchManagementService&lt;br /&gt;&lt;br /&gt;Get-WmiObject -Namespace ROOT\Virtualization -List |  ? { $_.Name -match '^Msvm' }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-6617002161558751797?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/6617002161558751797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=6617002161558751797' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/6617002161558751797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/6617002161558751797'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2012/01/wmi-hyperv.html' title='WMI - HyperV'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-4627297571461290511</id><published>2011-03-22T18:06:00.001-07:00</published><updated>2011-03-22T18:06:41.341-07:00</updated><title type='text'>Reading Eml Files</title><content type='html'>Function Load-EmlFile&lt;br /&gt;{&lt;br /&gt;    Param&lt;br /&gt;    (&lt;br /&gt;        $EmlFileName&lt;br /&gt;    )&lt;br /&gt;    $AdoDbStream = New-Object -ComObject ADODB.Stream&lt;br /&gt;    $AdoDbStream.Open()&lt;br /&gt;    $AdoDbStream.LoadFromFile($EmlFileName)&lt;br /&gt;    $CdoMessage = New-Object -ComObject CDO.Message&lt;br /&gt;    $CdoMessage.DataSource.OpenObject($stream,"_Stream")&lt;br /&gt;    &lt;br /&gt;    return $CdoMessage&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-4627297571461290511?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/4627297571461290511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=4627297571461290511' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4627297571461290511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4627297571461290511'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2011/03/reading-eml-files.html' title='Reading Eml Files'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-1930131988669476490</id><published>2010-02-02T08:14:00.000-08:00</published><updated>2010-02-02T08:15:57.643-08:00</updated><title type='text'>PowerShell Profile - Make your startup profile</title><content type='html'>new-item -path $profile -type file -force&lt;br /&gt;'$MaximumHistoryCount=9999' | out-file $profile&lt;br /&gt;"`n" | out-file $profile -append&lt;br /&gt;'Start-Transcript' | out-file $profile -append&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-1930131988669476490?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/1930131988669476490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=1930131988669476490' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1930131988669476490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1930131988669476490'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2010/02/powershell-profile-make-your-startup.html' title='PowerShell Profile - Make your startup profile'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-1615753583471837540</id><published>2010-02-01T15:41:00.000-08:00</published><updated>2010-02-01T15:42:28.429-08:00</updated><title type='text'>System.Configuration - Modify PowerShell.Exe.Config</title><content type='html'>[Reflection.Assembly]::LoadWithPartialName("System.Configuration")&lt;br /&gt;$config=[System.Configuration.ConfigurationManager]::OpenExeConfiguration([System.Configuration.ConfigurationUserLevel]::None)&lt;br /&gt;$config.SectionGroups | % { $_.name }&lt;br /&gt;$config.SectionGroups.Item("system.serviceModel").Bindings.NetTcpBinding.Bindings&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-1615753583471837540?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/1615753583471837540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=1615753583471837540' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1615753583471837540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1615753583471837540'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2010/02/systemconfiguration-modify.html' title='System.Configuration - Modify PowerShell.Exe.Config'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-4448663208459442452</id><published>2010-01-31T21:45:00.000-08:00</published><updated>2010-01-31T21:45:51.576-08:00</updated><title type='text'>PowerShell UDP Client/Server</title><content type='html'>"$port=2020&lt;br /&gt;$endpoint = new-object System.Net.IPEndPoint ([IPAddress]::Loopback,$port)&lt;br /&gt;$udpclient=new-Object System.Net.Sockets.UdpClient&lt;br /&gt;$b=[Text.Encoding]::ASCII.GetBytes('Is anyone there?')&lt;br /&gt;$bytesSent=$udpclient.Send($b,$b.length,$endpoint)&lt;br /&gt;$udpclient.Close()&lt;br /&gt;&lt;br /&gt;$port=2020&lt;br /&gt;$endpoint = new-object System.Net.IPEndPoint ([IPAddress]::Any,$port)&lt;br /&gt;$udpclient=new-Object System.Net.Sockets.UdpClient $port&lt;br /&gt;$content=$udpclient.Receive([ref]$endpoint)&lt;br /&gt;[Text.Encoding]::ASCII.GetString($content)"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-4448663208459442452?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/4448663208459442452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=4448663208459442452' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4448663208459442452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4448663208459442452'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2010/01/powershell-udp-clientserver.html' title='PowerShell UDP Client/Server'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-797677264732279211</id><published>2010-01-22T09:59:00.000-08:00</published><updated>2010-01-22T10:04:09.741-08:00</updated><title type='text'>PowerShell Choice (Yes/No) - User Input</title><content type='html'>$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&amp;Yes",""&lt;br /&gt;$no = New-Object System.Management.Automation.Host.ChoiceDescription "&amp;No",""&lt;br /&gt;$choices =  [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)&lt;br /&gt;$caption = "Warning!"&lt;br /&gt;$message = "Do you want to proceed"&lt;br /&gt;$result = $Host.UI.PromptForChoice($caption,$message,$choices,0)&lt;br /&gt;if($result -eq 0) { Write-Host "You answered YES" &lt;br /&gt;if($result -eq 1) { Write-Host "You answered NO" }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-797677264732279211?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/797677264732279211/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=797677264732279211' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/797677264732279211'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/797677264732279211'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2010/01/powershell-choice-yesno-user-input.html' title='PowerShell Choice (Yes/No) - User Input'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-757495186228188492</id><published>2010-01-21T15:10:00.000-08:00</published><updated>2010-01-21T15:11:01.827-08:00</updated><title type='text'>PowerShell - Change execution policy</title><content type='html'>powershell -c set-executionPolicy unrestricted -scope localMachine –force&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-757495186228188492?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/757495186228188492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=757495186228188492' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/757495186228188492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/757495186228188492'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2010/01/powershell-change-execution-policy.html' title='PowerShell - Change execution policy'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-542995167746183488</id><published>2008-04-08T21:40:00.001-07:00</published><updated>2008-04-08T21:40:08.179-07:00</updated><title type='text'>V2</title><content type='html'>&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-542995167746183488?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/542995167746183488/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=542995167746183488' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/542995167746183488'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/542995167746183488'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/04/v2.html' title='V2'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-4392706309100599815</id><published>2008-04-04T23:26:00.000-07:00</published><updated>2008-04-04T23:27:41.649-07:00</updated><title type='text'>GV : Get-VariableName</title><content type='html'>$a="This is test"&lt;br /&gt;$b=(gv -name a).value&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-4392706309100599815?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/4392706309100599815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=4392706309100599815' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4392706309100599815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4392706309100599815'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/04/gv-get-variablename.html' title='GV : Get-VariableName'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-7224055070763654461</id><published>2008-04-04T22:25:00.000-07:00</published><updated>2008-04-04T22:31:59.063-07:00</updated><title type='text'>Directory Searcher - FirstName LastName</title><content type='html'>DirectorySearcher gets initializes with default domain controller.&lt;br /&gt;&lt;br /&gt;$searcher = New-Object System.DirectoryServices.DirectorySearcher&lt;br /&gt;$searcher.Filter = '(&amp;(objectClass=User)(displayName=fistName lastName))'&lt;br /&gt;$userResult = $searcher.FindOne()&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-7224055070763654461?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/7224055070763654461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=7224055070763654461' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/7224055070763654461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/7224055070763654461'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/04/directory-searcher-firstname-lastname.html' title='Directory Searcher - FirstName LastName'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-7995797927873281142</id><published>2008-03-14T08:34:00.000-07:00</published><updated>2008-03-14T08:37:32.510-07:00</updated><title type='text'>Rename using RegEx</title><content type='html'>Wrong approach &lt;br /&gt;&lt;br /&gt;dir -rec -fi *.cs | ren  "Foo\(.*\)" "Bar$1"&lt;br /&gt;&lt;br /&gt;Correct (using Script block parameters)&lt;br /&gt;&lt;br /&gt;dir -rec -fi *.cs | ren  -new { $_ -replace ‘Foo\(.*\)’, ‘Bar$1’}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-7995797927873281142?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/7995797927873281142/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=7995797927873281142' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/7995797927873281142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/7995797927873281142'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/03/rename-using-regex.html' title='Rename using RegEx'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-1804284704887759257</id><published>2008-03-07T10:52:00.000-08:00</published><updated>2008-03-07T10:58:15.549-08:00</updated><title type='text'>Win2K8 Licensing Server</title><content type='html'>PS&gt;nslookup -type=srv _vlmcs._tcp ## KSM Server&lt;br /&gt;PS&gt;nslookup -type=srv _ldap._tcp ## Domain Controller&lt;br /&gt;&lt;br /&gt;PS&gt; (New-Object System.Net.Sockets.TcpClient serverName,1688).Connected&lt;br /&gt;True&lt;br /&gt;PS&gt; slmgr -dli # Check licensing server&lt;br /&gt;&lt;br /&gt;PS&gt; slmgr -ato # Activate using licensing server)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-1804284704887759257?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/1804284704887759257/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=1804284704887759257' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1804284704887759257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1804284704887759257'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/03/win2k8-licensing-server.html' title='Win2K8 Licensing Server'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-3561021332905027913</id><published>2008-03-07T09:36:00.000-08:00</published><updated>2008-03-07T09:39:00.569-08:00</updated><title type='text'>Terminal Services License</title><content type='html'>Enable Remote Desktop&lt;br /&gt;&lt;br /&gt;Reg Add "hklm\system\currentcontrolset\control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f&lt;br /&gt;&lt;br /&gt;Terminal Service License (TSCAL Licensing Service)&lt;br /&gt;&lt;br /&gt;reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TermService\Parameters\LicenseServers\&lt;ServerName&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-3561021332905027913?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/3561021332905027913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=3561021332905027913' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/3561021332905027913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/3561021332905027913'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/03/terminal-services-license.html' title='Terminal Services License'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-7488744847812965795</id><published>2008-03-07T09:35:00.000-08:00</published><updated>2008-03-07T09:36:46.937-08:00</updated><title type='text'>Wake up on LAN</title><content type='html'>New group article &lt;br /&gt;&lt;br /&gt;gwmi Win32_NetworkAdapter -filter "AdapterTypeId=0" | % {&lt;br /&gt;&lt;br /&gt;   $strNetworkAdapterID=$_.PNPDeviceID.ToUpper()&lt;br /&gt;&lt;br /&gt;   gwmi MSPower_DeviceWakeEnable -Namespace 'Root\Wmi' | % {&lt;br /&gt;      #  if($_.InstanceName.ToUpper() -like "$strNetworkAdapterID*"){      &lt;br /&gt;      if($_.InstanceName.ToUpper().startsWith($strNetworkAdapterID)){&lt;br /&gt;             $_.Enable = $true &lt;br /&gt;             $_.Put()&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;http://blogs.technet.com/smsandmom/archive/2008/03/04/configmgr-2007-implementing-wake-on-lan-wol.aspx&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-7488744847812965795?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/7488744847812965795/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=7488744847812965795' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/7488744847812965795'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/7488744847812965795'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/03/wake-up-on-lan.html' title='Wake up on LAN'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-8406477536904790329</id><published>2008-03-06T14:58:00.000-08:00</published><updated>2008-03-06T15:16:41.128-08:00</updated><title type='text'>Member of AD Group</title><content type='html'>PS &gt; $s=new-object DirectoryServices.DirectorySearcher&lt;br /&gt;PS &gt; $s.Filter='(cn=Name-of-the-Group)'&lt;br /&gt;PS &gt; ($s.findone().properties.member)&lt;br /&gt;&lt;br /&gt;Local group&lt;br /&gt;&lt;br /&gt;$admgrp = [ADSI]”WinNT://Server/Administrators,group” &lt;br /&gt;$admgrp.add("WinNT://Domain/User”) &lt;br /&gt;&lt;br /&gt;$serversList | ForEach-Object {([adsi]”WinNT://$_/administrators,group”).add(“WinNT://Domain/User”) &lt;br /&gt;&lt;br /&gt;Function Make-Admin ($machine,$user) &lt;br /&gt;&lt;br /&gt;{([adsi]”WinNT://$machine/administrators,group”).add(“WinNT://$user”)} &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;$admgrp = [ADSI]"WinNT://./Administrators,group"&lt;br /&gt;$admgrp.psbase.invoke("members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}&lt;br /&gt;&lt;br /&gt;Ref URL: http://www.c-sharpcorner.com/UploadFile/ecabral/ADand.NET08242005065451AM/ADand.NET.aspx&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-8406477536904790329?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/8406477536904790329/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=8406477536904790329' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8406477536904790329'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8406477536904790329'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/03/member-of-ad-group.html' title='Member of AD Group'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-719690085476248990</id><published>2008-03-05T22:14:00.001-08:00</published><updated>2008-03-05T22:14:33.796-08:00</updated><title type='text'>CLR Runtime Directory : .NET API</title><content type='html'>[System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-719690085476248990?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/719690085476248990/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=719690085476248990' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/719690085476248990'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/719690085476248990'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/03/clr-runtime-directory-net-api.html' title='CLR Runtime Directory : .NET API'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-9040559813757252355</id><published>2008-03-05T22:09:00.000-08:00</published><updated>2008-03-05T22:13:16.610-08:00</updated><title type='text'>PowerShell CTP Debugging Feature</title><content type='html'>New-PSBreakpoint (renamed post CTP to Set-PSBreakpoint)&lt;br /&gt;Get-PSBreakpoint&lt;br /&gt;Remove-PSBreakpoint&lt;br /&gt;Enable-PSBreakpoint&lt;br /&gt;Disable-PSBreakpoint&lt;br /&gt;Get-PSCallstack&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Get-Help about_debugger in the PowerShell CTP.&lt;br /&gt;&lt;br /&gt;New-PSBreakpoint can set breakpoints on scripts, commands, and on the read or write of variables.&lt;br /&gt;&lt;br /&gt;Note : This does not catch the read or write of properties of variables.&lt;br /&gt;&lt;br /&gt;Examples:&lt;br /&gt;&lt;br /&gt;New-PSBreakpoint –script “foo.ps1” –line 10 # Breaks on line 10 of foo.ps1&lt;br /&gt;&lt;br /&gt;New-PSBreakpoint –command “Write-Debug” # Breaks on Write-Debug&lt;br /&gt;&lt;br /&gt;$a = “hello”&lt;br /&gt;New-PSBreakpoint –variable “a” –rw &lt;br /&gt;&lt;br /&gt;(-r for read, -w for write, and –mode Read|Write|ReadWrite post CTP)&lt;br /&gt;&lt;br /&gt;$a # breaks on the read of a&lt;br /&gt;&lt;br /&gt;$a = 5 # breaks on the write of A&lt;br /&gt;&lt;br /&gt;You can also set a conditional breakpoint, by adding the –action parameter&lt;br /&gt;&lt;br /&gt;# Breaks only when you set a to 5&lt;br /&gt;&lt;br /&gt;New-PSBreakpoint –variable “a” –action {if ($a –eq 5) {break}}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-9040559813757252355?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/9040559813757252355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=9040559813757252355' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/9040559813757252355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/9040559813757252355'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/03/powershell-ctp-debugging-feature.html' title='PowerShell CTP Debugging Feature'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-6686954166048405292</id><published>2008-03-05T22:07:00.002-08:00</published><updated>2008-03-05T22:09:33.991-08:00</updated><title type='text'>Format-XML</title><content type='html'>function Format-XML ([xml]$xml, $indent=2) &lt;br /&gt;{ &lt;br /&gt;    $StringWriter = New-Object System.IO.StringWriter &lt;br /&gt;    $XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter &lt;br /&gt;    $xmlWriter.Formatting = "indented" &lt;br /&gt;    $xmlWriter.Indentation = $Indent &lt;br /&gt;    $xml.WriteContentTo($XmlWriter) &lt;br /&gt;    $XmlWriter.Flush() &lt;br /&gt;    $StringWriter.Flush() &lt;br /&gt;    Write-Output $StringWriter.ToString() &lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-6686954166048405292?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/6686954166048405292/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=6686954166048405292' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/6686954166048405292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/6686954166048405292'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2008/03/format-xml.html' title='Format-XML'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-1530541938701309589</id><published>2007-07-13T19:51:00.000-07:00</published><updated>2008-03-05T21:50:23.767-08:00</updated><title type='text'>PowerShell Gotchas</title><content type='html'>Create array of integer &lt;br /&gt;new-object int [2,2]&lt;br /&gt;&lt;br /&gt;Accessing .NET methods&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-1530541938701309589?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/1530541938701309589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=1530541938701309589' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1530541938701309589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1530541938701309589'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/07/powershell-gotchas.html' title='PowerShell Gotchas'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-163039273953902720</id><published>2007-06-18T19:23:00.000-07:00</published><updated>2007-06-18T19:25:00.413-07:00</updated><title type='text'>Discover all the WMI namespaces installed on system</title><content type='html'>PS&gt;Get-WMIObject -Query "Select * from __Namespace" -Namespace Root&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PS&gt;gwmi -q 'select * from __namespace' -n root  select name&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;name&lt;br /&gt;----&lt;br /&gt;ServiceModel&lt;br /&gt;SECURITY&lt;br /&gt;MSAPPS12&lt;br /&gt;RSOP&lt;br /&gt;Cli&lt;br /&gt;aspnet&lt;br /&gt;SecurityCenter&lt;br /&gt;WMI&lt;br /&gt;CIMV2&lt;br /&gt;Policy&lt;br /&gt;Microsoft&lt;br /&gt;DEFAULT&lt;br /&gt;directory&lt;br /&gt;subscription&lt;br /&gt;MSAPPS11&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-163039273953902720?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/163039273953902720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=163039273953902720' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/163039273953902720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/163039273953902720'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/06/discover-all-wmi-namespaces-installed.html' title='Discover all the WMI namespaces installed on system'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-8388332736908249976</id><published>2007-06-13T08:31:00.000-07:00</published><updated>2007-06-13T08:41:19.176-07:00</updated><title type='text'>Type Extensions and Type Formatters</title><content type='html'>For extending type PowerShell either uses user defined Xml files ( .ps1xml) and cmdlet Update-TypeData to update the PowerShell runtime information or you can modify system wide&lt;br /&gt;&lt;br /&gt;$pshome/types.ps1Xml (which is btw is not recommended method of doing it , but most of the blogs I see do that , even blogs on MSDN)&lt;br /&gt;&lt;br /&gt;You should create on TypeData file and call Update-TypeData cmdlet in your profile.&lt;br /&gt;&lt;br /&gt;The use of $pshome/types.ps1xml is to provide additional metadata about the .NET types i.e., extend your type same way you do that with Add-Member cmdlet.&lt;br /&gt;&lt;br /&gt;Format data ( $pshome/DotNetTypes.Format.PS1Xml)&lt;br /&gt;&lt;br /&gt;When Powershell needs to output the objects to the console window it figures out the formatting using these format files located in $pshome folder.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;the type extensions can add methods, properties etc to the class, but the type formatter decides what gets written down on the console window.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-8388332736908249976?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/8388332736908249976/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=8388332736908249976' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8388332736908249976'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8388332736908249976'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/06/type-extensions-and-type-formatters.html' title='Type Extensions and Type Formatters'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-678710458996591702</id><published>2007-06-11T19:11:00.000-07:00</published><updated>2007-06-11T19:14:33.750-07:00</updated><title type='text'>Start Async Command</title><content type='html'>By default &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;PowerShell&lt;/span&gt; doesn't support &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;Async&lt;/span&gt; command invocation&lt;br /&gt;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;PowerShell&lt;/span&gt; does have &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;Inovke&lt;/span&gt;-Item command that can be used as Start.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;exe&lt;/span&gt; command, but if you want to run something &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;async&lt;/span&gt; you can always use .NET &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;FW&lt;/span&gt; Start Method of System.Diagnostics.Process Class&lt;br /&gt;&lt;br /&gt;[System.Diagnostics.Process]::Start("&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;calc&lt;/span&gt;")&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-678710458996591702?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/678710458996591702/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=678710458996591702' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/678710458996591702'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/678710458996591702'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/06/start-async-command.html' title='Start Async Command'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-6196984816393301517</id><published>2007-06-11T18:45:00.000-07:00</published><updated>2007-06-11T18:58:50.354-07:00</updated><title type='text'>PowerShell Invoke Method</title><content type='html'>You can define a variable with Method name and then you can call Invoke on it to execute the method&lt;br /&gt;&lt;br /&gt;Example :&lt;br /&gt;&lt;br /&gt;PS &gt; $Method= "SubString"&lt;br /&gt;&lt;br /&gt;PS &gt; "&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;PowerShell&lt;/span&gt;".$Method.Invoke(0,5)&lt;br /&gt;Power&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-6196984816393301517?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/6196984816393301517/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=6196984816393301517' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/6196984816393301517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/6196984816393301517'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/06/powershell-invoke-method.html' title='PowerShell Invoke Method'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-367781424649757797</id><published>2007-06-11T18:38:00.001-07:00</published><updated>2007-06-11T18:44:35.153-07:00</updated><title type='text'>CMD.exe FOR Delims</title><content type='html'>How to use &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;delims&lt;/span&gt; and tokens in &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;PowerShell&lt;/span&gt; , as import-&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;CSV&lt;/span&gt; doesn't provide &lt;span class="blsp-spelling-corrected" id="SPELLING_ERROR_3"&gt;delimiters&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;FOR /F “TOKENS=1,3,5  &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;DELIMS&lt;/span&gt;=;” %%a IN (c:\data.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;txt&lt;/span&gt;) do ECHO %%a, %%b, %%c&lt;br /&gt;&lt;br /&gt;Use&lt;br /&gt;String.Split(';') --&gt; but it slow performance&lt;br /&gt;&lt;br /&gt;### Note: you can use mutliple array indexers in a single command.&lt;br /&gt;### Prints out every token in different lines&lt;br /&gt;&lt;br /&gt;PS&gt;type a.txt  % { $_.split(';')[0,2,4] } &lt;br /&gt;&lt;br /&gt;### Note: Subexpression $() and double quotes to use $OFS&lt;br /&gt;### Prints out all the tokens in same line.&lt;br /&gt;&lt;br /&gt;PS&gt; type a.txt  % { "$($_.split(';')[0,2,4])" }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-367781424649757797?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/367781424649757797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=367781424649757797' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/367781424649757797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/367781424649757797'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/06/cmdexe-for-delims.html' title='CMD.exe FOR Delims'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-1700043433115742446</id><published>2007-06-11T18:28:00.000-07:00</published><updated>2007-06-11T18:35:57.893-07:00</updated><title type='text'>Cmd.exe &amp;&amp; and || Operator</title><content type='html'>In &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;Cmd&lt;/span&gt;.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;exe&lt;/span&gt; you can use following conditional operator to execute your commands based open the success and failure of previous commands&lt;br /&gt;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;cmd&lt;/span&gt;1 &amp;&amp;amp; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;cmd&lt;/span&gt;2&lt;br /&gt;Runs the command following &amp;&amp;amp; only if the command preceding the symbol is successful.&lt;br /&gt;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;cmd&lt;/span&gt;1  &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;cmd&lt;/span&gt;2&lt;br /&gt;Run the command following  only if the command preceding fails.&lt;br /&gt;&lt;br /&gt;Unfortunately these operators are not implemented in &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;PowerShell&lt;/span&gt; so you need to check for %&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;ERRORLEVEL&lt;/span&gt;% , which is $&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;LastExitCode&lt;/span&gt; in PS&lt;br /&gt;&lt;br /&gt;&amp;&amp;amp;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;cmd&lt;/span&gt;1; if ($&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;LastExitCode&lt;/span&gt; -&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;eq&lt;/span&gt; 0) { &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_12"&gt;cmd&lt;/span&gt;2 }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_13"&gt;cmd&lt;/span&gt;1;if ($&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_14"&gt;LastExitCode&lt;/span&gt; -&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_15"&gt;ne&lt;/span&gt; 0 ) { &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_16"&gt;cmd&lt;/span&gt; 2}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-1700043433115742446?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/1700043433115742446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=1700043433115742446' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1700043433115742446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1700043433115742446'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/06/cmdexe-and-operator.html' title='Cmd.exe &amp;&amp; and || Operator'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-6820066392506876797</id><published>2007-03-28T18:43:00.001-07:00</published><updated>2007-07-13T19:56:47.392-07:00</updated><title type='text'>.Net Format Specifiers</title><content type='html'>'&lt;br /&gt;'This code example produces the following results:&lt;br /&gt;'&lt;br /&gt;'Standard Numeric Format Specifiers&lt;br /&gt;'(C) Currency: . . . . . . . . ($123.00)&lt;br /&gt;'(D) Decimal:. . . . . . . . . -123&lt;br /&gt;'(E) Scientific: . . . . . . . -1.234500E+002&lt;br /&gt;'(F) Fixed point:. . . . . . . -123.45&lt;br /&gt;'(G) General:. . . . . . . . . -123&lt;br /&gt;' (default):. . . . . . . . -123 (default = 'G')&lt;br /&gt;'(N) Number: . . . . . . . . . -123.00&lt;br /&gt;'(P) Percent:. . . . . . . . . -12,345.00 %&lt;br /&gt;'(R) Round-trip: . . . . . . . -123.45&lt;br /&gt;'(X) Hexadecimal:. . . . . . . FFFFFF85&lt;br /&gt;'&lt;br /&gt;'Standard DateTime Format Specifiers&lt;br /&gt;'(d) Short date: . . . . . . . 6/26/2004&lt;br /&gt;'(D) Long date:. . . . . . . . Saturday, June 26, 2004&lt;br /&gt;'(t) Short time: . . . . . . . 8:11 PM&lt;br /&gt;'(T) Long time:. . . . . . . . 8:11:04 PM&lt;br /&gt;'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM&lt;br /&gt;'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM&lt;br /&gt;'(g) General date/short time:. 6/26/2004 8:11 PM&lt;br /&gt;'(G) General date/long time: . 6/26/2004 8:11:04 PM&lt;br /&gt;' (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')&lt;br /&gt;'(M) Month:. . . . . . . . . . June 26&lt;br /&gt;'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT&lt;br /&gt;'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04&lt;br /&gt;'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)&lt;br /&gt;'(U) Universal sortable: . . . Sunday, June 27, 2004 3:11:04 AM&lt;br /&gt;'(Y) Year: . . . . . . . . . . June, 2004&lt;br /&gt;'&lt;br /&gt;'Standard Enumeration Format Specifiers&lt;br /&gt;'(G) General:. . . . . . . . . Green&lt;br /&gt;' (default):. . . . . . . . Green (default = 'G')&lt;br /&gt;'(F) Flags:. . . . . . . . . . Green (flags or integer)&lt;br /&gt;'(D) Decimal number: . . . . . 3&lt;br /&gt;'(X) Hexadecimal:. . . . . . . 00000003&lt;br /&gt;'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-6820066392506876797?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/6820066392506876797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=6820066392506876797' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/6820066392506876797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/6820066392506876797'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/03/net-format-specifiers.html' title='.Net Format Specifiers'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-8528389297990148426</id><published>2007-03-13T18:02:00.001-07:00</published><updated>2007-03-28T16:23:02.955-07:00</updated><title type='text'>Active Directory : Query Domain Controller</title><content type='html'>&lt;span xmlns=""&gt;&lt;p&gt;Get-Domain Controller &lt;/p&gt;&lt;p&gt;$dom = [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain()&lt;br /&gt;Get the DC's for the domain&lt;br /&gt;$dom.DomainControllers  select Name&lt;br /&gt;Find one DC&lt;br /&gt;$dom.FindDomainController()&lt;br /&gt;DC's for all the domains in the forest&lt;br /&gt;$dom.Forest.Domains&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-8528389297990148426?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/8528389297990148426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=8528389297990148426' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8528389297990148426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8528389297990148426'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/03/active-directory-query-domain.html' title='Active Directory : Query Domain Controller'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-4076745421552568262</id><published>2007-03-12T22:10:00.001-07:00</published><updated>2007-03-12T22:10:34.723-07:00</updated><title type='text'>Excel 2007 and  Workbooks.Add Method</title><content type='html'>&lt;span xmlns=''&gt;&lt;p&gt;$oExcel = New-Object -COM Excel.Application&lt;br /&gt;&lt;/p&gt;&lt;p&gt;$oExcel.Visible = $true&lt;br /&gt;&lt;/p&gt;&lt;p&gt;$oBooks = $oExcel.Workbooks&lt;br /&gt;&lt;/p&gt;&lt;p&gt;$oCulture= [System.Globalization.CultureInfo]"en-US"&lt;br /&gt;&lt;/p&gt;&lt;p&gt;$oBook=$oBooks.psbase.gettype().InvokeMember("Add",[Reflection.BindingFlags]::InvokeMethod,$null,$oBooks,$null,$oCulture)&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-4076745421552568262?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/4076745421552568262/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=4076745421552568262' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4076745421552568262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4076745421552568262'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/03/excel-2007-and-workbooksadd-method.html' title='Excel 2007 and  Workbooks.Add Method'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-425043295990105849</id><published>2007-03-12T21:43:00.001-07:00</published><updated>2007-03-12T21:43:44.367-07:00</updated><title type='text'>PowerShell and Excel COM object</title><content type='html'>&lt;span xmlns=''&gt;&lt;p&gt;How to create excel file using Excel.Application Object&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;$oExcel = New-Object -COM Excel.Application&lt;br /&gt;&lt;/p&gt;&lt;p&gt;$oExcel.Visible = $true&lt;br /&gt;&lt;/p&gt;&lt;p&gt;$oBook = $oExcel.Workbooks.Add()&lt;br /&gt;&lt;/p&gt;&lt;p&gt;$oSheet = $oBook.Worksheets.Item(1)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;$oSheet.Cells.Item(1,1) = "Some value from PowerShell"&lt;br /&gt;&lt;/p&gt;&lt;p&gt;$oBook.SaveAs("$pwd\$($(get-date).tostring('yyyyMMdd')).xls")&lt;br /&gt;&lt;/p&gt;&lt;p&gt;$oExcel.Quit()&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-425043295990105849?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/425043295990105849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=425043295990105849' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/425043295990105849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/425043295990105849'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2007/03/powershell-and-excel-com-object.html' title='PowerShell and Excel COM object'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-5723868579049566721</id><published>2006-09-23T08:02:00.000-07:00</published><updated>2006-09-23T08:04:48.163-07:00</updated><title type='text'>PowerShell : Filing Bugs on connect.microsoft.com</title><content type='html'>&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;First time user : Register for the MS Connect program:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Visit &lt;a href="http://connect.microsoft.com/"&gt;http://connect.microsoft.com/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Click on "Available Programs" on the left and sign in with your Microsoft Passport credentials.&lt;br /&gt;&lt;br /&gt;Click "Apply" next to the the item "Windows PowerShell"&lt;br /&gt;&lt;br /&gt;Click the "Submit Feedback" link on the left navigation bar to submit new bugs and suggestions.&lt;br /&gt;&lt;br /&gt;Click the "Feedback" link on the left navigation bar to track your submitted bugs and suggestions, as well as view, vote, and comment on bugs and suggestions submitted by others.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;If you are already subscribed to the PowerShell (Monad) Connect site:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Click on "My Participation" and sign in with your Microsoft Passport credentials.&lt;br /&gt;&lt;br /&gt;Click "Windows PowerShell"&lt;br /&gt;&lt;br /&gt;Click the "Submit Feedback" link on the left navigation bar to submit new bugs and suggestions.&lt;br /&gt;&lt;br /&gt;Click the "Feedback" link on the left navigation bar to track your submitted bugs and Suggestions, as well as view, vote, and comment on bugs and suggestions submitted by others.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-5723868579049566721?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/5723868579049566721/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=5723868579049566721' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/5723868579049566721'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/5723868579049566721'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/09/filing-bugs-on-connect.html' title='PowerShell : Filing Bugs on connect.microsoft.com'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-4622674433971060866</id><published>2006-09-23T07:34:00.000-07:00</published><updated>2008-03-05T21:50:12.278-08:00</updated><title type='text'>PowerShell: WMI FailFast</title><content type='html'>WMIC /FAILFAST Switch&lt;br /&gt;&lt;br /&gt;$Server = "MYWEBSVR01"&lt;br /&gt;&lt;br /&gt;$Server %  {&lt;br /&gt;        if ((Get-WmiObject Win32_PingStatus -F "Address='$_'").StatusCode -eq 0 ) {&lt;br /&gt;                 Get-WmiObject Win32_OperatingSystem -comp $_&lt;br /&gt;         }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-4622674433971060866?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/4622674433971060866/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=4622674433971060866' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4622674433971060866'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4622674433971060866'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/09/powershell-wmi-failfast.html' title='PowerShell: WMI FailFast'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-8002053017532583840</id><published>2006-09-17T07:29:00.000-07:00</published><updated>2006-09-17T07:56:19.598-07:00</updated><title type='text'>PowerShell : New-Object vs System.Activator vs GetConstructors</title><content type='html'>New-Object System.DateTime 2006,09,16&lt;br /&gt;&lt;br /&gt;[System.Activator]::CreateInstance([System.DateTime], (2006,09,16))&lt;br /&gt;&lt;br /&gt;PS &gt; [DateTime].Gettype()&lt;br /&gt;IsPublic IsSerial Name BaseType&lt;br /&gt;-------- -------- ------------- ------------&lt;br /&gt;False True RuntimeType System.Type&lt;br /&gt;&lt;br /&gt;Since it is drived from System.Type type which has method called GetConstructors you can use&lt;br /&gt;&lt;br /&gt;$Ctor=[DateTime].GetConstructor(@([int], [int],[int]))&lt;br /&gt;&lt;br /&gt;GetConstructor : Takes array of System.Type&lt;br /&gt;&lt;br /&gt;$Ctor.Invoke (@([int], [int],[int]))&lt;br /&gt;&lt;br /&gt;Invoke method only takes one argument so don't try $Ctor([int],[int],[int])&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-8002053017532583840?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/8002053017532583840/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=8002053017532583840' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8002053017532583840'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8002053017532583840'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/09/powershell-new-object-vs.html' title='PowerShell : New-Object vs System.Activator vs GetConstructors'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-4959495781598899743</id><published>2006-09-17T07:17:00.000-07:00</published><updated>2008-03-05T21:49:39.245-08:00</updated><title type='text'>PowerShell : Synchronize time with Internet Server</title><content type='html'>Courtesy : Alex Angelopoulos&lt;br /&gt;&lt;br /&gt;Param(    [string]$ComputerName = "time.nist.gov",    [int]$Port = 13,    [switch]$Adjust,    [switch]$Difference,    [Switch]$Verbose)&lt;br /&gt;&lt;br /&gt;if($Verbose){$VerbosePreference = "Continue"}&lt;br /&gt;$TcpClient = New-Object System.Net.Sockets.TcpClient&lt;br /&gt;[byte[]]$buffer =@(); 0..63  %{$buffer += [byte]0}&lt;br /&gt;$TcpClient.Connect($ComputerName,$Port)&lt;br /&gt;$TcpStream = $TcpClient.GetStream()&lt;br /&gt;#The received time is adjusted to the server's guess&lt;br /&gt;# at client arrival time, so we get the time NOW for ref.&lt;br /&gt;$LocalTime = Get-Date&lt;br /&gt;$length = $TcpStream.Read($buffer, 0, $buffer.Length);&lt;br /&gt;Write-Verbose ("returned buffer length is $length bytes");&lt;br /&gt;[void]$TcpClient.Close()&lt;br /&gt;;#53994 06-09-16 14:51:53 50 0 0 334.4 UTC(NIST) *&lt;br /&gt;$response = [Text.Encoding]::ASCII.GetString($buffer)&lt;br /&gt;Write-Verbose ("Raw response string`: $response")&lt;br /&gt;Write-Verbose ("Raw response length is`: $length")&lt;br /&gt;$rca = $response.ToCharArray()  ?{[int]$_ -ge 32}$ofs = "";&lt;br /&gt;[int]$Year = (2000 + [string]$rca[6..7])&lt;br /&gt;[int]$Month = [string]$rca[9,10]&lt;br /&gt;[int]$Day = [string]$rca[12,13]&lt;br /&gt;[int]$Hour = [string]$rca[15,16]&lt;br /&gt;[int]$Minute = [string]$rca[18,19]&lt;br /&gt;[int]$Second = [string]$rca[21,22]&lt;br /&gt;$DateArgs = @([int]$Year,[int]$Month,[int]$Day,`&lt;br /&gt;    [int]$Hour,[int]$Minute,[int]$Second,[int]0,`&lt;br /&gt;    [Globalization.CultureInfo]::InvariantCulture.Calendar,`&lt;br /&gt;    [DateTimeKind]"Utc")&lt;br /&gt;$Rfc867Time = New-Object DateTime $DateArgs&lt;br /&gt;$Rfc867Time = $Rfc867Time.ToLocalTime()&lt;br /&gt;# correct the time if asked to do so:&lt;br /&gt;if($Adjust){Set-Date $Rfc867Time}&lt;br /&gt;if($Difference){[TimeSpan]($Rfc867Time - $LocalTime)}else{$Rfc867Time}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-4959495781598899743?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/4959495781598899743/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=4959495781598899743' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4959495781598899743'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4959495781598899743'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/09/powershell-synchronize-time-with.html' title='PowerShell : Synchronize time with Internet Server'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-1155596775251786503</id><published>2006-09-16T08:21:00.000-07:00</published><updated>2006-09-16T09:01:26.323-07:00</updated><title type='text'>PowerShell: Definition of static methods</title><content type='html'>I found that in current version of Powershell , if you just specify the name of object and the method name without parens , it will return you the method definition. Which I found quite handy most of the time , it is just like intellisense and saves up web lookup in MSDN for the method parameters.&lt;br /&gt;&lt;br /&gt;PS &gt; (Get-Date).AddDays&lt;br /&gt;MemberType : Method&lt;br /&gt;OverloadDefinitions : {System.DateTime AddDays(Double value)}&lt;br /&gt;TypeNameOfValue : System.Management.Automation.PSMethod&lt;br /&gt;Value : System.DateTime AddDays(Double value)&lt;br /&gt;Name : AddDays&lt;br /&gt;IsInstance : True&lt;br /&gt;&lt;br /&gt;but if you try same thing static method it doesn't work .. may be a bug !!!&lt;br /&gt;&lt;br /&gt;but I have workaround till it get noticed and fixed&lt;br /&gt;&lt;br /&gt;so if I am looking for static method&lt;br /&gt;&lt;br /&gt;PS&gt; (Get-Date).ParseExact&lt;br /&gt;PS&gt;[System.DateTime]::ParseExact&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let's try workaround&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PS&gt; [System.DateTime] Get-Member -Static ? { $_.Name -eq "ParseExact" } Format-List&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-1155596775251786503?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/1155596775251786503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=1155596775251786503' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1155596775251786503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1155596775251786503'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/09/powershell-definition-of-static-method.html' title='PowerShell: Definition of static methods'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-5493309399243280453</id><published>2006-09-13T21:38:00.000-07:00</published><updated>2006-09-13T22:34:07.237-07:00</updated><title type='text'>Powershell : Find out the size of subfolders</title><content type='html'>[Enum]::GetValues([IO.FileAttributes])&lt;br /&gt;&lt;br /&gt;ReadOnly&lt;br /&gt;Hidden&lt;br /&gt;System&lt;br /&gt;Directory&lt;br /&gt;Archive&lt;br /&gt;Device&lt;br /&gt;Normal&lt;br /&gt;Temporary&lt;br /&gt;SparseFile&lt;br /&gt;ReparsePoint&lt;br /&gt;Compressed&lt;br /&gt;Offline&lt;br /&gt;NotContentIndexed&lt;br /&gt;Encrypted&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Both [System.IO.DirectoryInfo] and [System.IO.FileInfo] object contains Property called Attributes which returns [System.IO.FileAttributes]&lt;br /&gt;&lt;br /&gt;To find all the sub folders in the current working directory&lt;br /&gt;&lt;br /&gt;Either use .Net&lt;br /&gt;&lt;br /&gt;Get-ChildItem Where-Object { $_.Attributes -like "*Directory*" }&lt;br /&gt;&lt;br /&gt;or use PowerShell ScriptProperty "Mode"&lt;br /&gt;&lt;br /&gt;Get-ChildItem Where-Object { $_.Mode -Like "d*" }&lt;br /&gt;&lt;br /&gt;or use PowerShell ScriptProperty PSIsContainer&lt;br /&gt;&lt;br /&gt;Get-ChildItem Where-Object { $_. PSIsContainer}&lt;br /&gt;&lt;br /&gt;If you don't like typing full commands use aliases&lt;br /&gt;&lt;br /&gt;ls ? { $_.PSIsContainer }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ls ? { $_.PsIsContainer } % { $size=0;ls -r $_.Name % { $size +=$_.Length }; @{$_.Name=$size} }&lt;br /&gt;&lt;br /&gt;Formatted&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;ls ? { $_.PsIsContainer }&lt;br /&gt;% {&lt;br /&gt;$size=0;&lt;br /&gt;ls -r $_.Name % {$size +=$_.Length };&lt;br /&gt;@{$_.Name=$size}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Explanation&lt;br /&gt;&lt;br /&gt;Get-ChildItem in current folder&lt;br /&gt;Using Where-Object filter out object which returns $_.PSIsContainer -eq $true&lt;br /&gt;Pass it to first ForEach-Object pipeline&lt;br /&gt;This has three commands&lt;br /&gt;First one initialize the variable $size to zero.&lt;br /&gt;Second command executes Get-ChildItem recursively on current pipeline object&lt;br /&gt;The objects return from second command is passed to second ForEach-Object which has only one command&lt;br /&gt;First command adds the Length property of current pipeline (now $_ represents the object coming from dir -rec $_.Name command) to the $size variable.Third command of first ForEach-Object pipeline creates a hashtable @{} with key as the directory name and the value as $size variable&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now if you want this output sorted&lt;br /&gt;&lt;br /&gt;ls ? {$_.PsIsContainer} % { $s=0; ls -r $_.Name % {$s +=$_.Length }; @{ $_.Name=$s } } Sort-Object {$_.Values}&lt;br /&gt;&lt;br /&gt;In the last part of the pipeline the Sort-object cmdlet takes in script block argument and applies the sort algorithm on $_.Values property of the hashtable.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-5493309399243280453?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/5493309399243280453/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=5493309399243280453' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/5493309399243280453'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/5493309399243280453'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/09/size-of-sub-folders.html' title='Powershell : Find out the size of subfolders'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-4739513016539713217</id><published>2006-09-11T09:09:00.000-07:00</published><updated>2006-09-11T09:29:54.899-07:00</updated><title type='text'>System.DateTime ParseExact</title><content type='html'>ParseExact is a static method on System.DateTime class : That converts the specified string representation of Date and Time to its DateTime equivalent.&lt;br /&gt;&lt;br /&gt;the method that takes minimum agruments is&lt;br /&gt;&lt;br /&gt;public static DateTime ParseExact (string DateTimeString, string CustomDateTimeFormatString, IFormatProvider Provider)&lt;br /&gt;&lt;br /&gt;CustomDateTimeFormatString&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;d - Represents the day of the month as a number from 1 through 31.&lt;/li&gt;&lt;li&gt;dd - Represents the day of the month as a number from 01 through 31.&lt;/li&gt;&lt;li&gt;ddd -Represents the abbreviated name of the day of the week.&lt;/li&gt;&lt;li&gt;h - Represents the hour as a number from 1 through 12.&lt;/li&gt;&lt;li&gt;hh - Represents the hour as a number from 01 through 12.&lt;/li&gt;&lt;li&gt;H -Represents the hour as a number from 0 through 23.&lt;/li&gt;&lt;li&gt;HH- Represents the hour as a number from 00 through 23.&lt;/li&gt;&lt;li&gt;m - Represents the minute as a number from 0 through 59.&lt;/li&gt;&lt;li&gt;mm - Represents the minute as a number from 00 through 59. &lt;/li&gt;&lt;li&gt;M - Represents the month as a number from 1 through 12.&lt;/li&gt;&lt;li&gt;MM - Represents the month as a number from 01 through 12.&lt;/li&gt;&lt;li&gt;MMM - Represents three letter abbreviated name of the months.&lt;/li&gt;&lt;li&gt;s - Seconds from 1 -  60.&lt;/li&gt;&lt;li&gt;ss - Seconds from 01 - 60.&lt;/li&gt;&lt;li&gt;t   - Represents first character of AM or PM i.e., A or P.&lt;/li&gt;&lt;li&gt;tt  - AM or PM&lt;/li&gt;&lt;li&gt;yy - Two digit number for a year.&lt;/li&gt;&lt;li&gt;yyyy - Four digit number for a year.&lt;/li&gt;&lt;li&gt;z, zz, zzz : Represents timezone "-8","-08","-08:00" etc.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;An &lt;a onclick="javascript:TrackThisClick('ctl00_LibFrame_ctl03','ctl00_LibFrame_ctl10',this);" href="http://msdn2.microsoft.com/en-us/library/system.iformatprovider.aspx"&gt;IFormatProvider&lt;/a&gt; that supplies culture-specific format information about DateTimeString.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PS&gt; [DateTime]::ParseExact("20060908","yyyyMMdd", System.Globalization.CultureInfo]::InvariantCulture)&lt;br /&gt;&lt;br /&gt;Friday, September 08, 2006 12:00:00 AM&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-4739513016539713217?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/4739513016539713217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=4739513016539713217' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4739513016539713217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4739513016539713217'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/09/systemdatetime-parseexact.html' title='System.DateTime ParseExact'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-2956746688493950149</id><published>2006-09-07T07:41:00.000-07:00</published><updated>2007-03-28T16:24:54.480-07:00</updated><title type='text'>Changing Path using PowerShell</title><content type='html'>&lt;strong&gt;Changing Path in CMD.exe can be done by&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;PATH=%PATH%;C:\NewFolder&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Chaning path using PowerShell can be done by using Wscript.Shell object. Same set of steps can be applied using VBScript.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;$WShell = New-Object -Com Wscript.Shell&lt;br /&gt;$CurrentPath=$WShell.Environment("System").Item("Path")&lt;br /&gt;$NewPath=$CurrentPath+"C:\NewFolder"&lt;br /&gt;$WShell.Environment("System").Item("Path")=$NewPath&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;To change system path using registry can be done by accessing Session Manager's registry entry.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Using .Net API&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;[System.Environment]::SetEnvironmentVariable('PATH',"$Env:Path;$NewPath",'HostName')&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-2956746688493950149?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/2956746688493950149/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=2956746688493950149' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/2956746688493950149'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/2956746688493950149'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/09/changing-path-using-powershell.html' title='Changing Path using PowerShell'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-7770442740208942706</id><published>2006-09-04T21:52:00.000-07:00</published><updated>2008-03-05T21:49:14.267-08:00</updated><title type='text'>Range Operator</title><content type='html'>I always use range operator to generate series of # in PowerShell&lt;br /&gt;&lt;br /&gt;10..20 , it works great but I wish if PowerShell can support char ranges as well&lt;br /&gt;&lt;br /&gt;a..z okay , lets disect this&lt;br /&gt;&lt;br /&gt;first you can't give a just like this because it is a char so I tried&lt;br /&gt;'a'..'z' , so that didn't work either&lt;br /&gt;&lt;br /&gt;so releazed that since 'a' is a string not a char , it is not going to work out , and ranges only work for integer so I should do this&lt;br /&gt;&lt;br /&gt;[int]'a'..[int]'z'&lt;br /&gt;&lt;br /&gt;[int]'a'&lt;br /&gt;[char]97&lt;br /&gt;[int]'a'&lt;br /&gt;[int]('a')&lt;br /&gt;$c=[int]'a'&lt;br /&gt;$c=[int]'a'&lt;br /&gt;'a'.gettype()&lt;br /&gt;[int[]]'a'&lt;br /&gt;[int[]]'a'.tochararray()&lt;br /&gt;[int]'a'.tochararray()&lt;br /&gt;[int[]]'a'.tochararray()&lt;br /&gt;[int[]]'z'.tochararray()&lt;br /&gt;[int[]]'A'.tochararray()&lt;br /&gt;&lt;br /&gt;but it didn't work , again because 'a' is a string not a char&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PS&gt;[int]'a'&lt;br /&gt;&lt;br /&gt;Error&lt;br /&gt;&lt;br /&gt;[char[]](([int][char]'a')..([int][char]'z'))&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Other Examples from One of the post from MoW&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;PS&gt;1..7 % {(get-culture).DateTimeFormat.DayNames[($_ - 1)]}SundayMondayTuesdayWednesdayThursdayFridaySaturday&lt;br /&gt;&lt;br /&gt;PS&gt;1..12 % {(get-date "2006/$_/1").tostring('MMM')}JanFebMarAprMayJunJulAugSepOctNovDec&lt;br /&gt;&lt;br /&gt;PS&gt;1..12 % {(get-date "2006/$_/1").tostring('MMMM')}JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember&lt;br /&gt;&lt;br /&gt;PS&gt;Function get-CharRange ([char]$from,[char]$to){[char[]]([int][char]$from..[int][char]$to)}&lt;br /&gt;&lt;br /&gt;PS&gt;get-CharRange o k&lt;br /&gt;onmlk&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-7770442740208942706?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/7770442740208942706/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=7770442740208942706' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/7770442740208942706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/7770442740208942706'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/09/range-operator.html' title='Range Operator'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-6156446385541409009</id><published>2006-09-03T07:56:00.000-07:00</published><updated>2008-03-05T21:48:47.163-08:00</updated><title type='text'>Variable expasion inside double quoted string</title><content type='html'>&lt;div style="PADDING-RIGHT: 15px; PADDING-LEFT: 25px; FONT-SIZE: 70%; BACKGROUND: #dddddd; MARGIN-BOTTOM: 1em; PADDING-BOTTOM: 10px; PADDING-TOP: 10px; FONT-FAMILY: Lucida Console, Courier New"&gt;&lt;br /&gt;&lt;br /&gt;PS&gt; $MyVar="MyValue"&lt;br /&gt;PS&gt;&lt;br /&gt;PS&gt; "The value of $MyVar is $MyVar"&lt;br /&gt;The value of MyValue is MyValue&lt;br /&gt;PS&gt;&lt;br /&gt;PS&gt; "The value of `$MyVar is $MyVar"&lt;br /&gt;The value of $MyVar is MyValue&lt;br /&gt;PS&gt;&lt;br /&gt;PS&gt; "Let's make this as a file name string $MyVar.txt"&lt;br /&gt;Let's make this as a file name string MyValue.txt&lt;br /&gt;PS&gt;&lt;br /&gt;PS&gt; "Let's make this as a file name string $MyVar_Backup.txt"&lt;br /&gt;Let's make this as a file name string .txt&lt;br /&gt;PS&gt;&lt;br /&gt;&lt;br /&gt;PS&gt; "Let's make this as a file name string ${MyVar}_Backup.txt"&lt;br /&gt;Let's make this as a file name string MyValue_Backup.txt&lt;br /&gt;PS&gt;&lt;br /&gt;&lt;br /&gt;PS&gt; "The value of MyVar is $MyVar: "&lt;br /&gt;The value of MyVar is &lt;br /&gt;PS&gt;&lt;br /&gt;&lt;br /&gt;PS&gt; "The value of MyVar is ${MyVar}: "&lt;br /&gt;The value of MyVar is MyValue:&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I think it is always good to use {} for explicitly telling the shell about name of your varaibles.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-6156446385541409009?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/6156446385541409009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=6156446385541409009' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/6156446385541409009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/6156446385541409009'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/09/variable-expasion-inside-double-quoted.html' title='Variable expasion inside double quoted string'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-1802437955202446721</id><published>2006-08-31T19:57:00.000-07:00</published><updated>2008-03-05T21:38:53.860-08:00</updated><title type='text'>Creating dynamic variables</title><content type='html'>Creating dynamic variable using Invoke-Expression cmdlet&lt;br /&gt;It is just like SQL strod proc , sp_execute&lt;br /&gt;&lt;br /&gt;Foreach ($count in (1..10))&lt;br /&gt;{  &lt;br /&gt;      Invoke-Expression ('$`{var' + $count + '`} = @()')&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Another approch to create dynamic variable is using New-Variable cmdlets&lt;br /&gt;&lt;br /&gt;Foreach ($Count in (1..10))&lt;br /&gt;{ &lt;br /&gt;     New-Variable "var$Count" @()&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-1802437955202446721?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/1802437955202446721/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=1802437955202446721' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1802437955202446721'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1802437955202446721'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/creating-dynamic-variables.html' title='Creating dynamic variables'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-5628526372923741482</id><published>2006-08-31T07:22:00.000-07:00</published><updated>2008-03-05T21:38:37.433-08:00</updated><title type='text'>Discarding output  using out-null</title><content type='html'>Define a function called void , that will redirect the output of your whole block to out-null cmdlet.&lt;br /&gt;&lt;br /&gt;function void([scriptblock]$block) {   &amp;$block  out-null  }&lt;br /&gt;&lt;br /&gt;Usage :&lt;br /&gt;&lt;br /&gt;function Export-ArrayList ($Array)&lt;br /&gt;{  &lt;br /&gt;$AList= new-object Collections.ArrayList  &lt;br /&gt;void {    &lt;br /&gt;          $Array  % { $Alist.Add($_)}&lt;br /&gt;}  &lt;br /&gt;return [Collections.ArrayList]$AList&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;I realize you that you can do $Var=[Collections.ArrayList] (1,2,3) , but this is an example for suppressing the output from the function ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-5628526372923741482?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/5628526372923741482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=5628526372923741482' title='23 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/5628526372923741482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/5628526372923741482'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/discarding-output-using-out-null.html' title='Discarding output  using out-null'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>23</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-4910524834545162347</id><published>2006-08-26T11:41:00.001-07:00</published><updated>2008-03-05T21:38:28.157-08:00</updated><title type='text'>Grep and -match operator</title><content type='html'>Grep Syntax   for reading elements as a array&lt;br /&gt;&lt;br /&gt;Get-Content ReadMe.Txt  % { if ($_ -match "^(\w+).+?(\w+)$") {$matches[1]+" "+$matches[2]}  }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-4910524834545162347?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/4910524834545162347/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=4910524834545162347' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4910524834545162347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/4910524834545162347'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/grep-and-match-operator.html' title='Grep and -match operator'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-5923315272791614084</id><published>2006-08-26T11:40:00.001-07:00</published><updated>2008-03-05T21:37:51.696-08:00</updated><title type='text'>-ReadCount for batch reads</title><content type='html'>If you are reading 100 elements from file and if you want to batch it in group of 25 elements a piece&lt;br /&gt;&lt;br /&gt;PS&gt;  Get-Content ReadMe.Txt -ReadCount 10&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-5923315272791614084?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/5923315272791614084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=5923315272791614084' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/5923315272791614084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/5923315272791614084'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/readcount-for-batch-reads.html' title='-ReadCount for batch reads'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-1677332039129303263</id><published>2006-08-26T11:04:00.000-07:00</published><updated>2006-08-26T11:40:15.921-07:00</updated><title type='text'>Passing arrays through pipeline</title><content type='html'>How to pass array's through the pipeline , because if you pass the array to the pipeline using  operator , shell flattens out the array into individual elements.&lt;br /&gt;&lt;br /&gt;The same thing you see if you pass array to get-member cmdlet&lt;br /&gt;&lt;br /&gt;PS&gt; "First Item","Second Item","Third Line"   % { $_.Gettype().FullName }&lt;br /&gt;System.String&lt;br /&gt;System.String&lt;br /&gt;System.String&lt;br /&gt;&lt;br /&gt;PS&gt; "First Item","Second Item","Third Line"   Get-Member&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;It will display members for System.String class rather then System.Object[] class&lt;br /&gt;&lt;br /&gt;In Get-Member cmdlet luckily you have -InputObject switch which will give the members for System.Object[] class&lt;br /&gt;&lt;br /&gt;PS&gt; $Items="First Item","Second Item","Third Item" &lt;br /&gt;PS&gt; Get-Member -InputObject $Items&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;you can use something like this * trick *&lt;br /&gt;&lt;br /&gt;,$Items  Get-Member&lt;br /&gt;&lt;br /&gt;But now if I want to do something like this&lt;br /&gt;&lt;br /&gt;PS&gt; "First Item","Second Item","Third Item"   % { $_.Split(" ") }   % { $_[0] }&lt;br /&gt;F&lt;br /&gt;I&lt;br /&gt;S&lt;br /&gt;I&lt;br /&gt;T&lt;br /&gt;I&lt;br /&gt;&lt;br /&gt;I get the above out I would expect to see something like this &lt;br /&gt;First&lt;br /&gt;Second&lt;br /&gt;Third&lt;br /&gt;&lt;br /&gt;I got the previous output because during the first pipeline shell flattens out the array to individual elements&lt;br /&gt;&lt;br /&gt;so I could use this&lt;br /&gt;&lt;br /&gt;PS&gt; "First Item","Second Item","Third Item"   % { $_.Split(" ")[0] }&lt;br /&gt;&lt;br /&gt;but what if you want to pass these elements as a array for second pipeline.&lt;br /&gt;&lt;br /&gt;PS&gt; "First Item","Second Item","Third Item"   % { ,($_.Split(" "))}   % { $_[0] }&lt;br /&gt;&lt;br /&gt;If you want to get only first and last elements you could use&lt;br /&gt;&lt;br /&gt;PS&gt; "First Item","Second Item","Third Item"   Select-Object -First 2  % { ,($_.Split(" "))}   % { $_[0] }&lt;br /&gt;&lt;br /&gt;PS&gt; "First Item","Second Item","Third Item"   Select-Object -Last 2  % { ,($_.Split(" "))}   % { $_[0] }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-1677332039129303263?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/1677332039129303263/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=1677332039129303263' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1677332039129303263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/1677332039129303263'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/passing-arrays-through-pipeline.html' title='Passing arrays through pipeline'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-7199760413358703224</id><published>2006-08-26T08:35:00.000-07:00</published><updated>2006-08-26T09:28:57.961-07:00</updated><title type='text'>Rename-Item Cmdlet vs cmd.exe ren command</title><content type='html'>if you are trying to rename multiple files using cmd.exe that uses wildcard like (* , ? ) , it is really easy to do&lt;br /&gt;&lt;br /&gt;C:\&gt; dir file?.txt /b&lt;br /&gt;&lt;br /&gt;file1.txt&lt;br /&gt;file2.txt&lt;br /&gt;&lt;br /&gt;C:\&gt;ren file?.txt file?_old.txt&lt;br /&gt;C:\&gt;dir file*.txt&lt;br /&gt;&lt;br /&gt;file1_old.txt&lt;br /&gt;file2_old.txt&lt;br /&gt;&lt;br /&gt;but if you try the same syntax in PowerShell it won't work.&lt;br /&gt;&lt;br /&gt;My first stab is to split the filename using string split method and constructing the new filename string.&lt;br /&gt;&lt;br /&gt;PS &gt; dir file?.txt  % { ren $_.Name $($_.Name.split(".")[0]+"_old."+$_.Name.split(".")[1]) }&lt;br /&gt;&lt;br /&gt;lesson learned&lt;br /&gt;&lt;br /&gt;The Rename-Item has a -newname switch  and if you passing the objects through pipeline  , then you don't have to give old name and you can pass code block using { }&lt;br /&gt;&lt;br /&gt;PS &gt; dir file?.txt  ren -newname { ($_.Name.split(".")[0]+"_old."+$_.Name.split(".")[1] }&lt;br /&gt;&lt;br /&gt;or you can be more elegant using -replace operator&lt;br /&gt;&lt;br /&gt;PS&gt; dir file?.txt  ren -newname { $_.Name -replace "\.txt","_old.txt" }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;NOTE: if you are using above syntax since you are passing objects from one cmdlet to another cmdlet you don't have to worry about iterating in a loop using foreach-object/ {%}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-7199760413358703224?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/7199760413358703224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=7199760413358703224' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/7199760413358703224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/7199760413358703224'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/rename-item-cmdlet-vs-cmdexe-ren.html' title='Rename-Item Cmdlet vs cmd.exe ren command'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-8054519635439765897</id><published>2006-08-25T23:35:00.000-07:00</published><updated>2006-08-25T23:44:44.872-07:00</updated><title type='text'>Creating PSCustomObject using Select-Object</title><content type='html'>Pass any value to Select-Object CmdLet and specify the name of properties&lt;br /&gt;&lt;br /&gt;PS&gt; ""  Select-Object Name,IPAddress&lt;br /&gt;Name        IPAddress&lt;br /&gt;-------      -------------&lt;br /&gt;&lt;br /&gt;PS&gt; $Server=""  Select-Object Name,IPAddress&lt;br /&gt;&lt;br /&gt;PS&gt;$Server.Name="MyServer"&lt;br /&gt;PS&gt;$Server.IPAddress="164.140.1.45"&lt;br /&gt;&lt;br /&gt;PS&gt;$Server&lt;br /&gt;Name               IPAddress&lt;br /&gt;-------             -------------&lt;br /&gt;MyServer       164.140.1.45&lt;br /&gt;&lt;br /&gt;PS&gt;$Server.GetType()&lt;br /&gt;IsPublic IsSerial Name                                    BaseType&lt;br /&gt;-------- -------- ----                                        --------&lt;br /&gt;True      False      PSCustomObject                 System.Object&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-8054519635439765897?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/8054519635439765897/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=8054519635439765897' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8054519635439765897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8054519635439765897'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/creating-pscustomobject-using-select.html' title='Creating PSCustomObject using Select-Object'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-8419994188858304520</id><published>2006-08-25T23:13:00.000-07:00</published><updated>2006-08-25T23:29:21.730-07:00</updated><title type='text'>Suppressing the output using out-null and [void]</title><content type='html'>If you create a object of class ArrayList and try to add elements to the Arraylist using .Add method , it will output the index number on the screen which is kind of annoying.&lt;br /&gt;&lt;br /&gt;PS&gt; $oArray=new-object Collections.ArrayList&lt;br /&gt;PS&gt; $oArray.Add("100")&lt;br /&gt;0&lt;br /&gt;PS&gt; $oArray.Add(10)&lt;br /&gt;1&lt;br /&gt;PS&gt; $oArray&lt;br /&gt;100&lt;br /&gt;10&lt;br /&gt;PS&gt;&lt;br /&gt;&lt;br /&gt;You can discard the output either using [void] type casting&lt;br /&gt;&lt;br /&gt;PS&gt; [void]$oArray.Add(10)&lt;br /&gt;PS&gt; [void]$oArray.Add(20)&lt;br /&gt;PS&gt; $oArray&lt;br /&gt;100&lt;br /&gt;10&lt;br /&gt;10&lt;br /&gt;20&lt;br /&gt;PS&gt;&lt;br /&gt;&lt;br /&gt;or if you using these statements in PowerShell function and script you can use out-null&lt;br /&gt;&lt;br /&gt;PS&gt;&amp; {&lt;br /&gt;$oArray.Add(3)&lt;br /&gt;$oArray.Add(4)&lt;br /&gt;}  out-null&lt;br /&gt;&lt;br /&gt;PS&gt; $oArray&lt;br /&gt;100&lt;br /&gt;10&lt;br /&gt;10&lt;br /&gt;20&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;&lt;br /&gt;or you can use old fashioned (cmd.exe) like $null&lt;br /&gt;&lt;br /&gt;PS&gt; $oArray.Add(5) &gt; $null&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-8419994188858304520?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/8419994188858304520/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=8419994188858304520' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8419994188858304520'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/8419994188858304520'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/suppressing-output-using-out-null-and.html' title='Suppressing the output using out-null and [void]'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115611607972650031</id><published>2006-08-20T13:25:00.000-07:00</published><updated>2006-08-20T16:23:42.006-07:00</updated><title type='text'>File redirection (&gt; and &lt;)  vs Add-Content and Get-Content</title><content type='html'>Documenting thread from Microsoft.Public.Windows.PowerShell&lt;br /&gt;&lt;br /&gt;Contributors : Keith Hill, Mow and Sung M Kim&lt;br /&gt;&lt;br /&gt;Cmdlet used : Get-Content, Add-Content, Measure-Command and Compare-Object&lt;br /&gt;&lt;br /&gt;PS &gt; Get-Content $Env:SystemRoot\twain.dll &gt; xyz.dll&lt;br /&gt;&lt;br /&gt;# this will just read the ASCII values from source file and write it to destination file. But if you look at the destination filesize it is quite large then target file.&lt;br /&gt;&lt;br /&gt;PS &gt; Get-Content $Env:SystemRoot\twain.dll -Encoding Byte &gt; xyz.dll&lt;br /&gt;&lt;br /&gt;# The above statement specifies the encoding for the source file , but if you open the target file in notepad , you will see series of # ( Byte representation of source file)&lt;br /&gt;&lt;br /&gt;The problem can be solved by using Add-Content command let , which also supports encoding switch&lt;br /&gt;&lt;br /&gt;PS&gt; Get-Content $Env:SystemRoot\twain.dll -Encoding Byte Add-Content xyz.dll -Encoding byte&lt;br /&gt;&lt;br /&gt;PS&gt; Compare-Object $Env:SystemRoot\twain.dll xyz.dll&lt;br /&gt;&lt;br /&gt;If you compare these files using Compare-Object cmdlet you will see that there is no different in files except the filename and filepath&lt;br /&gt;&lt;br /&gt;But one thing you will notice here that this reading and writing takes lot of time , and if you real wants to look at numbers , you can use Measure-Command cmdlet to accomplish this.&lt;br /&gt;&lt;br /&gt;PS&gt; Measure-Command { Get-Content $Env:SystemRoot\twain.dll -Encoding Byte Add-Content xyz.dll -Encoding byte }&lt;br /&gt;&lt;br /&gt;Days : 0&lt;br /&gt;Hours : 0&lt;br /&gt;Minutes : 0&lt;br /&gt;Seconds : 27&lt;br /&gt;Milliseconds : 464&lt;br /&gt;&lt;br /&gt;If you want speed this up use can use -ReadCount switch with Get-Content , so it will read one block at a time , rather than one Byte at a time.&lt;br /&gt;&lt;br /&gt;PS&gt; Measure-Command { Get-Content $Env:SystemRoot\twain.dll -Encoding Byte -ReadCount 512 Add-Content xyz.dll -Encoding byte}&lt;br /&gt;&lt;br /&gt;Days : 0&lt;br /&gt;Hours : 0&lt;br /&gt;Minutes : 0&lt;br /&gt;Seconds : 0&lt;br /&gt;Milliseconds : 128&lt;br /&gt;&lt;br /&gt;OR&lt;br /&gt;&lt;br /&gt;if you want to use .Net to accomplish the same this use can use the following&lt;br /&gt;&lt;br /&gt;PS &gt; $FileBytes = [System.IO.File]::ReadAllBytes("$env:SystemLocation\twain.dll")&lt;br /&gt;PS &gt; [System.IO.File]::WriteAllBytes("$pwd\twain.dll",$FileBytes)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115611607972650031?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115611607972650031/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115611607972650031' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115611607972650031'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115611607972650031'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/file-redirection-and-vs-add-content.html' title='File redirection (&gt; and &lt;)  vs Add-Content and Get-Content'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115593426694595986</id><published>2006-08-18T13:28:00.000-07:00</published><updated>2007-07-13T19:58:00.755-07:00</updated><title type='text'>Useful .Net classes and methods (static)</title><content type='html'>&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Get All the month names&lt;/span&gt;&lt;br /&gt;PS &gt; 1..12 % { [Globalization.DatetimeFormatInfo]::CurrentInfo.MonthNames[$_-1] }&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Get Framework Location&lt;/span&gt;&lt;br /&gt;PS &gt; $FWDir=[Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()&lt;br /&gt;So you can call csc.exe&lt;br /&gt;PS &gt; &amp; "$FWDir\csc" ComplieMe.cs&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Get all loaded Assemblies&lt;/span&gt;&lt;br /&gt;[AppDomain]::CurrentDomain.GetAssemblies()&lt;br /&gt;Ngen'g PowerShell assemblies&lt;br /&gt;PS &gt; dir *.dll % { &amp;amp; "$FWDir\ngen" $_ }&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Loading assembly from dll&lt;/span&gt;&lt;br /&gt;PS &gt; [Reflection.Assembly]::LoadFrom("$pwd\LoadMe.dll")&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Loading assembly from GAC&lt;br /&gt;&lt;/span&gt;PS &gt; [System.Reflection.Assembly]::LoadWithPartialName("System.Data") &lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Check file version&lt;/span&gt;&lt;/p&gt;&lt;p&gt;[System.Diagnostics.FileVersionInfo]::GetVersionInfo("$pshome\powershell.exe")&lt;/p&gt;&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Read and Write File Bytes&lt;/span&gt;&lt;/p&gt;&lt;p&gt;PS &gt; $FileBytes = [System.IO.File]::ReadAllBytes("$env:SystemLocation\twain.dll") &lt;/p&gt;&lt;p&gt;PS &gt; [System.IO.File]::WriteAllBytes("$pwd\twain.dll",$FileBytes)&lt;/p&gt;&lt;p&gt;Read Text from the file [ as a string , not as array of objects .i.e., Get-Content )&lt;/p&gt;&lt;p&gt;PS&gt; [System.IO.File]::ReadAllText("Web.Config")&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115593426694595986?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115593426694595986/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115593426694595986' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115593426694595986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115593426694595986'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/net-useful-classes-and-methods-static.html' title='Useful .Net classes and methods (static)'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115592529180253002</id><published>2006-08-18T11:14:00.000-07:00</published><updated>2006-08-18T11:21:31.810-07:00</updated><title type='text'>Whoami /all</title><content type='html'>I always liked whoami /all command to lookup what all groups I belong to , the only thing I hated about the command is that it is not built in command (doesn't work on XP) ..so I thought lets try same thing in powershell and I was amazed so see that I can do this in just two lines , so if I want to pipe it further it can be done in one line.&lt;br /&gt;&lt;br /&gt;PS [~]&gt; $myId=[System.Security.Principal.WindowsIdentity]::GetCurrent()&lt;br /&gt;PS [~]&gt; $myId | % { $_.Translate([System.Security.Principal.NTAccount])}&lt;br /&gt;&lt;br /&gt;or &lt;br /&gt;&lt;br /&gt;PS [~]&gt; ([System.Security.Principal.WindowsIdentity]::GetCurrent()).Groups | % { $_.Translate([System.Security.Principal.NTAccount])}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115592529180253002?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115592529180253002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115592529180253002' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115592529180253002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115592529180253002'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/whoami-all.html' title='Whoami /all'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115562557704602826</id><published>2006-08-15T00:06:00.000-07:00</published><updated>2006-08-15T12:38:05.640-07:00</updated><title type='text'>Invoke-vbs.ps1</title><content type='html'>function invoke-vbs {&lt;br /&gt;param([string] $vbsBlock)&lt;br /&gt;$r=new-object Random&lt;br /&gt;$filename=(1..8 | % {$f=""}{ $f+=[char]$r.Next(97,(97+25))} {"{0}\~{1}.vbs" -f $env:temp,$f})&lt;br /&gt;if ($vbsBlock.Length -gt 1) &lt;br /&gt;{&lt;br /&gt; "'vbs temp file" | out-file $filename&lt;br /&gt; if ($vbsBlock.IndexOfAny(';') -gt 0)&lt;br /&gt; {&lt;br /&gt;  foreach($vbsStatement in $vbsBlock.split(';'))&lt;br /&gt;  {&lt;br /&gt;   $vbsStatement | out-file $filename -append &lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; else&lt;br /&gt; {&lt;br /&gt;  $vbsBlock | out-file $filename -append&lt;br /&gt; }&lt;br /&gt; Write-host "Executing Vbs ..."&lt;br /&gt; cscript //nologo $filename&lt;br /&gt; remove-item $filename&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115562557704602826?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115562557704602826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115562557704602826' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115562557704602826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115562557704602826'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/invoke-vbsps1.html' title='Invoke-vbs.ps1'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115560885051998402</id><published>2006-08-14T19:26:00.000-07:00</published><updated>2006-08-14T19:28:49.253-07:00</updated><title type='text'>One liner for random filename generation</title><content type='html'>PS&gt; 1..8 %  {$f=""}{ $f+=[char]$r.Next(97,(97+25))} {"~{0}\{1}.vbs" -f $env:temp,$f}&lt;br /&gt;&lt;br /&gt;C:\DOCUME~1\XXX\LOCALS~1\Temp\~xjsjmnef.vbs&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115560885051998402?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115560885051998402/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115560885051998402' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115560885051998402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115560885051998402'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/one-liner-for-random-filename.html' title='One liner for random filename generation'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115559287798904649</id><published>2006-08-14T15:01:00.000-07:00</published><updated>2006-08-14T15:16:16.683-07:00</updated><title type='text'>PowerShell Profile</title><content type='html'>&lt;span style="font-family:Georgia;font-size:85%;"&gt;Since the name and path of PowerShell profile is hard to remember, I always had to do google search to find&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What is the location for PowerShell Profile?&lt;br /&gt;&gt;"$env:userprofile\PSConfiguration"&lt;br /&gt;What is the filename for PowerShell profile?&lt;br /&gt;&gt;"$($shellid)_Profile.ps1"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I found a easy way to do it. $Profle is a PowerShell built in variable which is available even if you don't have default Profile&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&gt;dir variable: ? { $_.Name -like "*Pro*" }&lt;br /&gt;or&lt;br /&gt;&gt;dir variable:*Pro*&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;but you can't do this&lt;br /&gt;&lt;br /&gt;&gt;dir variable: -filter *Pro*&lt;br /&gt;(ERROR: because Variable provide doesn't support filtering)&lt;br /&gt;&lt;br /&gt;** How to create a new profile **&lt;br /&gt;&lt;br /&gt;&gt; if ( test-path (split-path $profile)) { mkdir (split-path $profile) }&lt;br /&gt;&gt; if ( test-path $profile ) { new-item –type file –name (split-path $profile –leaf)) –value “#Profile” }&lt;br /&gt;&lt;br /&gt;If you wish there would be two variables like $profilepath and $profilename then above command will be more easier to type &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Georgia;font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Georgia;font-size:85%;"&gt;.. not a problem with PowerShell , you can make 'em using one-line&lt;br /&gt;&lt;br /&gt;&gt; ($profilepath,$profilename)=“$null”,”-leaf” % { invoke-expression “split-path ‘$profile’ $_” }&lt;br /&gt;&lt;br /&gt;&gt; $profilepath&lt;br /&gt;Documents and Settings\XXX\My Documents\PSConfiguration&lt;br /&gt;&lt;br /&gt;&gt; $profilename&lt;br /&gt;Microsoft.PowerShell_profile.ps1&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Georgia;font-size:85%;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115559287798904649?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115559287798904649/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115559287798904649' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115559287798904649'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115559287798904649'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/powershell-profile_14.html' title='PowerShell Profile'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115490317807142929</id><published>2006-08-06T13:57:00.000-07:00</published><updated>2006-08-06T23:52:39.623-07:00</updated><title type='text'>PowerShell Prompt Part 2</title><content type='html'>In PowerShell prompt is a function&lt;br /&gt;$dir function:&lt;br /&gt;&lt;br /&gt;CommandType Name Definition&lt;br /&gt;----------- ---- ----------&lt;br /&gt;&lt;b&gt;Function prompt $&lt;/b&gt;&lt;br /&gt;Function TabExpansion ...&lt;br /&gt;Function Clear-Host $spaceType&lt;br /&gt;Function more param([string[]]$paths);&lt;br /&gt;Function help param([string]$help);&lt;br /&gt;Function man param([string]$help);&lt;br /&gt;Function mkdir param([string[]]$paths);&lt;br /&gt;Function md param([string[]]$paths);&lt;br /&gt;&lt;br /&gt;Simple prompt in PowerShell&lt;br /&gt;&lt;br /&gt;function prompt { "$"}&lt;br /&gt;&lt;br /&gt;CMD equivalent: PROMPT $$&lt;br /&gt;&lt;br /&gt;Bash equivalent: PS1="$"&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;Most common prompt which displays your current working directory&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;function prompt { "$(get-location)&gt; " }&lt;br /&gt;&lt;br /&gt;CMD : PROMPT $P$G&lt;br /&gt;&lt;br /&gt;Bash : PS1='\w$' or PS1='`pwd`'&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;Another prompt to display current working directory ( not the full path ) &lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;function prompt { "$(split-path $(get-locaiton) -leaf)&gt; "&lt;br /&gt;&lt;br /&gt;CMD : ????&lt;br /&gt;&lt;br /&gt;Bash : PS1='\W $'&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;Prompt with linefeed character &lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;function prompt { "$(get-location)`n&gt; "}&lt;br /&gt;&lt;br /&gt;CMD : $P$_$G&lt;br /&gt;&lt;br /&gt;Bash : PS1='\w\n&gt;'&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;Prompt with DateTime &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;function prompt { "$(get-date)&gt;"}&lt;br /&gt;&lt;br /&gt;CMD : $T$G&lt;br /&gt;&lt;br /&gt;Bash : PS1='\t&gt;'&lt;br /&gt;&lt;br /&gt;Bash has four special codes for representing datetime prompt string&lt;br /&gt;&lt;br /&gt;\t : 17:05:05&lt;br /&gt;\T : 05:05:05&lt;br /&gt;\@ : 05:05 PM&lt;br /&gt;\d : Sun Aug, 06&lt;br /&gt;&lt;br /&gt;Let's do samething in powershell&lt;br /&gt;&lt;br /&gt;"$($(get-date).tostring('HH:MM:s'))" ==&gt; 17:05:05&lt;br /&gt;&lt;br /&gt;"$($(get-date).tostring('hh:MM:s'))" ==&gt; 05:05:05&lt;br /&gt;&lt;br /&gt;"$($(get-date).tostring('hh:MM tt'))" ==&gt; 05:05 PM&lt;br /&gt;&lt;br /&gt;"$($(get-date).tostring('ddd MMM, dd'))" ==&gt; Sun Aug, 06&lt;br /&gt;&lt;br /&gt;&lt;span style="color:red;"&gt;&lt;b&gt;&lt;i&gt;Prompt with Hostname &lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;function prompt { "$env:computername &gt; "}&lt;br /&gt;&lt;br /&gt;CMD: prompt %computername%$G&lt;br /&gt;&lt;br /&gt;Bash : PS1='\h&gt;'&lt;br /&gt;&lt;br /&gt;NOTE: Bash also offers \H which will give you the complete hostname in the domain, you can mimic the same thing in powershell using following prompt&lt;br /&gt;&lt;br /&gt;function prompt { "$([System.Net.Dns]::GetHostByName([System.Net.Dns]::GetHostName()).hostname) &gt;" }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:red;"&gt;&lt;b&gt;&lt;i&gt;Prompt with Username &lt;/span&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;function prompt { "$env:username &gt; "}&lt;br /&gt;&lt;br /&gt;CMD: prompt %username%$G&lt;br /&gt;&lt;br /&gt;Bash : PS1='\u&gt;'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115490317807142929?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115490317807142929/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115490317807142929' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115490317807142929'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115490317807142929'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/powershell-prompt-part-2.html' title='PowerShell Prompt Part 2'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115484042002340301</id><published>2006-08-05T21:55:00.000-07:00</published><updated>2006-08-14T22:53:06.533-07:00</updated><title type='text'>Shell Prompt</title><content type='html'>Shell Prompt&lt;br /&gt;&lt;br /&gt;Most of the interactive shell has an environment variable to set it's shell prompt unlike PowerShell , where prompt is a function , whatever string you return and/or write-host from that function will be used as PowerShell prompt.&lt;br /&gt;&lt;br /&gt;for example&lt;br /&gt;&lt;br /&gt;Command.com ( Pre-WinNT) / Cmd.exe&lt;br /&gt;Name of environment variable is : PROMPT&lt;br /&gt;.........&lt;br /&gt;.........&lt;br /&gt;PROCESSOR_LEVEL=15&lt;br /&gt;PROCESSOR_REVISION=0401&lt;br /&gt;ProgramData=V:\ProgramData&lt;br /&gt;ProgramFiles=V:\Program Files&lt;br /&gt;PROMPT=$P$G&lt;br /&gt;PUBLIC=V:\Users\Public&lt;br /&gt;.........&lt;br /&gt;.........&lt;br /&gt;&lt;br /&gt;Windows Cmd.exe PROMPT Codes&lt;br /&gt;&lt;br /&gt;$A &amp;amp; (Ampersand)&lt;br /&gt;$B (pipe)&lt;br /&gt;$C ( (Left parenthesis)&lt;br /&gt;$F ) (Right parenthesis)&lt;br /&gt;$G &gt; (greater-than sign)&lt;br /&gt;$L &lt; (less-than sign) &lt;br /&gt;$Q = (equal sign) &lt;br /&gt;$S (space)   Charcters that are not on the keyboard   &lt;br /&gt;$E Escape code (ASCII code 27) &lt;br /&gt;$H Backspace (erases previous character) &lt;br /&gt;$_ Carriage return and linefeed&lt;br /&gt;$$ $ (dollar sign) and special code to represent commands  &lt;br /&gt;$D Current date  &lt;br /&gt;$N Current drive  &lt;br /&gt;$P Current drive and path  &lt;br /&gt;$T Current time  &lt;br /&gt;$V Windows version number   &lt;br /&gt;Advance codes to represents   &lt;br /&gt;$+ PUSHD directory stack  &lt;br /&gt;$M Remote name associated with the current drive    &lt;br /&gt;&lt;br /&gt;In Unix , if you use set command it will display all exported shell variables. PSX = PS1,PS2 etc , is used to set your primary and secondary shell prompt  ..................  &lt;br /&gt;..................  &lt;br /&gt;OPTIND=1  &lt;br /&gt;OSTYPE=darwin8.0  &lt;br /&gt;PATH=/bin:/sbin:/usr/bin:/usr/sbin  &lt;br /&gt;PIPESTATUS=([0]="0")  &lt;br /&gt;PPID=1630  &lt;br /&gt;PS1='\h:\w \u\$ '  &lt;br /&gt;PS2='&gt; '&lt;br /&gt;PS4='+ '&lt;br /&gt;SECURITYSESSIONID=a8ec70&lt;br /&gt;SHELL=/bin/bash&lt;br /&gt;....................&lt;br /&gt;....................&lt;br /&gt;&lt;br /&gt;Unix PS1 codes:&lt;br /&gt;&lt;br /&gt;\n newline&lt;br /&gt;\r carriage return&lt;br /&gt;\a an ASCII bell character (07)&lt;br /&gt;\e an ASCII escape character (033)&lt;br /&gt;\nnn the character corresponding to the octal number "nnn"&lt;br /&gt;\\ a backslash&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;\t the current time in 24_hour HH:MM:SS format&lt;br /&gt;\T the current time in 12_hour HH:MM:SS format&lt;br /&gt;\@ the current time in 12_hour am/pm format&lt;br /&gt;\d the date in "Weekday Month Date" format (e.g., "Tue May 26")&lt;br /&gt;&lt;br /&gt;\u the username of the current user&lt;br /&gt;\h the hostname up to the first `.'&lt;br /&gt;\H the hostname&lt;br /&gt;\w the current working directory&lt;br /&gt;\W the basename of the current working directory&lt;br /&gt;\$ if the effective UID is 0, a #, otherwise a $&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;\s the name of the shell, the basename of $0 (the portion following the final slash)&lt;br /&gt;\v the version of bash (e.g., 2.00)&lt;br /&gt;\V the release of bash, version + patchlevel (e.g., 2.00.0)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;\! the history number of this command&lt;br /&gt;\# the command number of this command&lt;br /&gt;&lt;br /&gt;\[ begin a sequence of non_printing characters&lt;br /&gt;\] end a sequence of non_printing characters&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115484042002340301?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115484042002340301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115484042002340301' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115484042002340301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115484042002340301'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/08/shell-prompt.html' title='Shell Prompt'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115437992429255014</id><published>2006-07-31T13:45:00.000-07:00</published><updated>2006-08-03T22:23:47.350-07:00</updated><title type='text'>Writing Windows events using PowerShell</title><content type='html'>Four lines of code to directly write to Windows EventLog , which is far far better then Windows built in native EVENTCREATE.EXE ( which will only let you choose event # between 1 -1000 ) and WshShell.LogEvent ( which won't let you even choose event # and source .. so lame )&lt;br /&gt;&lt;br /&gt;&gt;$evt=new-object System.Diagnostics.EventLog("Application")&lt;br /&gt;&gt;$evt.Source="MyEvent"&lt;br /&gt;&gt;$infoevent=[System.Diagnostics.EventLogEntryType]::Information&lt;br /&gt;&gt;$evt.WriteEntry("My Test Event",$infoevent,70)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here's step by step process&lt;br /&gt;&lt;br /&gt;&gt; new-object System.Diagnostics.EventLog("Application")&lt;br /&gt;Max(K) Retain OverflowAction Entries Name&lt;br /&gt;------ ------ -------------- ------- ----&lt;br /&gt;20,032 0 OverwriteAsNeeded 23,614 Application&lt;br /&gt;&lt;br /&gt;&gt;# The above line will tell you useful information about What is the Max size of eventlog and # of entries in the log at the time you created the object etc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# Store the result in $evt Object so it can be used later on for writing to the event log&lt;br /&gt;&lt;br /&gt;&gt;$evt=new-object System.Diagnostics.EventLog("Application")&lt;br /&gt;&lt;br /&gt;# Now I have figure out what method to use to write to eventlog ( Here's our friend cmdlet Get-Member will come in handy )&lt;br /&gt;&lt;br /&gt;&gt;$evt gm -member Method&lt;br /&gt;&lt;br /&gt;# Now let me figure out what is the prototypes of WriteEntry methods&lt;br /&gt;&lt;br /&gt;&gt;$evt.WriteEntry&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# If just want overloads and their prototypes then use this&lt;br /&gt;&lt;br /&gt;&gt;($evt.WriteEntry).OverloadDefinitions&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;System.Void WriteEntry(String message)&lt;br /&gt;System.Void WriteEntry(String message, EventLogEntryType type)&lt;br /&gt;System.Void WriteEntry(String message, EventLogEntryType type, Int32 eventID)System.Void WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category)&lt;br /&gt;System.Void WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)&lt;br /&gt;&lt;br /&gt;##### SWEEEEEEEEEEETTTTTTTTTT ############ Look ma no Visual Studio installed :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now I want to use following overload for this method&lt;br /&gt;&lt;br /&gt;System.Void WriteEntry(String message, EventLogEntryType type, Int32 eventID)&lt;br /&gt;&lt;br /&gt;but don't know what are the Enumerations for EventLogEntryType , then use&lt;br /&gt;&lt;br /&gt;&gt; [Enum]::GetValues([System.Diagnostics.EventLogEntryType])&lt;br /&gt;&lt;br /&gt;Error&lt;br /&gt;Warning&lt;br /&gt;Information&lt;br /&gt;SuccessAudit&lt;br /&gt;FailureAudit&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Cool !!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115437992429255014?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115437992429255014/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115437992429255014' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115437992429255014'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115437992429255014'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/07/writing-windows-events-using.html' title='Writing Windows events using PowerShell'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115436903160402957</id><published>2006-07-31T10:52:00.000-07:00</published><updated>2006-07-31T11:16:02.560-07:00</updated><title type='text'>Spell Checker in PowerShell</title><content type='html'>Here's what I tried with Office 11 and PowerShell&lt;br /&gt;&lt;br /&gt;Two methods to check your spellings on PowerShell Command line&lt;br /&gt;&lt;br /&gt;$oWord=new-object -COM Word.Application&lt;br /&gt;&lt;br /&gt;&gt;$oWord.CheckSpelling("Check my spelling")&lt;br /&gt;True&lt;br /&gt;&lt;br /&gt;&gt;$oWord.CheckSpelling("Check my speelling")&lt;br /&gt;&lt;br /&gt;False&lt;br /&gt;&lt;br /&gt;What if you want to get suggestions for your wrong spelling ( Now this is freaking cool)&lt;br /&gt;&lt;br /&gt;&gt;$oWord.GetSpellingSuggestions("speell")&lt;br /&gt;&lt;br /&gt;Yeah , the above command won't work because for some reason you need to create Document just to GetSpellingSuggestions method.&lt;br /&gt;&lt;br /&gt;So just to make Word APIs happy&lt;br /&gt;&lt;br /&gt;&gt;[void]$oWord.Documents.Add()&lt;br /&gt;## Word is now happy to give you its suggestions&lt;br /&gt;&lt;br /&gt;&gt;$oWord.GetSpellingSuggestions("speell")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Application Creator Parent Name&lt;br /&gt;----------- ------- ------ ----&lt;br /&gt;System.__ComObject 1297307460 {spell, spiel, spells, spill} spell&lt;br /&gt;System.__ComObject 1297307460 {spell, spiel, spells, spill} spiel&lt;br /&gt;System.__ComObject 1297307460 {spell, spiel, spells, spill} spells&lt;br /&gt;System.__ComObject 1297307460 {spell, spiel, spells, spill} spill&lt;br /&gt;&lt;br /&gt;&gt;$oWord.GetSpellingSuggestions("speell") % { $_.Name}&lt;br /&gt;&lt;br /&gt;spell&lt;br /&gt;spiel&lt;br /&gt;spells&lt;br /&gt;spill&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Freaking cool .. Can someone please extend this to read the input of Messenger or Notepad and SpellCheck it :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;While doing this I found something interesting too. I was trying to call same APIs for Office 12 , but seems like it needs all 14 parameters for GetSpellingSuggestions method. So I just wanted to compare the arguments but PowerShell gives you the function definition in one line&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;MemberType : Method&lt;br /&gt;OverloadDefinitions : {SpellingSuggestions GetSpellingSuggestions (string, Variant, Variant, Variant, Variant, Variant,&lt;br /&gt;Variant, Variant, Variant, Variant, Variant, Variant, Variant, Variant)}&lt;br /&gt;TypeNameOfValue : System.Management.Automation.PSMethod&lt;br /&gt;Value : SpellingSuggestions GetSpellingSuggestions (string, Variant, Variant, Variant, Variant, Variant,&lt;br /&gt;Variant, Variant, Variant, Variant, Variant, Variant, Variant, Variant)&lt;br /&gt;Name : GetSpellingSuggestions&lt;br /&gt;IsInstance : True&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Which is pretty ugly to read , so I did this&lt;br /&gt;&lt;br /&gt;&gt; ($oWord.GetSpellingSuggestions).OverloadDefinitions[0].split(",")&lt;br /&gt;SpellingSuggestions GetSpellingSuggestions (string&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant&lt;br /&gt;Variant)&lt;br /&gt;&gt;&lt;br /&gt;&lt;br /&gt;Moral of the story is : POWERSHELL Rocks !!!!!!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115436903160402957?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115436903160402957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115436903160402957' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115436903160402957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115436903160402957'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/07/spell-checker-in-powershell.html' title='Spell Checker in PowerShell'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115432495174836163</id><published>2006-07-30T22:47:00.000-07:00</published><updated>2006-07-30T22:49:11.756-07:00</updated><title type='text'>Why PowerShell?  Why not C#?</title><content type='html'>First of all C# is not a scripting language it is strictly typed full fledge language (Yeah, it is easier to write application code in C# rather than writing in C or in C++ or for that matter in COBOL :)) .&lt;br /&gt;&lt;br /&gt;If you really want to write some piece of code in C#, you need intellisense IDE (like Visual Studio). Now if you consider a system administrator managing 10,000+ web servers, he/she will never install 2 gigabytes of Visual Studio on every server to edit his C# utility.&lt;br /&gt;&lt;br /&gt;If you have any utility that you are running on production system and want to make some minor changes then you need to go back to your desktop where you have your source code preferably Visual Studio installed, edit your C# program, recompile it and copy it back to production system.  If you consider complex and disciplined production environments with strict change control polices, then it would take a while before you can execute your code on production.&lt;br /&gt;&lt;br /&gt;C# is case sensitive complex language with hundreds of assembly and thousands of classes (whereas PoSH is case insensitive with only 128 cmdlets).  Now don’t tell me that I can write code in Notepad and compile using CSC.&lt;br /&gt;&lt;br /&gt;If you really want to write actual code in C#, you need to have some knowledge of OOPs (object oriented programming) concept (how to define class? what are static methods?), even if you are writing a simple program you need to write at least main method whose definition is &lt;public&gt;  now if you need to understand  what does public mean? What are class access rules, why to make this function public, and then comes static? What does that mean? How it is different from instance methods? Why return type is void etc.)&lt;br /&gt;&lt;br /&gt;Feel free to correct me and add more reasons.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115432495174836163?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115432495174836163/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115432495174836163' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115432495174836163'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115432495174836163'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/07/why-powershell-why-not-c.html' title='Why PowerShell?  Why not C#?'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115406222832414369</id><published>2006-07-27T21:45:00.000-07:00</published><updated>2006-07-27T23:17:39.416-07:00</updated><title type='text'>I love [System.Enum]::GetValues</title><content type='html'>This is the one of the coolest feature of PowerShell that you can use [System.Enum]::GetValues or [System.Enum]::GetNames to enumerate the .Net Enumerations&lt;br /&gt;&lt;br /&gt;Here's the example&lt;br /&gt;&lt;br /&gt;[System.Enum]::GetValues([System.Diagnostics.EventLogEntryType])&lt;br /&gt;&lt;br /&gt;Error&lt;br /&gt;Warning&lt;br /&gt;Information&lt;br /&gt;Success&lt;br /&gt;Audit&lt;br /&gt;Failure&lt;br /&gt;Audit&lt;br /&gt;&lt;br /&gt;You can always remove System from above command to make it shorter&lt;br /&gt;&lt;br /&gt;[Enum]::GetValues([Diagnostics.EventLogEntryType])&lt;br /&gt;&lt;br /&gt;I assume PS trys to search class in System Namespace&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115406222832414369?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115406222832414369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115406222832414369' title='26 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115406222832414369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115406222832414369'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/07/i-love-systemenumgetvalues.html' title='I love [System.Enum]::GetValues'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>26</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115364274513577768</id><published>2006-07-23T01:14:00.000-07:00</published><updated>2006-08-18T09:37:12.093-07:00</updated><title type='text'>Edit function : PowerShell</title><content type='html'>Yesterday I was writing functions in PowerShell and it was getting very annoying to see that you can’t edit your functions in PoSH. So I thought let me write my own function that will spawn an editor of your choice and read your function text into that.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;function global:ed-fn&lt;br /&gt;{&lt;br /&gt;param($fnName) if ($env:editor -eq $null)&lt;br /&gt;{&lt;br /&gt;$env:editor="notepad"&lt;br /&gt;}&lt;br /&gt;$fnDir=dir function:$fnName -ErrorAction SilentlyContinue&lt;br /&gt;if ($fnDir -eq $null) { Write-Host -ForegroundColor Red "Error: Function &lt;$fnName&gt; not found." }&lt;br /&gt;$fnFileName="{0}\{1}_tmp.ps1" -f $env:tmp,$fnName&lt;br /&gt;$fnText=@(gc function:$fnName)&lt;br /&gt;"function global:{0}" -f $fnName &gt; $fnFileName&lt;br /&gt;"{" &gt;&gt;$fnFileName&lt;br /&gt;" {0}" -f $fnText[0].tostring().trim() &gt;&gt; $fnFileName&lt;br /&gt;"}" &gt;&gt; $fnFileName&lt;br /&gt;$psi=new-object System.Diagnostics.ProcessStartInfo&lt;br /&gt;$psi.FileName=$env:editor&lt;br /&gt;$psi.Arguments=$fnFileName&lt;br /&gt;$p=[System.Diagnostics.Process]::start($psi)&lt;br /&gt;$p.waitforexit()&lt;br /&gt;. $fnFileName&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115364274513577768?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115364274513577768/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115364274513577768' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115364274513577768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115364274513577768'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/07/edit-function-powershell.html' title='Edit function : PowerShell'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-31227280.post-115310367836346939</id><published>2006-07-16T19:25:00.000-07:00</published><updated>2006-07-27T23:20:42.513-07:00</updated><title type='text'>PowerShell Fan</title><content type='html'>&lt;strong&gt;Windows PowerShell (Code Name Monad) / MSH Links :&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Integrated Development Environment&lt;br /&gt;&lt;br /&gt;Karl Prosser's MshAnalyzer (&lt;a href="http://www.karlprosser.com/coder/?p=17"&gt;http://www.karlprosser.com/coder/?p=17&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;SAPIEN PrimalScript 4.1 (&lt;a href="http://www.primalscript.com/psnextpreview.asp"&gt;http://www.primalscript.com/psnextpreview.asp&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;PowerShell GUI help&lt;br /&gt;Shiny Power (&lt;a href="http://secretgeek.net/shinyPower.asp"&gt;http://secretgeek.net/shinyPower.asp&lt;/a&gt; )&lt;br /&gt;&lt;br /&gt;PowerShell Remoting Project MSHForFun (&lt;a href="http://mshforfun.blogspot.com/2006/06/powershell-remoting-version-0271.html"&gt;http://mshforfun.blogspot.com/2006/06/powershell-remoting-version-0271.html&lt;/a&gt;)&lt;br /&gt;GotDOTNet Workspace (&lt;a href="http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=ce09cdaf-7da2-4f1c-bed3-f8cb35de5aea"&gt;http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=ce09cdaf-7da2-4f1c-bed3-f8cb35de5aea&lt;/a&gt;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31227280-115310367836346939?l=winpowershell.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://winpowershell.blogspot.com/feeds/115310367836346939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=31227280&amp;postID=115310367836346939' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115310367836346939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/31227280/posts/default/115310367836346939'/><link rel='alternate' type='text/html' href='http://winpowershell.blogspot.com/2006/07/powershell-fan.html' title='PowerShell Fan'/><author><name>PoSH Fan</name><uri>http://www.blogger.com/profile/08900762481587535892</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>
