&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Articles from October 2015 on PowerShell.org - Welcome Automaters!</title><link>https://powershell.org/articles/2015/10/</link><description>Recent content in Articles from October 2015 on PowerShell.org - Welcome Automaters!</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://powershell.org/articles/2015/10/index.xml" rel="self" type="application/rss+xml"/><item><title>Join Computer to Domain with Specified Computer Name and OU</title><link>https://powershell.org/articles/2015-10-30-join-computer-to-domain-with-specified-computer-name-and-ou/</link><guid>https://powershell.org/articles/2015-10-30-join-computer-to-domain-with-specified-computer-name-and-ou/</guid><pubDate>Fri, 30 Oct 2015 18:10:55 +0000</pubDate><description>&lt;p&gt;I addressed a reader requested script for my article this week. PowerShell gives you the ability to add computers to Active Directory right from the command line with the built in PowerShell commandlets. This was introduced with PowerShell version 3 and can be used to automate imaging processes or to prompt an agent for the desired computer name and organizational unit. This is useful since a lot of organizations will use specific OUs for computers according to location or department. This allows them to set group policies that apply to those computer accounts accordingly. By default these computer accounts are created in the root Computers OU, but creating an account can be targeted. The highlighted examples should provide you everything you need to tackle that use case. I provide the basics of adding a computer to the domain as well as prompting the user to enter the computer name and location. Head on over to &lt;a href="http://powershellblogger.com/?p=220"&gt;PowershellBlogger.com&lt;/a&gt; for the full write up and thanks for everyone&amp;rsquo;s continued support!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I addressed a reader requested script for my article this week. PowerShell gives you the ability to add computers to Active Directory right from the command line with the built in PowerShell commandlets. This was introduced with PowerShell version 3 and can be used to automate imaging processes or to prompt an agent for the desired computer name and organizational unit. This is useful since a lot of organizations will use specific OUs for computers according to location or department. This allows them to set group policies that apply to those computer accounts accordingly. By default these computer accounts are created in the root Computers OU, but creating an account can be targeted. The highlighted examples should provide you everything you need to tackle that use case. I provide the basics of adding a computer to the domain as well as prompting the user to enter the computer name and location. Head on over to<a href="http://powershellblogger.com/?p=220">PowershellBlogger.com</a> for the full write up and thanks for everyone&rsquo;s continued support!</p>
]]></content:encoded></item><item><title>Win a Free 4-Day Pass to PowerShell and DevOps Summit 2016!</title><link>https://powershell.org/articles/2015-10-28-win-a-free-4-day-pass-to-powershell-and-devops-summit-2016/</link><guid>https://powershell.org/articles/2015-10-28-win-a-free-4-day-pass-to-powershell-and-devops-summit-2016/</guid><pubDate>Wed, 28 Oct 2015 13:56:18 +0000</pubDate><description>&lt;p&gt;Want to attend the newly expanded, 4-day &lt;a href="http://powershellsummit.org"&gt;PowerShell and DevOps Summit&lt;/a&gt; coming to Bellevue, WA in April 2016? Well you can - if you make your own community contribution!&lt;/p&gt;
&lt;p&gt;Our &lt;a href="https://powershell.org/newsletter/"&gt;TechLetter newsletter&lt;/a&gt; is looking for articles. And, November is of course &lt;a href="http://nanowrimo.org"&gt;NaNoWriMo&lt;/a&gt;, the National Novel Writing Month. But we aren&amp;rsquo;t looking for a novel - just newsletter articles! So we&amp;rsquo;ll call it National PowerShell and DevOps Article Writing Month (NaPoshDoArWriMo). Er. Or something.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Want to attend the newly expanded, 4-day<a href="http://powershellsummit.org">PowerShell and DevOps Summit</a> coming to Bellevue, WA in April 2016? Well you can - if you make your own community contribution!</p><p>Our<a href="https://powershell.org/newsletter/">TechLetter newsletter</a> is looking for articles. And, November is of course<a href="http://nanowrimo.org">NaNoWriMo</a>, the National Novel Writing Month. But we aren&rsquo;t looking for a novel - just newsletter articles! So we&rsquo;ll call it National PowerShell and DevOps Article Writing Month (NaPoshDoArWriMo). Er. Or something.</p><p>Anyway, here&rsquo;s the rules:</p><ol><li>Submit your articles in Word or RTF format, in a ZIP file via email, to &ldquo;editors&rdquo; here at PowerShell.org. Please include a plain-text file with copies of any code in your article, as this makes formatting easier. Also include PNG files of any screen shots your article uses.</li><li>Your article can be on any PowerShell or DevOps topic. Talk about techniques, challenges you&rsquo;ve solved, best practices, or whatever you like. Minimum article length, excluding code, is 1,500 words. Maximum article length, excluding code, is 5,000 words.</li><li>The best articles usually tell a story - a problem you ran into, what you tried, what errors you encountered, and what eventually worked. This is true of &ldquo;best practices&rdquo; as well - talk about how the practice helped you solve a problem, or will help prevent problems. Provide lots of examples!</li><li>You may submit more than one article. Please do so in a separate email for each. In each email, include your name and e-mail address. <strong>Entries are due by the end of November, 2015.</strong></li><li>Our Editors will choose the winning entry and announce it in the January 2016 TechLetter. Editors reserve the right to decline any article they feel is unsuitable, and Editors&rsquo; decision on the winning article is final. Winners are responsible for any taxes or duties imposed by their local government. Prize does not include travel expenses, lodging, or anything else. Anyone, anywhere, is eligible to win unless prevented or limited by local law. Prize is nontransferable and has no cash value.</li></ol><p>All right. Go to it!!!</p>
]]></content:encoded></item><item><title>Find any E-Mail Address or Proxy Address In Active Directory</title><link>https://powershell.org/articles/2015-10-23-find-any-e-mail-address-or-proxy-address-in-active-directory/</link><guid>https://powershell.org/articles/2015-10-23-find-any-e-mail-address-or-proxy-address-in-active-directory/</guid><pubDate>Fri, 23 Oct 2015 16:58:00 +0000</pubDate><description>&lt;p&gt;I am back this week with some more Exchange and Unified Communications goodness. This is another request I see a lot, someone want&amp;rsquo;s to know where an e-mail address is assigned. This opens up the possibilities of user mailboxes, shared mailboxes, distribution lists, public folders, conference rooms, contacts or resources. I have also seen duplicate e-mail addresses being assigned outside of Exchange causing delivery failures. I take a look at how you can quickly find any e-mail address in your environment along with partial searches of e-mail addresses. The two attributes for e-mail addresses being mail and proxyAddresses.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I am back this week with some more Exchange and Unified Communications goodness. This is another request I see a lot, someone want&rsquo;s to know where an e-mail address is assigned. This opens up the possibilities of user mailboxes, shared mailboxes, distribution lists, public folders, conference rooms, contacts or resources. I have also seen duplicate e-mail addresses being assigned outside of Exchange causing delivery failures. I take a look at how you can quickly find any e-mail address in your environment along with partial searches of e-mail addresses. The two attributes for e-mail addresses being mail and proxyAddresses.</p><p>I cover finding specific types of proxy addresses such as sip: x500: eum: etc. I also touch briefly on creating a simple function that will accept e-mail addresses as an input to return all of the AD objects that contain it. I cover the search through Active Directory commandlets, including LDAP query syntax, as well as the Exchange commandlets. Head on over to<a href="http://powershellblogger.com/?p=200">PowerShellBlogger.com</a> for the full article.</p>
]]></content:encoded></item><item><title>The JAPE challenge</title><link>https://powershell.org/articles/2015-10-19-the-jape-challenge/</link><guid>https://powershell.org/articles/2015-10-19-the-jape-challenge/</guid><pubDate>Mon, 19 Oct 2015 08:58:34 +0000</pubDate><description>&lt;p&gt;I have wanted to write my very own obfuscated e-mail signature for a long time but kept myself from doing it. At the time I thought of all these lines of obfuscated code that people wrote during competitions such as the &lt;em&gt;International Obfuscated C Code Contest (IOCCC)&lt;/em&gt; or the &lt;em&gt;Obfuscated Perl Contest&lt;/em&gt; as beyond interest.&lt;/p&gt;
&lt;p&gt;Then I started competing in the Scripting Games, and some tasks involved writing Powershell oneliners that required &lt;strong&gt;mastering the use of the pipeline&lt;/strong&gt; as a tool to refine what each cmdlet passed to another. Once I added a few aliases to these oneliners - which sometimes happened to involve pretty arcane regular expressions - I often came back with hard-to-read and impossible-to-maintain pieces of Powershell code. But, hey, this was fun!&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I have wanted to write my very own obfuscated e-mail signature for a long time but kept myself from doing it. At the time I thought of all these lines of obfuscated code that people wrote during competitions such as the<em>International Obfuscated C Code Contest (IOCCC)</em> or the<em>Obfuscated Perl Contest</em> as beyond interest.</p><p>Then I started competing in the Scripting Games, and some tasks involved writing Powershell oneliners that required<strong>mastering the use of the pipeline</strong> as a tool to refine what each cmdlet passed to another. Once I added a few aliases to these oneliners - which sometimes happened to involve pretty arcane regular expressions - I often came back with hard-to-read and impossible-to-maintain pieces of Powershell code. But, hey, this was fun!</p><p>So, today I have reviewed my point of view. I have understood that reading and understanding obfuscated code can be an interesting<strong>mental challenge.</strong> And being able to write it is a game I like to play.</p><p>Last week I was writing an<a href="http://www.happysysadm.com/2015/10/powershell-gymnastics-prime-numbers.html">article exploring different ways to implement primality tests in Powershell</a>. In the last part of that article I show how to port to Powershell a powerful Perl onliner that can find prime numbers only by matching strings whose length is not prime.</p><p>This Perl oneliner, originally written by Abigail, is part of a collection of famous<strong>JAPHs</strong> - Usenet posting signatures in the 90s - that will output the text &lsquo;<em>Just another Perl Hacker,</em>&rsquo; to screen.</p><p>When you have a look at some of these JAPHs (there is a canonical list on CPAN.org), you can see how it can actually be surprisingly difficult to write truly breathtaking obfuscated code.</p><p>Having said all that, I have come up with the idea of starting some kind of similar challenge around Powershell.</p><h2 id="write-your-jape" class="ps-heading">Write your JAPE<a class="ps-heading-anchor" href="#write-your-jape" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>The challenge consists of writing the most intricate, illegible, awe-inspiring piece of code you can think of, which prints the text &lsquo;<em>JUST ANOTHER POWERSHELL ENTHUSIAST,</em>&rsquo;.</p><p>Feel free to post your contribution in the comments. The rules are:</p><ol><li>the code has to be carefully formatted to fit into max four lines of max 77 characters each, in the style of a Usenet signature</li><li>the comma at the end of the string is mandatory (hey, we are just adding ourselves to the basket!)</li><li>letter case in the output is not important, so you can go for pOwErShElL if you feel like it</li><li>every JAPE has to be presented in the canonical list format, with a date and author attribution</li></ol><p>Rule 1 can be thrown out of the window in case you want to go artistic, as in this notable Perl JAPH by Kickstart:</p><p><code>#Kickstart from http://www.perlmonks.com/ #note: a slight valentine variation :) $LOVE= AMOUR. true.cards. ecstacy.crush .hon.promise.de .votion.partners. tender.truelovers. treasure.affection. devotion.care.woo.baby.ardor.romancing. enthusiasm.fealty.fondness.turtledoves. lovers.sentiment.worship.sweetling.pure attachment.flowers.roses.promise.poem; $LOVE=~ s/AMOUR/adore/g; @a=split(//, $LOVE); $o.= chr (ord($a[1])+6). chr (ord($a[3])+3). $a[16]. $a[5]. chr (32). $a[0]. $a[(26+2)]. $a[27]. $a[5].$a[25]. $a[8].$a[3].chr (32).$a[29]. $a[8].$a[3]. $a[62].chr(32).$a[62]. $a[2].$a[38].$a[4]. $a[3].'.'; print $o;</code>Now, the most notable contributions will be added to the<strong>JAPE Hall of Fame</strong> below.</p><p><strong>Do come up with some interesting piece of &rsquo;educational&rsquo; code, and let&rsquo;s see what creative minds we have here. And remember to have fun!</strong></p><p>To start with, I have decided, with the consent of the author, that the first JAPE be one by Lee Holmes. Even if it breaks the rule of outputting &lsquo;JUST ANOTHER POWERSHELL ENTHUSIAST,&rsquo;, it&rsquo;s probably the first Powershell obfuscated code I have ever seen. Hence the index 0.</p><h2 id="jape-hall-of-fame" class="ps-heading">JAPE Hall of Fame<a class="ps-heading-anchor" href="#jape-hall-of-fame" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Index: $jape[0] - Author: Lee Holmes - Date: June 6th, 2007</p><p><code>$ofs=""; '"$(0'+ '..(0'+ 'xa*['+ 'Math'+ ']::R'+ 'ound'+ '([Ma'+ 'th]:'+ ':Pi/'+ '2,1)'+ ')|%{'+ '[cha'+ 'r][i'+ 'nt]"'+ '"$($'+ '("""'+ '"0$('+ '1838'+ '1589'+ '*726'+ '371*'+ '60)$'+ '(877'+ '7365'+ '981*'+ '263*'+ '360)'+ '$(22'+ '2330'+ '793*'+ '1442'+ '99)$'+ '(310'+ '9*37'+ ') ""'+ '"")[' + '($_*' + '3)..' + '($_*'+ '3+2)' + '])""' + ' })"'|iex</code>Here&rsquo;s my first JAPE as a very basic example to start with. It&rsquo;s a signature block composed of 4 lines of 59 chars.</p><p>Index: $jape[1]  - Author: Carlo - Date: October 9th, 2015</p><p><code>([regex]::Matches(",{0}S{1}I{2}U{3}T{4}E{5}L{6}E{7}S{8}E{9} O{10} {11}E{12}T{13}N{14} {15}S{16}J" -f 'T!A$S!H$N! $L!H$R !W$P!R$H!O$A!T$U'.split('!|$',[System.StringSplitOptions]:: RemoveEmptyEntries),'.','RightToLeft')|%{$_.value}) -join''</code>References:</p><ul><li><a href="http://www.leeholmes.com/blog/2007/06/06/obfuscated-powershell/">http://www.leeholmes.com/blog/2007/06/06/obfuscated-powershell/</a></li><li><a href="http://www.happysysadm.com/2015/10/powershell-gymnastics-prime-numbers.html">http://www.happysysadm.com/2015/10/powershell-gymnastics-prime-numbers.html</a></li><li><a href="http://www.cpan.org/misc/japh">http://www.cpan.org/misc/japh</a></li><li><a href="http://www.happysysadm.com/p/jape.html">http://www.happysysadm.com/p/jape.html</a></li></ul><p>Contact me:</p><ul><li>Twitter<a href="https://twitter.com/sysadm2010">@sysadm2010</a></li></ul>
]]></content:encoded></item><item><title>Command and query separation in Pester tests</title><link>https://powershell.org/articles/2015-10-18-command-and-query-separation-in-pester-tests/</link><guid>https://powershell.org/articles/2015-10-18-command-and-query-separation-in-pester-tests/</guid><pubDate>Sun, 18 Oct 2015 19:15:14 +0000</pubDate><description>&lt;p&gt;Do you feel that writing tests is confusing, and you often end up with complicated test code? I did too, before I learned about Command-query separation principle (or CQS). This principle lead me to start thinking about data flow directions in tests and in the end I realized there are few basic patterns that I use in my test code over and over.&lt;/p&gt;
&lt;h2 id="command-query-separation-principle" class="ps-heading"&gt;Command-query separation principle&lt;a class="ps-heading-anchor" href="#command-query-separation-principle" aria-label="Link to this section" title="Link to this section"&gt;&lt;i class="fas fa-link" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The command and query separation principle tells us that we should separate commands from queries (duh!). To do that, we first need to learn the difference between a command and query: A command is a function that has an observable side-effect and returns no result. A query is the opposite. A function that has no observable-side effect, and returns a result.&lt;br&gt;
&lt;a href="https://gist.github.com/nohwnd/fb5616fb92995555480c"&gt;https://gist.github.com/nohwnd/fb5616fb92995555480c&lt;/a&gt;&lt;br&gt;
The call to &lt;em&gt;Set-Variable&lt;/em&gt; has a side effect of creating a variable named &amp;ldquo;a&amp;rdquo; and setting it to value &amp;ldquo;1&amp;rdquo;. This side effect is clearly observable, because we had no variable &lt;em&gt;$a&lt;/em&gt; before the call and now we have one, so &lt;em&gt;Set-Variable&lt;/em&gt; must be a command. Also the &lt;em&gt;Set-Variable&lt;/em&gt; does not return any output which should be another clue (unless you provide the &lt;em&gt;-PassThru&lt;/em&gt; parameter, more on that later).&lt;br&gt;
The other call, the call to &lt;em&gt;Get-Variable&lt;/em&gt;, has no observable side effect. You could call it once or 100 times and that would have no effect on the value of the &lt;em&gt;$a&lt;/em&gt; variable. Plus the Get-Variable returns a result so it must be a query.&lt;br&gt;
PowerShell also gives us another clue whether a function is a command or query with the Verb used for that function. Anything with Set, Add and New verb is supposed to be a command. Anything with Get verb should be a query.&lt;br&gt;
Understanding the difference between commands and queries is important, because data flows through them in opposite directions, and so you need to test them differently.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Do you feel that writing tests is confusing, and you often end up with complicated test code? I did too, before I learned about Command-query separation principle (or CQS). This principle lead me to start thinking about data flow directions in tests and in the end I realized there are few basic patterns that I use in my test code over and over.</p><h2 id="command-query-separation-principle" class="ps-heading">Command-query separation principle<a class="ps-heading-anchor" href="#command-query-separation-principle" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>The command and query separation principle tells us that we should separate commands from queries (duh!). To do that, we first need to learn the difference between a command and query: A command is a function that has an observable side-effect and returns no result. A query is the opposite. A function that has no observable-side effect, and returns a result.<br><a href="https://gist.github.com/nohwnd/fb5616fb92995555480c">https://gist.github.com/nohwnd/fb5616fb92995555480c</a><br>
The call to<em>Set-Variable</em> has a side effect of creating a variable named &ldquo;a&rdquo; and setting it to value &ldquo;1&rdquo;. This side effect is clearly observable, because we had no variable<em>$a</em> before the call and now we have one, so<em>Set-Variable</em> must be a command. Also the<em>Set-Variable</em> does not return any output which should be another clue (unless you provide the<em>-PassThru</em> parameter, more on that later).<br>
The other call, the call to<em>Get-Variable</em>, has no observable side effect. You could call it once or 100 times and that would have no effect on the value of the<em>$a</em> variable. Plus the Get-Variable returns a result so it must be a query.<br>
PowerShell also gives us another clue whether a function is a command or query with the Verb used for that function. Anything with Set, Add and New verb is supposed to be a command. Anything with Get verb should be a query.<br>
Understanding the difference between commands and queries is important, because data flows through them in opposite directions, and so you need to test them differently.</p><h3 id="data-flow-in-commands-and-queries" class="ps-heading">Data flow in commands and queries<a class="ps-heading-anchor" href="#data-flow-in-commands-and-queries" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h3><p>Let&rsquo;s see some (almost) real-life examples of tests that deal with commands and queries, identify the data flow in them, and try to discover some patterns.<br><a href="https://gist.github.com/nohwnd/f6be402363baa4fb15e7">https://gist.github.com/nohwnd/f6be402363baa4fb15e7</a><br>
In this code the first two functions only act as place-holders for the actual Active Directory cmdlets, feel free to ignore them. The next two functions are more interesting, they are the actual production code that we test - the SUT (System Under Test). Notice that the first function,<em>New-SalesUser</em> is a command, and the second,<em>Get-SalesUser</em> is a query. The most important part are the actual tests, let&rsquo;s have a closer look on each one of them separately.</p><h3 id="testing-new-salesuser" class="ps-heading">Testing New-SalesUser<a class="ps-heading-anchor" href="#testing-new-salesuser" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h3><p>The<em>New-SalesUser</em> is a command, it won&rsquo;t return any value, but it should have an observable side-effect. The side-effect is that a new user is created in the Sales department. The<em>New-SalesUser</em> is not able to do that by itself, instead it delegates the work to the<em>New-ADUser</em> cmdlet. Because we believe that the<em>New-ADUser</em> will do it&rsquo;s work, all we need to test is if it was invoked with the correct parameters, and that&rsquo;s exactly what&rsquo;s happening.<br>
As you can hopefully see the data (input parameters) flow from the input of the<em>New-SalesUser</em> (SUT) towards the internal function<em>New-ADUser</em>, we then use the<em>Assert-MockCalled</em> to verify that the internal command was called correctly. I call this the command direction.</p><h3 id="testing-get-salesuser" class="ps-heading">Testing Get-SalesUser<a class="ps-heading-anchor" href="#testing-get-salesuser" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h3><p>The<em>Get-SalesUser</em> is a query. It will return a value and will have no side-effect. We know that the<em>Get-ADUser</em> is a query as well, so the only part that needs testing is whether or not the<em>FullName</em> property was added. To do that we create a mock of the<em>Get-ADUser</em> function that returns an object and set it&rsquo;s<em>GivenName</em> and<em>Surname</em> properties. We run the<em>Get-SalesUser</em> function and check the values of<em>FullName</em> property.<br>
In this case the data go from the internal function Get-ADUser to the output of the<em>Get-SalesUser</em> (SUT), and we use the Should assertion to check if data was processed correctly. I call this the query direction.</p><h2 id="command-query-hybrids" class="ps-heading">Command-Query hybrids<a class="ps-heading-anchor" href="#command-query-hybrids" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Unfortunately the world of PowerShell is not so black and white as we might like. There are numerous commands that support<em>-PassThru</em> parameter. The<em>-PassThru</em> parameter breaks the clean separation between commands and queries, and so our example function would become a<em>New-Get-SalesUser</em> hybrid.<br>
Such hybrids are a source of confusion and lot of people end up with code like this:<br><a href="https://gist.github.com/nohwnd/86dc22cede6736c2647c">https://gist.github.com/nohwnd/86dc22cede6736c2647c</a><br>
As you can see both the production code and the tests are simply a merge of the<em>Get-SalesUser</em> and<em>New-SalesUser</em> seen in the previous example. The test no longer tests a single thing. If you take your time and track the flow of the data you should see the both the command and query directions are used, and asserted.<br>
The test still works, but is unnecessarily complex and can fail for at least two different reasons. It would be way better to have two separate simpler tests. One testing the query path of the command and another testing the command path. Such conversion is easily done, all we need to do is take the<em>Get-SalesUser</em> test and change the command to<em>New-SalesUser</em>:<br><a href="https://gist.github.com/nohwnd/31df2ef5686f77f1b910">https://gist.github.com/nohwnd/31df2ef5686f77f1b910</a><br>
The tests were split into two and the<em>-PassThru</em> switch was implemented in the<em>New-SalesUser</em> function.<br>
The first<em>It</em> tests the command part of the function, it does not specify the<em>-PassThru</em> switch and so the<em>New-SalesUser</em> acts as a pure command and is tested like that.<br>
The second<em>It</em> tests the query part of the function, specifying the<em>-PassThru</em> switch, and hitting the mock, which produces no side-effects, in result it acts as a pure query function, and is also tested like one.</p><h2 id="are-query-command-hybrids-really-that-bad" class="ps-heading">Are query-command hybrids really that bad?<a class="ps-heading-anchor" href="#are-query-command-hybrids-really-that-bad" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>No not really. Such hybrids have some useful properties that make PowerShell better. Probably the most useful is that they enable you to combine both queries and commands in a single pipeline. The also enable you to immediately retreive result of your changes and for example print them to screen.<br>
All in all such hybrids are quite useful beasts. The downside unfortunately is that a lot of people unconiously end up with such hybrid, and without seeing the way to split it they start to produce overly-complicated tests. Often copy pasting the code to set up the whole environment, just to assert the result of the &ldquo;query&rdquo;. Setting up twenty properties on the resulting object just to ignore it while testing the &ldquo;command&rdquo;. Or worst all of this together.</p><h2 id="summary" class="ps-heading">Summary<a class="ps-heading-anchor" href="#summary" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Hopefully this article gave you the minimum to tell commands from queries and outlined possible approaches to testing them. You should now be aware of the command query hybrids and be able to identify them even if they don&rsquo;t specify a<em>-PassThru</em> parameter.<br>
Happy coding!</p>
]]></content:encoded></item><item><title>Desired State Configuration – Beware Of Circular Configurations</title><link>https://powershell.org/articles/2015-10-14-desired-state-configuration-beware-of-circular-configurations/</link><guid>https://powershell.org/articles/2015-10-14-desired-state-configuration-beware-of-circular-configurations/</guid><pubDate>Wed, 14 Oct 2015 13:00:37 +0000</pubDate><description>&lt;p&gt;Lately, I&amp;rsquo;ve been working at converting a lot of my server configuration scripts into DSC configurations.  After all, what better way to learn than by updating your existing methods?  I recently ran into an issue, however, while converting my SCCM Distribution Point deployment script into a config, where the test systems inexplicably began rebooting every thirty minutes or so.  The Local Configuration Manager was configured to reboot if necessary, and these were fresh installs, so I knew that my culprit was most likely in my configuration.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Lately, I&rsquo;ve been working at converting a lot of my server configuration scripts into DSC configurations.  After all, what better way to learn than by updating your existing methods?  I recently ran into an issue, however, while converting my SCCM Distribution Point deployment script into a config, where the test systems inexplicably began rebooting every thirty minutes or so.  The Local Configuration Manager was configured to reboot if necessary, and these were fresh installs, so I knew that my culprit was most likely in my configuration.</p><p>The config was pretty basic: Put the server into a Core state and uninstall the UI management tools, ensure RDC is installed, install the distribution point prerequisites (IIS, IIS 6 WMI Compatibility, .NET 4.5, etc), and configure some firewall rules.  My original script had always served me well, so I was dumbfounded as to what the problem could be.  I decided to<a href="http://blogs.msdn.com/b/powershell/archive/2014/01/03/using-event-logs-to-diagnose-errors-in-desired-state-configuration.aspx">enable the debug logging</a> for DSC and see what came up.</p><p><code>Get-WinEvent -LogName "Microsoft-Windows-Dsc/Debug" -ComputerName LWINCM02 -Oldest | Out-Gridview</code>When I get the output, I&rsquo;m seeing a lot of looping around my Remote Differential Compression resource, which ensures that the RDC component is installed.  A further look in the logs showed that the UI Management Tools were also being uninstalled repeatedly.  Hmm&hellip;</p><p><a href="https://powershell.org/wp-content/uploads/2015/10/RDCOGV.jpg"><img src="https://powershell.org/wp-content/uploads/2015/10/RDCOGV-628x331.jpg" alt=""/></p><p>So on another system that isn&rsquo;t receiving the configuration, I decide to run the Install-WindowsFeature command with the WhatIf switch against the RDC component.  Upon the result, I immediately see what my problem is:</p><p><a href="https://powershell.org/wp-content/uploads/2015/10/RDCInst-e1444781815463.jpg"><img src="https://powershell.org/wp-content/uploads/2015/10/RDCInst-e1444781798166-628x413.jpg" alt="RDCInst"/></p><p>The Remote Differential Component requires the installation of the GUI Management Tools.  Likewise, the uninstallation of these tools results in the removal of the RDC component.  So what was happening was this:</p><ul><li>GUI Tools are removed by DSC, also removing the RDC component.</li><li>Server reboots.</li><li>GUI tools are verified uninstalled.  RDC component is reinstalled, which reinstalls the GUI Tools.</li><li>Server Reboots.</li><li>Wash.  Rinse.  Repeat.</li></ul><p>I&rsquo;ve since removed the GUI tools removal from my configuration, as RDC is a required component for my distribution points, and my configuration is now working flawlessly.  In tracing the root of my problem, I came to realize two very important lessons.</p><p>First, as admins, engineers, and solution providers, we often don&rsquo;t take a very close look at our scripts and what it&rsquo;s really doing behind the scenes if it gives us the result we&rsquo;re looking for.  In the case of my configuration script, I added a line to install the RDC component after removing the UI and tools and didn&rsquo;t look any further into why I had to do this in the first place.  DSC kept me honest in this respect - and gave me a gentle reminder to look a little deeper if something unexpected occurs, rather than slapping a band-aid on it and calling it good.</p><p>Second, it can be very easy to find yourself dealing with a configuration loop if you&rsquo;re altering the state of components that other components in your config rely on.  Be sure to test your configurations, check your logs, and most importantly, make sure you know what you&rsquo;re really configuring when you configure it.</p>
]]></content:encoded></item><item><title>Using Package Management in Windows PowerShell v3</title><link>https://powershell.org/articles/2015-10-12-using-package-management-in-windows-powershell-v3/</link><guid>https://powershell.org/articles/2015-10-12-using-package-management-in-windows-powershell-v3/</guid><pubDate>Mon, 12 Oct 2015 20:48:32 +0000</pubDate><description>&lt;p&gt;Hey now! The &lt;a href="http://blogs.msdn.com/b/powershell/archive/2015/10/09/package-management-preview-for-powershell-4-amp-3-is-now-available.aspx"&gt;PowerShell team&lt;/a&gt; published a preview version of &lt;a href="https://www.microsoft.com/en-us/download/details.aspx?id=49186"&gt;PackageManagement&lt;/a&gt; for Windows PowerShell v3 and v4. As it happens, I have a Windows 7 SP1 box running PowerShell v3&amp;ndash;why not run a little experiment?&lt;/p&gt;
&lt;p&gt;`$PSVersionTable.PSVersion
Major Minor Build Revision&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;3 0 -1 -1
`## Preparing the Environment&lt;/p&gt;
&lt;p&gt;You need &lt;a href="https://www.microsoft.com/en-us/download/details.aspx?id=40779"&gt;.NET Framework 4.5&lt;/a&gt; or later, so take care of that prerequisite before you install the following two assets:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.microsoft.com/en-us/download/details.aspx?id=34595"&gt;Windows Management Framework (WMF) v3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.microsoft.com/en-us/download/details.aspx?id=49186"&gt;PackageManagement PowerShell Modules Preview&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I restarted the computer after each installation just to be safe.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Hey now! The<a href="http://blogs.msdn.com/b/powershell/archive/2015/10/09/package-management-preview-for-powershell-4-amp-3-is-now-available.aspx">PowerShell team</a> published a preview version of<a href="https://www.microsoft.com/en-us/download/details.aspx?id=49186">PackageManagement</a> for Windows PowerShell v3 and v4. As it happens, I have a Windows 7 SP1 box running PowerShell v3&ndash;why not run a little experiment?</p><p>`$PSVersionTable.PSVersion
Major Minor Build Revision</p><hr><p>3 0 -1 -1
`## Preparing the Environment</p><p>You need<a href="https://www.microsoft.com/en-us/download/details.aspx?id=40779">.NET Framework 4.5</a> or later, so take care of that prerequisite before you install the following two assets:</p><ul><li><a href="https://www.microsoft.com/en-us/download/details.aspx?id=34595">Windows Management Framework (WMF) v3</a></li><li><a href="https://www.microsoft.com/en-us/download/details.aspx?id=49186">PackageManagement PowerShell Modules Preview</a></li></ul><p>I restarted the computer after each installation just to be safe.</p><p>Before we proceed we also need to relax our Windows 7 client&rsquo;s script execution policy or we won&rsquo;t see the PSModule package provider or the PowerShellGet module:</p><p><code>Set-ExecutionPolicy -ExecutionPolicy Bypass -Force</code>As you can see in the following screenshot, installing the PackageManagement Preview also gives us PowerShellGet. By the way, in case you didn&rsquo;t know, we use PowerShellGet to discover, install, and manage PowerShell modules, and we use PackageManagement to discover, install, and manage software packages.</p><p><a href="https://powershell.org/wp-content/uploads/2015/10/Modules-folder-on-our-Windows-7-workstation.png"><img src="https://powershell.org/wp-content/uploads/2015/10/Modules-folder-on-our-Windows-7-workstation-628x313.png" alt="Modules folder on our Windows 7 workstation"/></p><pre><code>Modules folder on our Windows 7 workstation</code></pre><h2 id="poking-around-with-the-commands" class="ps-heading">Poking Around with the Commands<a class="ps-heading-anchor" href="#poking-around-with-the-commands" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Let&rsquo;s do this! Open an administrative PowerShell console examine the PackageManagement commands:</p><p><code>Get-Command -Module PackageManagement | Select-Object -Property Name | Format-Wide -Column 2 Find-Package Get-Package Get-PackageProvider Get-PackageSource Install-Package Register-PackageSource Save-Package Set-PackageSource Uninstall-Package Unregister-PackageSource</code>In PackageManagement nomenclature, a package provider represents the &ldquo;conduit&rdquo; between the local computer and the PackageManagement engine. As a matter of fact, PackageManagement is most often called a package manager manager (no, that&rsquo;s not a typo).</p><p>Next, take a look at the default package providers:</p><h2 id="name" class="ps-heading">`Get-PackageProvider | Select-Object -Property Name | Sort-Object -Property Name
Name<a class="ps-heading-anchor" href="#name" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>msi
msu
Programs
PSModule
`Your intuition is correct if you think that you can manage locally installed software by working with the<strong>msi, msu,</strong> and<strong>Programs</strong> providers. A single package provider can be associated with one or more package sources (repositories).</p><p>`Get-PackageSource | Select-Object -Property Name, ProviderName, IsTrusted
Name ProviderName IsTrusted</p><hr><p>PSGallery PSModule False
`The<a href="https://www.powershellgallery.com/">PowerShell Gallery</a> (PSGallery for short) is a Microsoft-run PowerShell module repository. That&rsquo;s fine, but where are the software packages? That&rsquo;s what PackageManagement package sources are for!</p><p>Microsoft promotes the<a href="https://chocolatey.org/">Chocolatey package repository</a> as a starting point for PowerShell package management. Please note that Chocolatey is not owned by Microsoft and using Chocolatey packages is at your own risk.</p><p>Moreover, be aware also that setting the<strong>-Trusted</strong> flag on a repository performs no source code validation. Instead, it simply suppresses an &ldquo;Are you sure?&rdquo; confirmation sanity check before you install a package.</p><p>All that having been said, let&rsquo;s register Chocolatey as a trusted repo on our Windows 7 workstation, and then verify its installation:</p><p>`Register-PackageSource -Name Chocolatey -Location<a href="http://chocolatey.org/api/v2">http://chocolatey.org/api/v2</a> -ProviderName PSModule -Trusted -Verbose
Get-PackageSource | Select-Object -Property Name, ProviderName, IsTrusted
Name ProviderName IsTrusted</p><hr><p>PSGallery PSModule False
Chocolatey PSModule True
`I didn&rsquo;t show it in the previous code example, but on first run you&rsquo;ll be prompted to let PowerShell download and install the NuGet provider.<a href="https://www.nuget.org/">NuGet</a> is a package manager intended for .NET developers and makes it easier to find and install code libraries in Visual Studio. Chocolatey has a dependency on NuGet, so that&rsquo;s why it&rsquo;s required.</p><p>The open-source world seems to love word puns; perhaps you derived a few &lsquo;yuk yuks&rsquo; over the idea of &ldquo;chocolatey nuget,&rdquo; right? Er, maybe not. 🙂</p><h2 id="installing-some-software" class="ps-heading">Installing Some Software<a class="ps-heading-anchor" href="#installing-some-software" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Well, the great moment has arrived: Let&rsquo;s install some software. How about 7-Zip, the freeware file archiver? Does the Chocolatey repo host a copy of the tool?</p><p><code>Find-Package -Name *7zip*</code>I&rsquo;ll spare you the output, but the answer is &ldquo;Yes, of course.&rdquo; Now that we know the name of the package, we can pipeline the object to<strong><a href="https://docs.nuget.org/consume/package-manager-console-powershell-reference#install-package">Install-Package</a>.</strong> We&rsquo;ll specify** **the<strong>-Verbose</strong> switch parameter so we see as many &ldquo;behind the scenes&rdquo; details as possible:</p><p><code>Find-Package -Name 7zip | Install-Package -Verbose -Force</code>Sadly, I learned through bitter experience (as well as by inspecting the<strong>-Verbose</strong> package installation output) that different packages put the executables in different folders. For instance, the Chocolatey<a href="http://www.7-zip.org/">7-Zip</a> package uses the traditional<strong>C:\Program Files</strong>. On the other hand, the Chocolatey<a href="https://technet.microsoft.com/en-us/sysinternals/bb545021.aspx">Windows Sysinternals</a> package places its executables in the path<strong>C:\Chocolatey\bin</strong>. Thus, I needed to add this path permanently to my<a href="https://www.wikiwand.com/en/PATH_(variable)">PATH</a> environment variable to make the Sysinternals utilities easier to use from within PowerShell. </p><p>Now for the bad news. What I said in the previous paragraph is perfectly valid for PackageManagement under Windows PowerShell v5. However, I was unable to install any packages on my Windows 7 SP1 machine. Strangely, the package installations failed not with a traditional red error message but with the yellow (or green? I&rsquo;m colorblind) warning message:</p><p><code>WARNING: The module '7zip' cannot be installed or updated because it is not a properly-formed module.</code>This is obviously a bug. Either that or I did something stupid on my own on this computer .:)</p><h2 id="testing-powershellget" class="ps-heading">Testing PowerShellGet<a class="ps-heading-anchor" href="#testing-powershellget" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Just for grins, let&rsquo;s use PowerShellGet to install<a href="http://www.powertheshell.com/isesteroids/">ISE Steroids</a>, my favorite script editor. We&rsquo;ll begin by enumerating the PowerShellGet functions as usual:</p><p><code>Get-Command -Module PowerShellGet | Select-Object -Property Name | Format-Wide -Column 2 Find-Module Get-InstalledModule Get-PSRepository Install-Module Publish-Module Register-PSRepository Save-Module Set-PSRepository Uninstall-Module Unregister-PSRepository Update-Module</code>Fun fact: The PowerShellGet functions are simply wrappers for PackageManagement commands. PowerShellGet runs through the PSModule package provider by default.</p><p>Next we&rsquo;ll install the module. Yes, we could use<strong>Find-Module</strong>, but I already know that<a href="https://mvp.microsoft.com/en-us/PublicProfile/9199?fullName=Tobias%20Weltner">Dr. Weltner</a> posted his module to the Gallery:</p><p><code>Install-Module -Name ISESteroids -Verbose -Force</code>This time a smile crept across my face when I issued<strong>Start-Steroids</strong> from within my PowerShell v3 ISE and ISE Steroids loaded. </p><h2 id="final-thoughts" class="ps-heading">Final Thoughts<a class="ps-heading-anchor" href="#final-thoughts" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>I have two parting thoughts for you. First, the PackageManagement Modules Preview for PowerShell v3 and v4 (wow, say that three times quickly) is indeed a preview release. Therefore, we can always file bug reports on<a href="https://connect.microsoft.com/PowerShell">Microsoft Connect</a> and I&rsquo;m sure the PowerShell team will validate and correct them.</p><p>Second, any self-respecting business should deploy their own private, internal package and module repositories rather than use public ones like Chocolatey. The best instructions I&rsquo;ve found online for building your own package management repository come from PowerShell MVP<a href="https://mvp.microsoft.com/en-us/PublicProfile/5000355?fullName=Boe%20Prox">Boe Prox</a> in his blog post &ldquo;<a href="http://learn-powershell.net/2014/04/11/setting-up-a-nuget-feed-for-use-with-oneget/">Setting Up a NuGet Feed for Use with OneGet</a>.&rdquo; By the way, OneGet was the original name for what&rsquo;s now called PackageManagement.</p><p>I hope you found this article useful. Let&rsquo;s chat about it in the comments! Thanks for reading and take good care.</p>
]]></content:encoded></item><item><title>Automate Sip Address and UPN name changes in Lync / Skype for Business</title><link>https://powershell.org/articles/2015-10-12-automate-sip-address-and-upn-name-changes-in-lync-skype-for-business/</link><guid>https://powershell.org/articles/2015-10-12-automate-sip-address-and-upn-name-changes-in-lync-skype-for-business/</guid><pubDate>Mon, 12 Oct 2015 18:37:56 +0000</pubDate><description>&lt;p&gt;Name changes are a common occurrence in the world of IT and usually the primary concern is the e-mail address. Exchange e-mail address policies will handle this for us but often times the Sip Address and User Principal Name are left behind. I tackle these changes with an automated way of changing the Lync / Skype for Business sip address (also known as sign-in address) and User Principal Name to match the e-mail address. I also include the link to download the Lync / Skype for Business meeting update tool that is required when a Sip Address is changed. Head on over to &lt;a href="http://powershellblogger.com/?p=164"&gt;PowerShellBlogger.com&lt;/a&gt; for the full article.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Name changes are a common occurrence in the world of IT and usually the primary concern is the e-mail address. Exchange e-mail address policies will handle this for us but often times the Sip Address and User Principal Name are left behind. I tackle these changes with an automated way of changing the Lync / Skype for Business sip address (also known as sign-in address) and User Principal Name to match the e-mail address. I also include the link to download the Lync / Skype for Business meeting update tool that is required when a Sip Address is changed. Head on over to<a href="http://powershellblogger.com/?p=164">PowerShellBlogger.com</a> for the full article.</p>
]]></content:encoded></item><item><title>Export Subnets from Active Directory Sites and Services</title><link>https://powershell.org/articles/2015-10-09-export-subnets-from-active-directory-sites-and-services/</link><guid>https://powershell.org/articles/2015-10-09-export-subnets-from-active-directory-sites-and-services/</guid><pubDate>Sat, 10 Oct 2015 02:39:20 +0000</pubDate><description>&lt;p&gt;I am back this week with a quick write up on how to export your network subnets from Active Directory Sites and Services. Active Directory Sites and Services subnet assignments are important for healthy replication and for location based services to function properly. The need for this information has come across my desk on several occasions. Even a quick print out would be extremely helpful to keep at your desk.  I have included both Windows 7/2008 and Windows 8/2012 methods to ensure everyone is covered. Head on over to &lt;a href="http://powershellblogger.com/?p=121"&gt;PowerShellBlogger.com&lt;/a&gt; for the full article. As always, leave a comment and I will be sure to respond.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>I am back this week with a quick write up on how to export your network subnets from Active Directory Sites and Services. Active Directory Sites and Services subnet assignments are important for healthy replication and for location based services to function properly. The need for this information has come across my desk on several occasions. Even a quick print out would be extremely helpful to keep at your desk.  I have included both Windows 7/2008 and Windows 8/2012 methods to ensure everyone is covered. Head on over to<a href="http://powershellblogger.com/?p=121">PowerShellBlogger.com</a> for the full article. As always, leave a comment and I will be sure to respond.</p>
]]></content:encoded></item><item><title>Testing PowerShell Direct with Windows Server 2016 TP3 Hyper-V</title><link>https://powershell.org/articles/2015-10-08-testing-powershell-direct-with-windows-server-2016-tp3-hyper-v/</link><guid>https://powershell.org/articles/2015-10-08-testing-powershell-direct-with-windows-server-2016-tp3-hyper-v/</guid><pubDate>Thu, 08 Oct 2015 14:03:48 +0000</pubDate><description>&lt;p&gt;Hey there! I  thought we could test &lt;a href="http://blogs.technet.com/b/virtualization/archive/2015/05/14/powershell-direct-running-powershell-inside-a-virtual-machine-from-the-hyper-v-host.aspx"&gt;PowerShell Direct&lt;/a&gt; together today. Here&amp;rsquo;s the elevator pitch: In Windows Server 2016 and Windows 10, we can send PowerShell commands from the Hyper-V host directly to its corresponding virtual machines (VMs), &lt;em&gt;&lt;strong&gt;even in the absence of guest VM networking&lt;/strong&gt;&lt;/em&gt;. Yeah, that&amp;rsquo;s cool, isn&amp;rsquo;t it?&lt;/p&gt;
&lt;p&gt;What&amp;rsquo;s just as impressive is that PowerShell Direct works _&lt;strong&gt;even if PowerShell remoting is disabled on the guest VM!&lt;/strong&gt; _PowerShell Direct also circumvents Windows Firewall. Note that PowerShell Direct requires that commands are sent only from a Hyper-V host to its local VMs.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Hey there! I  thought we could test<a href="http://blogs.technet.com/b/virtualization/archive/2015/05/14/powershell-direct-running-powershell-inside-a-virtual-machine-from-the-hyper-v-host.aspx">PowerShell Direct</a> together today. Here&rsquo;s the elevator pitch: In Windows Server 2016 and Windows 10, we can send PowerShell commands from the Hyper-V host directly to its corresponding virtual machines (VMs),<em><strong>even in the absence of guest VM networking</strong></em>. Yeah, that&rsquo;s cool, isn&rsquo;t it?</p><p>What&rsquo;s just as impressive is that PowerShell Direct works _<strong>even if PowerShell remoting is disabled on the guest VM!</strong> _PowerShell Direct also circumvents Windows Firewall. Note that PowerShell Direct requires that commands are sent only from a Hyper-V host to its local VMs.</p><p>Also, PowerShell Direct is supported at this point only by Windows Server 2016 TP3 and Windows 10. That means a Windows Server 2016 TP3 Hyper-V host cannot leverage PowerShell Direct against, say, Windows Server 2012 R2 virtual machines (give the Hyper-V, PowerShell, and Windows Server teams time; I&rsquo;m sure this will be supported in the future).</p><p>The secret sauce behind PowerShell Direct is<a href="https://msdn.microsoft.com/en-us/library/dd357801.aspx">PowerShell Remoting Protocol</a> (MS-PSRP), which used to be called just plain ol&rsquo; garden variety &ldquo;PowerShell remoting.&rdquo;</p><h2 id="the-lab-setup" class="ps-heading">The Lab Setup<a class="ps-heading-anchor" href="#the-lab-setup" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>In my test lab, I started with a domain controller and Hyper-V host (yeah, I&rsquo;m combining server roles&ndash;what of it?) named<strong>hyperv1.company.pri</strong>. That server&rsquo;s running<a href="https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-technical-preview">Windows Server 2016 Technical Preview 3</a>.</p><p>In Hyper-V I created a single virtual switch named<strong>Internal</strong> that is connected to the host/guest network. Of course, we don&rsquo;t care about the switch fabric because we&rsquo;re going to use PowerShell Direct.</p><p>Next, I built a Windows Server 2016 TP3-based guest VM named<strong>server1</strong> and disabled the network adapter as you can see in the following screenshot. No smoke and mirrors here!</p><p><a href="https://powershell.org/wp-content/uploads/2015/10/Our-lab-set-up-and-ready-to-test-PowerShell-direct.png"><img src="https://powershell.org/wp-content/uploads/2015/10/Our-lab-set-up-and-ready-to-test-PowerShell-direct.png" alt="Our lab is set up and ready to test PowerShell Direct."/></p><pre><code>Our lab is set up and ready to test PowerShell Direct.</code></pre><p>As a final &ldquo;sanity check&rdquo; to ensure the guest VM is as theoretically inaccessible as possible, I blocked access to all remote access session configurations and disabled the Windows Remote Management (WinRM) service by running the following command from within the guest (thanks to PowerShell MVP <a href="https://twitter.com/alexandair">Aleksandar Nikolić</a> for clarification on this point):</p><p><code>Disable-PSRemoting -Force Get-Service -Name WinRM | Stop-Service -Force | Set-Service -StartupType Disabled</code>Okay. Let&rsquo;s move onto the next phase of our experiment.</p><h2 id="sending-commands-to-the-guest-vm" class="ps-heading">Sending Commands to the Guest VM<a class="ps-heading-anchor" href="#sending-commands-to-the-guest-vm" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Let&rsquo;s obtain the name and globally unique identifier (GUID) of our Windows Server 2016 VM (you&rsquo;ll see why in just a moment):</p><p>`Get-VM | Select-Object -Property Name, VMid
Name VMId</p><hr><p>server1 31d787fe-02cd-4363-b50b-16bc8243fc77
`PowerShell Direct makes itself manifest by means of two new parameters:</p><ul><li>VMname</li><li>VMGuid</li></ul><p>Handy, eh? The following two cmdlets support the<strong>-VMname</strong> and<strong>-VMGuid</strong> parameters as of this writing in October 2016:</p><ul><li><a href="https://technet.microsoft.com/en-us/library/hh849707.aspx">Enter-PSSession</a></li><li><a href="https://technet.microsoft.com/en-us/library/hh849719.aspx">Invoke-Command</a></li></ul><p>Time to test! Let&rsquo;s start a remote session with the<strong>server1</strong> guest VM by specifying its GUID. Note that you will need:</p><ul><li>Hyper-V administrative privileges on the host</li><li>Local administrative privileges on the guest</li></ul><p><code>$cred = Get-Credential Enter-PSSession -VMGuid 31d787fe-02cd-4363-b50b-16bc8243fc77 -Credential $cred [server1]: PS C:\Users\Administrator\Documents&gt;</code>We&rsquo;ll finish by using Invoke-Command to send ad-hoc PowerShell pipelines and entire scripts from host to guest:</p><p><code>Invoke-Command -VMName 'server1' -Credential $cred -ScriptBlock { Get-Service | Where-Object {$_.Status -eq 'Stopped'} } Invoke-Command -VMName 'server1' -FilePath 'D:\scripts\setup-ip.ps1' -Credential $cred</code>## Conclusions</p><p>Convenience is the primary advantage that PowerShell Direct brings to us Hyper-V administrators. We can connect to and fully administer our guest virtual machines regardless of their networking, firewall, or WS-Man state. Thanks for reading, and more power to the shell!</p>
]]></content:encoded></item><item><title>#MSPSUG Virtual Meeting: Using Regular Expressions with #PowerShell – October 13th 2015</title><link>https://powershell.org/articles/2015-10-06-mspsug-virtual-meeting-using-regular-expressions-with-powershell-october-13th-2015/</link><guid>https://powershell.org/articles/2015-10-06-mspsug-virtual-meeting-using-regular-expressions-with-powershell-october-13th-2015/</guid><pubDate>Tue, 06 Oct 2015 14:13:57 +0000</pubDate><description>&lt;p&gt;Join the Mississippi PowerShell User Group virtually on Tuesday, October 13th at 8:30pm Central Time when &lt;a href="http://twitter.com/TechTrainerTim"&gt;Timothy Warner&lt;/a&gt; will present “&lt;em&gt;&lt;strong&gt;Pattern Match Like a Pro: Using Regular Expressions with Windows PowerShell&lt;/strong&gt;&lt;/em&gt;”.&lt;/p&gt;
&lt;p&gt;Many Windows systems administrators are intimidated with regular expressions due to its seemingly strange, &amp;ldquo;Unixy&amp;rdquo; syntax. Take heart! By the end of this session, you&amp;rsquo;ll finally understand how to perform simple and advanced text filtering with RegEx, specifically by leveragine PowerShell&amp;rsquo;s -match operator and Select-String cmdlet.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Join the Mississippi PowerShell User Group virtually on Tuesday, October 13th at 8:30pm Central Time when<a href="http://twitter.com/TechTrainerTim">Timothy Warner</a> will present “<em><strong>Pattern Match Like a Pro: Using Regular Expressions with Windows PowerShell</strong></em>”.</p><p>Many Windows systems administrators are intimidated with regular expressions due to its seemingly strange, &ldquo;Unixy&rdquo; syntax. Take heart! By the end of this session, you&rsquo;ll finally understand how to perform simple and advanced text filtering with RegEx, specifically by leveragine PowerShell&rsquo;s -match operator and Select-String cmdlet.</p><p>Visit the<a href="http://mspsug.com/2015/09/22/mspsug-1013-meeting-pattern-match-like-a-pro-using-regular-expressions-with-windows-powershell/">Mississippi PowerShell User Group</a> website to learn more about Timothy and to find out more details about this month’s meeting.</p><p>The Mississippi PowerShell User Group Meetings are held online (via Skype for Business) on the second Tuesday of each month at 8:30pm Central Time and are free to attend. The system requirements to attend these online meetings can be found on the MSPSUG website under the “<a href="http://mspsug.com/attendee-info/">Attendee Info</a>” section.</p><p>Register via<a href="http://mspsug.eventbrite.com/">EventBrite</a> to receive the URL for this meeting.</p><p>Note: It is not necessary to live in Mississippi or join our user group to attend our meetings or present a session for our user group.</p><p>µ</p>
]]></content:encoded></item><item><title>Finding Evil LDAP Queries</title><link>https://powershell.org/articles/2015-10-05-finding-evil-ldap-queries/</link><guid>https://powershell.org/articles/2015-10-05-finding-evil-ldap-queries/</guid><pubDate>Mon, 05 Oct 2015 14:17:34 +0000</pubDate><description>&lt;p&gt;Have you ever wondered what LDAP queries were hitting your domain controllers? Even outside of fun investigations, it can be insightful to get a sampling of queries hitting your domain controller. The more services you have integrated with Active Directory, the more likely a vendor or sysadmin unwittingly configured their service to produce evil queries.&lt;/p&gt;
&lt;p&gt;Mark Morowczynski from Microsoft wrote a great post on &lt;a href="http://blogs.technet.com/b/askpfeplat/archive/2015/05/11/how-to-find-expensive-inefficient-and-long-running-ldap-queries-in-active-directory.aspx"&gt;finding these expensive, inefficient, or long running queries&lt;/a&gt; - But something was missing. Screen shots of regedit? If you have more than a handful of domain controllers, enabling and disabling this logging is going to be quite a chore.&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Have you ever wondered what LDAP queries were hitting your domain controllers? Even outside of fun investigations, it can be insightful to get a sampling of queries hitting your domain controller. The more services you have integrated with Active Directory, the more likely a vendor or sysadmin unwittingly configured their service to produce evil queries.</p><p>Mark Morowczynski from Microsoft wrote a great post on <a href="http://blogs.technet.com/b/askpfeplat/archive/2015/05/11/how-to-find-expensive-inefficient-and-long-running-ldap-queries-in-active-directory.aspx">finding these expensive, inefficient, or long running queries</a> - But something was missing. Screen shots of regedit? If you have more than a handful of domain controllers, enabling and disabling this logging is going to be quite a chore.</p><p><a href="http://ramblingcookiemonster.github.io/Evil-LDAP-Queries/">Here&rsquo;s a quick bit</a> on using PowerShell to enable and disable this logging quickly. Take a peek, you might find some misbehaving applications.</p>
]]></content:encoded></item><item><title>2015-October Scripting Games Puzzle</title><link>https://powershell.org/articles/2015-10-03-october-2015-scripting-games-puzzle/</link><guid>https://powershell.org/articles/2015-10-03-october-2015-scripting-games-puzzle/</guid><pubDate>Sat, 03 Oct 2015 13:31:53 +0000</pubDate><description>&lt;p&gt;Our October 2015 puzzle might take us beyond the realm of one-liners, but it circles back to the August 2015 theme of retrieving information from the web. This is another scenario that actually has a lot of real-world applications, in that there&amp;rsquo;s a lot of practical uses in the work environment for this technique. &lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Our October 2015 puzzle might take us beyond the realm of one-liners, but it circles back to the August 2015 theme of retrieving information from the web. This is another scenario that actually has a lot of real-world applications, in that there&rsquo;s a lot of practical uses in the work environment for this technique. </p><h2 id="instructions" class="ps-heading"><strong>Instructions</strong><a class="ps-heading-anchor" href="#instructions" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>The Scripting Games have been re-imagined as a monthly puzzle. We publish puzzles the first Saturday of each month, along with solutions and commentary for the previous month&rsquo;s puzzle. You can find them all at<a href="https://powershell.org/category/announcements/scripting-games/">https://powershell.org/category/announcements/scripting-games/</a>. Many puzzles will include optional challenges, that you can use to really push your skills.</p><p><strong>To participate</strong>, add your solution to a public Gist (<a href="http://gist.github.com">http://gist.github.com</a>; you&rsquo;ll need a free GitHub account, which all PowerShellers should have anyway). After creating your public Gist, just copy the URL from your browser window and paste it, by itself, as a comment of this post. 
**Only post one entry per person. You are not allowed to come back and post corrected or improved versions. If you do, all of your posts will be ignored. **However, remember that you can always go back and edit your Gist. We&rsquo;ll always pull the most recent one when we display it, so there&rsquo;s no need to post multiple entries if you want to make an edit.</p><p>Don&rsquo;t forget the <a href="https://powershell.org/?p=2574">main rules and purpose of these monthly puzzles</a>, including the fact that you won&rsquo;t receive individual scoring or commentary on your entry.</p><p><strong>User groups are encouraged to work together</strong> on the monthly puzzles. User group leaders should submit their group&rsquo;s best entry to Ed Wilson, the Scripting Guy, via e-mail, prior to the third Saturday of the month. On the last Saturday of the month, Ed will post his favorite, along with commentary and excerpts from noteworthy entries. The user group with the most &ldquo;favorite&rdquo; entries of the year will win a grand prize from PowerShell.org.</p><h2 id="" class="ps-heading"><a class="ps-heading-anchor" href="#" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><h2 id="our-puzzle" class="ps-heading"><strong>Our Puzzle</strong><a class="ps-heading-anchor" href="#our-puzzle" aria-label="Link to this section" title="Link to this section"><i class="fas fa-link" aria-hidden="true"/></a></h2><p>Write a short script that can retrieve the most recent article headlines from a blog by using the blog’s RSS or Atom feed. You should ideally just display the headlines, but might also choose to display a URL that links to the article, and might display a short excerpt of the article. If the feed contains the full article text, don’t display it – at most, display a short excerpt.</p><p>While you could definitely write this as a one-liner, and might choose to do so as you start, there&rsquo;s real value in turning this into a &ldquo;Get-RSSFeed&rdquo; function. To be fair, lots of folks have done this before - but challenge yourself, and try to figure it out without opening a search engine!</p><p><strong>Challenges:</strong></p><ul><li>Try to write this to be a PowerShell command (an advanced function) that uses parameters to direct the behavior of the command.</li><li>Try to ensure your script’s output could be easily displayed in an on-screen table, or redirected to a CSV file.</li><li>Try to minimize your use of “raw” .NET classes (e.g., try to use only PowerShell commands as much as possible).</li></ul>]]></content:encoded></item><item><title>Delete Specific E-Mail or E-Mails From All Exchange Mailboxes</title><link>https://powershell.org/articles/2015-10-02-delete-specific-e-mail-or-e-mails-from-all-exchange-mailboxes/</link><guid>https://powershell.org/articles/2015-10-02-delete-specific-e-mail-or-e-mails-from-all-exchange-mailboxes/</guid><pubDate>Fri, 02 Oct 2015 15:27:10 +0000</pubDate><description>&lt;p&gt;Well this is week number two in my quest to post an article once a week and I am back with a common request for Exchange administrators. There are a lot of scenarios that bring up a need to remove an e-mail or e-mails from all mailboxes in your environment. Perhaps there was a disgruntled employee, a virus outbreak, or a reply all to the whole company. We all know that the &amp;ldquo;Retract&amp;rdquo; button is best effort (yes I still miss GroupWise for that purpose).&lt;/p&gt;</description><content:encoded>&lt;![CDATA[<p>Well this is week number two in my quest to post an article once a week and I am back with a common request for Exchange administrators. There are a lot of scenarios that bring up a need to remove an e-mail or e-mails from all mailboxes in your environment. Perhaps there was a disgruntled employee, a virus outbreak, or a reply all to the whole company. We all know that the &ldquo;Retract&rdquo; button is best effort (yes I still miss GroupWise for that purpose).</p><p>As always we can turn to PowerShell for our scripting needs. The Search-Mailbox command is your best friend for these scenarios. With a simple Get-Mailbox | Search-Mailbox you can take control of all your mailboxes. Be extremely cautious when executing, with great power comes great responsibility. For a full run down on how to accomplish this head on over to<a href="http://powershellblogger.com/?p=117">PowerShellBlogger.com</a>. I look forward to seeing everyone again next week!</p>
]]></content:encoded></item></channel></rss>