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

<channel>
	<title>PowerShell Station</title>
	<atom:link href="https://powershellstation.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://powershellstation.com/</link>
	<description>Mike&#039;s PowerShell Musings</description>
	<lastBuildDate>Thu, 13 May 2021 02:19:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>New WebHost</title>
		<link>https://powershellstation.com/2021/02/09/new-webhost/</link>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Tue, 09 Feb 2021 19:06:20 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://powershellstation.com/?p=1471</guid>

					<description><![CDATA[<p>After an emergency at my previous webhost, I&#8217;ve switched to a new webhost. If you see any missing content, let me know!</p>
<p>The post <a href="https://powershellstation.com/2021/02/09/new-webhost/">New WebHost</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>After an emergency at my previous webhost, I&#8217;ve switched to a new webhost.  If you see any missing content, let me know!</p>
<p>The post <a href="https://powershellstation.com/2021/02/09/new-webhost/">New WebHost</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Dude, Where&#8217;s my Command?</title>
		<link>https://powershellstation.com/2020/09/01/dude-wheres-my-command/</link>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Wed, 02 Sep 2020 00:53:52 +0000</pubDate>
				<category><![CDATA[Scripts]]></category>
		<guid isPermaLink="false">http://powershellstation.com/?p=1443</guid>

					<description><![CDATA[<p>The Dilemma This post was inspired by a recent occurrence at work.  I have built a framework which constructs documents based on a lists of functions in a module specific to that kind of document. I found myself running into an issue where even though I knew there was a command named a certain thing, ...</p>
<p><a href="https://powershellstation.com/2020/09/01/dude-wheres-my-command/" class="more-link">Continue reading &#8216;Dude, Where&#8217;s my Command?&#8217; &#187;</a></p>
<p>The post <a href="https://powershellstation.com/2020/09/01/dude-wheres-my-command/">Dude, Where&#8217;s my Command?</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>The Dilemma</h1>
<p>This post was inspired by a recent occurrence at work.  I have built a framework which constructs documents based on a lists of functions in a module specific to that kind of document.</p>
<p>I found myself running into an issue where even though I knew there was a command named a certain thing, and that the function was correctly exported from the module, PowerShell wasn&#8217;t finding the command.</p>
<p>My code looked something like this:</p>
<pre class="brush: powershell; title: ; notranslate">
$module='Module1'
$Steps='Get-CustomerData','Get-MarketingData','New-CustomerMarketingDocument'
# each function takes a hashtable as a parameter and outputs a hashtable
$state=@{}
foreach($Step in $Steps){
    $stepCmd=Get-Command -Name $step -module $module
    $state=&amp;amp; $StepCmd -state @State
}
</pre>
<p>So why was PowerShell not working nicely for me? The problems has to do with how PowerShell loads functions. Let&#8217;s take a step back</p>
<h1>PowerShell&#8217;s Command-Loading Procedure</h1>
<p>For now, let&#8217;s assume we have a simple script module called Module1.</p>
<p>For a script module to be &#8220;discoverable&#8221; by PowerShell, it must exist in one of the folders listed in the <strong>PSModulePath</strong> environment variable.</p>
<p>This PowerShell will show you the folders that PowwerShell will look in:</p>
<pre class="brush: powershell; title: ; notranslate">$env:PSModulePath.Split(';')</pre>
<p>Here are the results from a PowerShell 7 instance:<br />
<img fetchpriority="high" decoding="async" class="alignnone wp-image-1446 size-full" src="http://powershellstation.com/wp-content/uploads/2020/09/PSModulePath.png" alt="" width="831" height="262" srcset="https://powershellstation.com/wp-content/uploads/2020/09/PSModulePath.png 831w, https://powershellstation.com/wp-content/uploads/2020/09/PSModulePath-300x95.png 300w, https://powershellstation.com/wp-content/uploads/2020/09/PSModulePath-768x242.png 768w, https://powershellstation.com/wp-content/uploads/2020/09/PSModulePath-730x230.png 730w" sizes="(max-width: 831px) 100vw, 831px" /></p>
<p>When you try to run a command (or use <strong>Get-Command</strong>), PowerShell will first look to see if the command is already loaded. IF so, then it just runs (or outputs) the command you asked for.</p>
<p>If it isn&#8217;t already present, PowerShell looks through valid modules for the function. As a reminder, valid modules:</p>
<ul>
<li>Exist in one of the folders in <strong>PSModulePath</strong></li>
<li>Have a &#8220;module file&#8221; named the same as the folder it&#8217;s in (for instance, module1\module1.psm1)</li>
<li>Module Files extensions are psm1, psd1, dll, or cdxml.</li>
<li>File is syntactically valid and not blocked</li>
</ul>
<p>If the command is present, and exported (via <strong>Export-ModuleMember</strong> and <strong>Functions/CmdletsToExport</strong> in the manifest), then the module will be loaded silently and the command (now present) will be executed or output.</p>
<p>Pretty simple, right?</p>
<p>In my case, I had a valid module, in a valid folder, in the <strong>PSModulePath</strong>, with the named function exported from it.  What could have gone wrong?</p>
<h2>PowerShell Command Hiding</h2>
<p>The problem was that I had gotten used to naming functions somewhat generically, and had duplicated one.</p>
<p>I had two modules which contained a function called <strong>Get-DocumentData.  </strong>The command discovery procedure worked fine, it just found the wrong command.</p>
<p>Let&#8217;s see an example of what I&#8217;m talking about.</p>
<p>Consider two modules, module1 and module2.</p>
<p>Module1 has a single command, <strong>Get-Stuff</strong></p>
<pre class="brush: powershell; title: ; notranslate">
function Get-Stuff{
    'in module1'
}
</pre>
<p>Similarly, Module2 has a <strong>Get-Stuff</strong> command which outputs &#8216;in module2&#8217;.</p>
<p>If I were to open a new PowerShell session and type <strong>Get-Stuff</strong>, PowerShell would find module1&#8217;s copy of Get-Stuff first and load it (that is, module1).</p>
<p>If that were the only<strong> Get-Stuff</strong>, the story would be over.</p>
<p>In this case, I have two different modules with Get-Stuff functions.</p>
<p>To get to the second, I can import the module explicitly:</p>
<pre class="brush: powershell; title: ; notranslate">Import-Module module2</pre>
<p>You can verify the output below:<br />
<img decoding="async" class="alignnone size-full wp-image-1450" src="http://powershellstation.com/wp-content/uploads/2020/09/twomodules.png" alt="" width="375" height="129" srcset="https://powershellstation.com/wp-content/uploads/2020/09/twomodules.png 375w, https://powershellstation.com/wp-content/uploads/2020/09/twomodules-300x103.png 300w" sizes="(max-width: 375px) 100vw, 375px" /></p>
<p>Now, we&#8217;ve imported both modules and executed both functions. What does Get-Command tell us?<br />
<img decoding="async" class="alignnone size-full wp-image-1451" src="http://powershellstation.com/wp-content/uploads/2020/09/get-command1.png" alt="" width="792" height="113" srcset="https://powershellstation.com/wp-content/uploads/2020/09/get-command1.png 792w, https://powershellstation.com/wp-content/uploads/2020/09/get-command1-300x43.png 300w, https://powershellstation.com/wp-content/uploads/2020/09/get-command1-768x110.png 768w, https://powershellstation.com/wp-content/uploads/2020/09/get-command1-730x104.png 730w" sizes="(max-width: 792px) 100vw, 792px" /><br />
First, it only shows us the command from module2, that is, the most recently loaded.</p>
<p>If we ask for the command from module1, we won&#8217;t find it:<br />
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-1452" src="http://powershellstation.com/wp-content/uploads/2020/09/get-command2.png" alt="" width="1048" height="178" srcset="https://powershellstation.com/wp-content/uploads/2020/09/get-command2.png 1048w, https://powershellstation.com/wp-content/uploads/2020/09/get-command2-300x51.png 300w, https://powershellstation.com/wp-content/uploads/2020/09/get-command2-1024x174.png 1024w, https://powershellstation.com/wp-content/uploads/2020/09/get-command2-768x130.png 768w, https://powershellstation.com/wp-content/uploads/2020/09/get-command2-730x124.png 730w" sizes="auto, (max-width: 1048px) 100vw, 1048px" /></p>
<p>You might notice that the error is misleading.  There sure is a <strong>Get-Stuff</strong> command available, just not from module1 (or at least not available from module1).</p>
<p>But if we ask for &#8220;all&#8221; Get-Stuff commands, there it is:<br />
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-1453" src="http://powershellstation.com/wp-content/uploads/2020/09/get-command3.png" alt="" width="791" height="144" srcset="https://powershellstation.com/wp-content/uploads/2020/09/get-command3.png 791w, https://powershellstation.com/wp-content/uploads/2020/09/get-command3-300x55.png 300w, https://powershellstation.com/wp-content/uploads/2020/09/get-command3-768x140.png 768w, https://powershellstation.com/wp-content/uploads/2020/09/get-command3-730x133.png 730w" sizes="auto, (max-width: 791px) 100vw, 791px" /></p>
<p>So, why didn&#8217;t <strong>Get-Command</strong> show it?</p>
<p>The answer (which you can read in more detail <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_command_precedence?view=powershell-5.1" target="_blank" rel="noopener noreferrer">here</a>) is that the module1 version of the command has been hidden, and <strong>Get-Command</strong> (without <strong>-All</strong>) shows commands that aren&#8217;t hidden.</p>
<p>Adding <strong>-All</strong> to our earlier search for the command works like we had expected:<br />
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-1454" src="http://powershellstation.com/wp-content/uploads/2020/09/get-command4.png" alt="" width="789" height="122" srcset="https://powershellstation.com/wp-content/uploads/2020/09/get-command4.png 789w, https://powershellstation.com/wp-content/uploads/2020/09/get-command4-300x46.png 300w, https://powershellstation.com/wp-content/uploads/2020/09/get-command4-768x119.png 768w, https://powershellstation.com/wp-content/uploads/2020/09/get-command4-730x113.png 730w" sizes="auto, (max-width: 789px) 100vw, 789px" /></p>
<p>Note that there&#8217;s another way to get a module-specific command, and that&#8217;s by using a fully-qualified command reference like <strong>module1\get-stuff</strong>:<br />
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-1456" src="http://powershellstation.com/wp-content/uploads/2020/09/fullyqualified.png" alt="" width="355" height="45" srcset="https://powershellstation.com/wp-content/uploads/2020/09/fullyqualified.png 355w, https://powershellstation.com/wp-content/uploads/2020/09/fullyqualified-300x38.png 300w" sizes="auto, (max-width: 355px) 100vw, 355px" /></p>
<p>I beat my head against this one for quite a while.  I was even considering writing a blog post about it when I read the about_command_precedence help topic (for research) and figured out the &#8220;issue&#8221;.</p>
<p>&nbsp;</p>
<p>Thanks for reading,</p>
<p>Mike</p>
<p>The post <a href="https://powershellstation.com/2020/09/01/dude-wheres-my-command/">Dude, Where&#8217;s my Command?</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Git &#8211; The 5 Percent that I Always Use</title>
		<link>https://powershellstation.com/2020/08/25/git-the-5-percent-that-i-always-use/</link>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Wed, 26 Aug 2020 03:29:30 +0000</pubDate>
				<category><![CDATA[Discussion]]></category>
		<category><![CDATA[get-learning]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[source-control]]></category>
		<guid isPermaLink="false">http://powershellstation.com/?p=1424</guid>

					<description><![CDATA[<p>One of the reasons I got into IT was that I really enjoy learning new things. Unfortunately, there are so many things to learn that it&#8217;s easy to get overwhelmed. Does it make sense to do a deep-dive into each technology that you use, or does it sometimes make sense to skim the cream off ...</p>
<p><a href="https://powershellstation.com/2020/08/25/git-the-5-percent-that-i-always-use/" class="more-link">Continue reading &#8216;Git &#8211; The 5 Percent that I Always Use&#8217; &#187;</a></p>
<p>The post <a href="https://powershellstation.com/2020/08/25/git-the-5-percent-that-i-always-use/">Git &#8211; The 5 Percent that I Always Use</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="size-medium wp-image-1435 alignright" src="http://powershellstation.com/wp-content/uploads/2020/08/320px-Git-logo.svg_-300x126.png" alt="" width="300" height="126" srcset="https://powershellstation.com/wp-content/uploads/2020/08/320px-Git-logo.svg_-300x126.png 300w, https://powershellstation.com/wp-content/uploads/2020/08/320px-Git-logo.svg_.png 320w" sizes="auto, (max-width: 300px) 100vw, 300px" />One of the reasons I got into IT was that I really enjoy learning new things. Unfortunately, there are so many things to learn that it&#8217;s easy to get overwhelmed. Does it make sense to do a deep-dive into each technology that you use, or does it sometimes make sense to skim the cream off the top and move on to the next technology?</p>
<p>In this post, I&#8217;m talking about git, the distributed source control system that is used in GitHub, Azure DevOps Repos, GitLab, and countless other places.  Git can be really complicated, and intimidating, so I&#8217;m going to try to convey the tiny fragment of git which allows me to get my work done.</p>
<h2>Just Eight Commands</h2>
<p>Here are the commands I regularly use:</p>
<ul>
<li>git clone</li>
<li>git checkout</li>
<li>git add</li>
<li>git commit</li>
<li>git push</li>
<li>git pull</li>
<li>git branch</li>
<li>(occasionally) git stash</li>
</ul>
<p>That&#8217;s it.  Eight commands.</p>
<p>Here&#8217;s how I do things.  If you&#8217;re a git guru and see ways to improve this simple workflow, let me know.  Also, know that I&#8217;m usually working on projects by myself, but I try to work like I would on a team.</p>
<h2>Starting Off</h2>
<p>To start, I clone the repository that I&#8217;m going to be working on.  For instance, if I wanted to work on WPFBot, I&#8217;d go to the github repo for it and get the URL:</p>

<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="357" height="167" class="wp-image-1426" src="http://powershellstation.com/wp-content/uploads/2020/08/image.png" alt="" srcset="https://powershellstation.com/wp-content/uploads/2020/08/image.png 357w, https://powershellstation.com/wp-content/uploads/2020/08/image-300x140.png 300w" sizes="auto, (max-width: 357px) 100vw, 357px" /></figure>

<p>With that, I can issue the command: </p>
<p><strong>git clone https://github.com/MikeShepard/WPFBot3000</strong></p>
<p>and git will copy the remote repository into a local directory called WPFBot3000 ready for me to edit.</p>
<p>If I&#8217;m starting a new project, I would create a repo (Github, AzureDevops, etc.) and clone it locally. </p>
<p>I could create it locally and push it up, but this way I only have one method to remember.</p>
<h2>Preparing for changes</h2>
<p>Before I make any changes, I need to make sure I&#8217;m on a branch dedicated to my changes. </p>
<p>If this is a new set of changes I&#8217;m working on, I can create the branch and switch to it with the command:</p>
<p><strong>git checkout -b BranchName</strong></p>
<p>(where <em>BranchName</em> is a descriptive label for the changes I&#8217;m making.</p>
<p>If the branch already exists,</p>
<p><strong>git checkout BranchName</strong></p>
<p> will switch me to the existing branch.</p>
<h2>Making Changes</h2>
<p>Making changes is easy.  I just make the changes.  I can edit files, move things around, delete files, create folders, etc.</p>
<p>As long as the changes are in the repo (the WPFBot3000 folder, in this case), git will find them. </p>
<p>There are no git commands necessary for this to happen.</p>
<h2>Staging the Changes</h2>
<p>I tell git that I&#8217;ve made changes that I like using the command</p>
<p><strong>git add .</strong></p>
<p>This says to &#8220;stage&#8221; any changes that I&#8217;ve made anywhere in the repo. </p>
<p>Staging changes isn&#8217;t &#8220;final&#8221; in any way.  It just says that these changes are ones I&#8217;m interested in.</p>
<p>As before, I could use sophisticated wildcards and parameters to pick what to stage, but by working on short-lived branches I almost always want to stage everything I&#8217;ve changed.</p>
<h2>Committing the Changes</h2>
<p>Committing the changes is like setting a milestone.  This is a point-in-time where the state of these files is &#8220;interesting&#8221;.</p>
<p>I do this using the command: <strong>git commit -m &#8216;A descriptive message about what changes I made&#8217;</strong></p>
<p>A few things to note about commits:</p>
<ol>
<li>Interesting doesn&#8217;t always mean finished. I can commit several times without pushing the code anywhere.</li>
<li>&#8220;descriptive&#8221; is subjective.  There has been a lot written about good commit messages.  Mine probably are bad.</li>
</ol>
<h2>Repeat the Cycle</h2>
<p>If I&#8217;m not done with the changes, I can continue the last 3 steps:</p>
<ul>
<li>Making Changes</li>
<li>Staging the Changes</li>
<li>Committing the Changes</li>
</ul>
<p>All of these steps are happening locally, but by committing often I have chances to roll-back to different places in time if I feel like it (I rarely do).</p>
<h2>Completing the Changes</h2>
<p>The next step is a bit of a cheat.</p>
<p>I hate remembering long git commands, so rather than remembering how to link my local branch with the remote repo, I simply say</p>
<p><strong>git push</strong></p>
<p>Git will reply with an error message because it doesn&#8217;t know what remote branch to push it to.</p>
<p>In the error message, though, it tells me how to do what I want:</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-1433" src="http://powershellstation.com/wp-content/uploads/2020/08/gitpush-1-300x57.png" alt="" width="300" height="57" srcset="https://powershellstation.com/wp-content/uploads/2020/08/gitpush-1-300x57.png 300w, https://powershellstation.com/wp-content/uploads/2020/08/gitpush-1.png 621w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>In this case, it&#8217;s </p>
<p><strong>git push &#8211;set upstream origin TEst </strong>   (and yes, branch names are case-sensitive)</p>
<h2>Pull Request</h2>
<p>At this point, I go to Azure DevOps or GitHub (I don&#8217;t use GitLab much) and browse to the repo.</p>
<p>It will usually have a notice that a branch was just changed and will give me the opportunity to create a pull request.</p>
<p>A pull request is a request to merge (or pull) changes from one branch into another.  </p>
<p>Typically, you&#8217;re merging (or pulling) changes from your branch into master.</p>
<p>Once you&#8217;ve created the pull request, this is the time for your team members to review the changes, make suggestions, and approve or deny the request.</p>
<p>If you&#8217;re working alone, you can approve the request yourself.</p>
<p>I also select the &#8220;delete the branch after merge&#8221; option so I don&#8217;t have a bunch of old branches hanging around.</p>
<p>If the merge is successful, then the changes are now part of the master branch on the remote repo.</p>
<p>They are only in my feature branch locally, though.</p>
<h2>Pulling Changes Down</h2>
<p>To get the updated master branch, I have to first switch to it:</p>
<p><strong>git checkout master<br /></strong><br /><br />Once I&#8217;m on the branch, I can</p>
<p><strong>git pull </strong></p>
<p>to pull the changes down.</p>
<h2>Cleaning up and Starting over</h2>
<p>Now that our changes are in master, I can remove the local branch with:</p>
<p><strong>git branch -d BranchName</strong></p>
<p>At this point, I don&#8217;t usually know what I&#8217;m going to work on next.</p>
<p>I have a bad habit of accidentally making changes in master locally, though so my next step helps me avoid that.</p>
<p>I simply check out a new branch called Next like this:</p>
<p><strong>git checkout -b Next</strong></p>
<p>Note: This is exactly what we did at the beginning, just with a temporary branch name of Next.</p>
<p>When I&#8217;m ready to work on a real set of changes, I can rename the branch with</p>
<p> <strong>git branch -m NewBranchName</strong></p>
<p>&nbsp;</p>
<h2>Summary</h2>
<p>That probably seemed like a lot, but here are all of the commands (with some obvious placeholders)</p>
<ul>
<li><strong>git clone &lt;url&gt;</strong></li>
<li><strong>git checkout -b BranchName</strong></li>
<li><strong>git add .</strong></li>
<li><strong>git commit -m &#8216;Fantastic commit message&#8217;</strong></li>
<li><strong>&lt;repeat add/commit until ready to push&gt;</strong></li>
<li><strong>git push    (followed by copy/paste from the error message)</strong></li>
<li><strong>&lt;proceed to create and complete the pull request&gt;</strong></li>
<li><strong>git checkout master</strong></li>
<li><strong>git pull</strong></li>
<li><strong>git branch -d BranchName</strong></li>
<li><strong>git checkout -b Next</strong></li>
</ul>
<h2>Bonus command &#8211; git stash</h2>
<p>If I find I&#8217;ve made changes in master,<strong> git stash</strong> will shelve the changes.  I can then get on the right branch and do a<strong> git stash pop</strong> to get the changes back.</p>
<p>With the adoption of the <strong>git checkout -b Next</strong> protocol, though, I don&#8217;t find myself needing this very often.</p>
<p>&nbsp;</p>
<p>What do you think?  Does this help you get your head around using git?</p><p>The post <a href="https://powershellstation.com/2020/08/25/git-the-5-percent-that-i-always-use/">Git &#8211; The 5 Percent that I Always Use</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Very Verbose PowerShell Output</title>
		<link>https://powershellstation.com/2020/08/21/very-verbose-powershell-output/</link>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Fri, 21 Aug 2020 11:50:46 +0000</pubDate>
				<category><![CDATA[Scripts]]></category>
		<guid isPermaLink="false">http://powershellstation.com/?p=1403</guid>

					<description><![CDATA[<p>Have you ever been writing a PowerShell script and wanted verbose output to show up no matter what? You may have thought of doing something like this: #Save the preference variable so you can put it back later $saveVerbosePreference=$VerbosePreference #Override the preference variable to make the output show up $VerbosePreference='Continue' Write-Verbose 'This is an important ...</p>
<p><a href="https://powershellstation.com/2020/08/21/very-verbose-powershell-output/" class="more-link">Continue reading &#8216;Very Verbose PowerShell Output&#8217; &#187;</a></p>
<p>The post <a href="https://powershellstation.com/2020/08/21/very-verbose-powershell-output/">Very Verbose PowerShell Output</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Have you ever been writing a PowerShell script and wanted verbose output to show up no matter what?</p>
<p>You may have thought of doing something like this:</p>
<pre class="brush: powershell; title: ; notranslate">
#Save the preference variable so you can put it back later
$saveVerbosePreference=$VerbosePreference

#Override the preference variable to make the output show up
$VerbosePreference='Continue'
Write-Verbose 'This is an important message you need to see'

#Leave it like you found it
$VerbosePreference=$saveVerbosePreference
</pre>
<p>If you do that, you&#8217;ll get the verbose message every time, just like you wanted.</p>
<p>Fortunately for you, there&#8217;s a much easier way to get the message:</p>
<pre class="brush: powershell; title: ; notranslate">
#By adding the -Verbose switch, you override the preference for this cmdlet
Write-Verbose 'This is an important message you need to see' -Verbose
</pre>
<p>Wasn&#8217;t that easy?</p>
<p>The post <a href="https://powershellstation.com/2020/08/21/very-verbose-powershell-output/">Very Verbose PowerShell Output</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>A PowerShell Parameter Puzzler</title>
		<link>https://powershellstation.com/2019/01/02/a-powershell-parameter-puzzler/</link>
					<comments>https://powershellstation.com/2019/01/02/a-powershell-parameter-puzzler/#comments</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Thu, 03 Jan 2019 03:33:07 +0000</pubDate>
				<category><![CDATA[Parameters]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[parameter]]></category>
		<category><![CDATA[puzzle]]></category>
		<category><![CDATA[syntax]]></category>
		<guid isPermaLink="false">http://powershellstation.com/?p=1396</guid>

					<description><![CDATA[<p>I ran across an interesting PowerShell behavior today thanks to a coworker (hi Matt!). It involved a function with just a few arguments. When I looked at the syntax something looked off. I am not going to recreate the exact scenario I found (because it involved a cmdlet written in C#), but I was able ...</p>
<p><a href="https://powershellstation.com/2019/01/02/a-powershell-parameter-puzzler/" class="more-link">Continue reading &#8216;A PowerShell Parameter Puzzler&#8217; &#187;</a></p>
<p>The post <a href="https://powershellstation.com/2019/01/02/a-powershell-parameter-puzzler/">A PowerShell Parameter Puzzler</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="size-medium wp-image-1400 alignright" style="font-family: Consolas, Monaco, monospace;" src="http://powershellstation.com/wp-content/uploads/2019/01/puzzle-308908_640-300x280.png" alt="" width="300" height="280" srcset="https://powershellstation.com/wp-content/uploads/2019/01/puzzle-308908_640-300x280.png 300w, https://powershellstation.com/wp-content/uploads/2019/01/puzzle-308908_640.png 640w" sizes="auto, (max-width: 300px) 100vw, 300px" /><br />
I ran across an interesting PowerShell behavior today thanks to a coworker (hi Matt!).</p>
<p>It involved a function with just a few arguments. When I looked at the syntax something looked off.</p>
<p>I am not going to recreate the exact scenario I found (because it involved a cmdlet written in C#), but I was able to recreate a similar issue using advanced functions.</p>
<p>So consider that you are entering a command and you see an intellisense prompt like this one:<br />
<img loading="lazy" decoding="async" class="size-medium wp-image-1397 alignnone" src="http://powershellstation.com/wp-content/uploads/2019/01/intellisense-300x251.png" alt="" width="300" height="251" srcset="https://powershellstation.com/wp-content/uploads/2019/01/intellisense-300x251.png 300w, https://powershellstation.com/wp-content/uploads/2019/01/intellisense.png 530w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>You would rightfully assume that it had 3 parameters.</p>
<p>If you looked at the syntax using Get-Help (or the -? switch) you would see something strange:</p>
<p><img loading="lazy" decoding="async" class="size-medium wp-image-1398 alignnone" src="http://powershellstation.com/wp-content/uploads/2019/01/question_syntax-300x75.png" alt="" width="300" height="75" srcset="https://powershellstation.com/wp-content/uploads/2019/01/question_syntax-300x75.png 300w, https://powershellstation.com/wp-content/uploads/2019/01/question_syntax-768x191.png 768w, https://powershellstation.com/wp-content/uploads/2019/01/question_syntax-1024x255.png 1024w, https://powershellstation.com/wp-content/uploads/2019/01/question_syntax-730x181.png 730w, https://powershellstation.com/wp-content/uploads/2019/01/question_syntax.png 1030w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>Wait&#8230;where did the other 2 parameters go?</p>
<p>Using Get-Command get-Thing -syntax shows essentially the same result:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-1399" src="http://powershellstation.com/wp-content/uploads/2019/01/get-command_syntax-300x36.png" alt="" width="300" height="36" srcset="https://powershellstation.com/wp-content/uploads/2019/01/get-command_syntax-300x36.png 300w, https://powershellstation.com/wp-content/uploads/2019/01/get-command_syntax-768x91.png 768w, https://powershellstation.com/wp-content/uploads/2019/01/get-command_syntax-730x87.png 730w, https://powershellstation.com/wp-content/uploads/2019/01/get-command_syntax.png 942w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>This was the kind of problem I ran into.  I was given a cmdlet, and when I looked at the syntax to see the parameters, I didn&#8217;t find the parameters I expected.  They were there, but they weren&#8217;t shown by Get-Command.</p>
<p>The &#8220;puzzle&#8221; is a bit less confusing when you see the code of the function:</p>
<pre class="brush: powershell; title: ; notranslate">
function get-thing {
&#x5B;CmdletBinding()]
Param(
  &#x5B;Parameter(Position=0)]$parm1,
  &#x5B;Parameter(Position=0)]$parm2,
  &#x5B;Parameter(Position=0)]$parm3
)

#nothing to see here

}
</pre>
<p>The issue arose from the overlapping position modifiers on the parameters. When those are corrected the issue goes away.</p>
<p>Note: The original instance was a bit stranger. As I mentioned earlier, the cmdlet in question was written in C#. What really surprised me was that Get-Help and Get-Command showed different syntaxes. Get-Help showed all of the parameters, while Get-Command only showed the last one.</p>
<p>The post <a href="https://powershellstation.com/2019/01/02/a-powershell-parameter-puzzler/">A PowerShell Parameter Puzzler</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://powershellstation.com/2019/01/02/a-powershell-parameter-puzzler/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>The PowerShell Conference Book</title>
		<link>https://powershellstation.com/2018/08/04/the-powershell-conference-book/</link>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sat, 04 Aug 2018 17:53:58 +0000</pubDate>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[PSConfBook]]></category>
		<category><![CDATA[WPFBot3000]]></category>
		<guid isPermaLink="false">http://powershellstation.com/?p=1385</guid>

					<description><![CDATA[<p>Back in May, Mike Robbins (@mikefrobbins) asked if I wanted to contribute a chapter to a book he was putting together. The book would include chapters from different scripters in the PowerShell community and each would provide material that would be similar to a session at a conference.In addition, the proceeds from the sale of ...</p>
<p><a href="https://powershellstation.com/2018/08/04/the-powershell-conference-book/" class="more-link">Continue reading &#8216;The PowerShell Conference Book&#8217; &#187;</a></p>
<p>The post <a href="https://powershellstation.com/2018/08/04/the-powershell-conference-book/">The PowerShell Conference Book</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" src="http://powershellstation.com/wp-content/uploads/2018/08/psconftitle-1-232x300.jpg" alt="" width="232" height="300" class="alignright size-medium wp-image-1390" srcset="https://powershellstation.com/wp-content/uploads/2018/08/psconftitle-1-232x300.jpg 232w, https://powershellstation.com/wp-content/uploads/2018/08/psconftitle-1-768x994.jpg 768w, https://powershellstation.com/wp-content/uploads/2018/08/psconftitle-1-791x1024.jpg 791w, https://powershellstation.com/wp-content/uploads/2018/08/psconftitle-1-730x945.jpg 730w, https://powershellstation.com/wp-content/uploads/2018/08/psconftitle-1.jpg 1275w" sizes="auto, (max-width: 232px) 100vw, 232px" /></p>
<p>Back in May, Mike Robbins (@mikefrobbins) asked if I wanted to contribute a chapter to a book he was putting together. The book would include chapters from different scripters in the PowerShell community and each would provide material that would be similar to a session at a conference.<br />In addition, the proceeds from the sale of the book would support the DevOpsCollective OnRamp scholarship for new IT pros going to the PowerShell and DevOps Conference in 2019.</p>
<p>Sounded like fun, so I signed on. We did the writing in markdown in a private GitHub repo. Not at all what I&#8217;m used to for writing but it was a really good experience. Mike was joined by Mike Lombardi (@barbariankb, from the STLPSUG) and Jeff Hicks (@jeffhicks). They did a great job corralling over 30 writers and at this point, the book is at 90% complete.</p>
<p>If you haven&#8217;t heard about this, go over to <a href="https://leanpub.com/powershell-conference-book">leanpub</a> and take a look. The table of contents alone should convince you that this book is worth your time.<br />My chapter, Rethinking PowerShell GUIs, went live last friday (8/3) and talks about the beginnings of WPFBot3000 and a &#8220;companion&#8221; module called ContextSensitiveMenus which I haven&#8217;t blogged about yet.</p>
<p>I would enjoy hearing feedback on my chapter and the book in general.</p>
<p>&#8211;Mike</p>
<p>The post <a href="https://powershellstation.com/2018/08/04/the-powershell-conference-book/">The PowerShell Conference Book</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PowerShell DSL Module Considerations</title>
		<link>https://powershellstation.com/2018/08/01/powershell-dsl-module-considerations/</link>
					<comments>https://powershellstation.com/2018/08/01/powershell-dsl-module-considerations/#comments</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Thu, 02 Aug 2018 02:29:57 +0000</pubDate>
				<category><![CDATA[Scripts]]></category>
		<guid isPermaLink="false">http://powershellstation.com/?p=1374</guid>

					<description><![CDATA[<p>Just a quick note to mention a couple of things I&#8217;ve come across with PowerShell modules that encapsulate DSLs (Domain Specific Languages, specifically WPFBot3000). PowerShell Command Name Warnings PowerShell modules have always issued warnings if they contain commands that don&#8217;t use approved verbs.  What&#8217;s fun with modules for DSLs is that the commands in general ...</p>
<p><a href="https://powershellstation.com/2018/08/01/powershell-dsl-module-considerations/" class="more-link">Continue reading &#8216;PowerShell DSL Module Considerations&#8217; &#187;</a></p>
<p>The post <a href="https://powershellstation.com/2018/08/01/powershell-dsl-module-considerations/">PowerShell DSL Module Considerations</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Just a quick note to mention a couple of things I&#8217;ve come across with PowerShell modules that encapsulate DSLs (Domain Specific Languages, specifically WPFBot3000).</p>
<h2>PowerShell Command Name Warnings</h2>
<p>PowerShell modules have always issued warnings if they contain commands that don&#8217;t use approved verbs.  What&#8217;s fun with modules for DSLs is that the commands in general don&#8217;t use verbs at all.  Since these commands aren&#8217;t &#8220;proper&#8221;, you might expect a warning.  You won&#8217;t get one, though.</p>
<h2>PowerShell Module Autoloading</h2>
<p>PowerShell modules have had autoloading since v3.0.  Simply put, if you use a cmdlet that isn&#8217;t present in your session PowerShell will look in all of the modules in the <strong>PSModulePath</strong> and try to find the cmdlet somewhere.  If it finds it, PowerShell imports the module quietly behind the scenes.</p>
<p>This doesn&#8217;t work out of the box with DSLs.  The reason is simple.</p>
<p>DSLs generally have commands that aren&#8217;t in the verb-noun form that PowerShell is expecting for a cmdlet, so it doesn&#8217;t try to look for the command at all.</p>
<p>The fix for this is simple (for WPFBot3000, at least).  All I&#8217;ve done is replace the two top-level commands (<strong>Window</strong> and <strong>Dialog</strong>) with well-formed cmdlet names (<strong>New-WPFBotWindow</strong> and <strong>Invoke-WPFBotDialog</strong>).  Then, I create aliases (<strong>Window</strong> and <strong>Dialog</strong>) pointing to these commands.</p>
<p>Now that I think of it, I&#8217;m not sure why that works.  If PowerShell is looking for the aliases, why wasn&#8217;t it finding the commands?  Nevertheless, it works.</p>
<p>&nbsp;</p>
<p>That&#8217;s all for today, just a couple of oddities.</p>
<p>&#8211;Mike</p>
<p>The post <a href="https://powershellstation.com/2018/08/01/powershell-dsl-module-considerations/">PowerShell DSL Module Considerations</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://powershellstation.com/2018/08/01/powershell-dsl-module-considerations/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>WPFBot3000 &#8211; Approaching 1.0</title>
		<link>https://powershellstation.com/2018/07/31/wpfbot3000-approaching-1-0/</link>
					<comments>https://powershellstation.com/2018/07/31/wpfbot3000-approaching-1-0/#comments</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Wed, 01 Aug 2018 04:23:39 +0000</pubDate>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPFBot3000]]></category>
		<guid isPermaLink="false">http://powershellstation.com/?p=1365</guid>

					<description><![CDATA[<p>I just pushed version 0.9.18 of WPFBot3000 to the PowerShell Gallery and would love to get feedback. I&#8217;ve been poking and prodding, refactoring and shuffling for the last month or so. In that time I&#8217;ve added the following: Attached Properties (like Grid.Row or Dockpanel.Top) DockPanels A separate &#8220;DataEntryGrid&#8221; to help with complex layout A ton ...</p>
<p><a href="https://powershellstation.com/2018/07/31/wpfbot3000-approaching-1-0/" class="more-link">Continue reading &#8216;WPFBot3000 &#8211; Approaching 1.0&#8217; &#187;</a></p>
<p>The post <a href="https://powershellstation.com/2018/07/31/wpfbot3000-approaching-1-0/">WPFBot3000 &#8211; Approaching 1.0</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I just pushed version 0.9.18 of WPFBot3000 to the PowerShell Gallery and would love to get feedback. I&#8217;ve been poking and prodding, refactoring and shuffling for the last month or so.</p>
<p>In that time I&#8217;ve added the following:</p>
<ul>
<li>Attached Properties (like Grid.Row or Dockpanel.Top)</li>
<li>DockPanels</li>
<li>A separate &#8220;DataEntryGrid&#8221; to help with complex layout</li>
<li>A ton of other controls (DataGrid and ListView are examples)</li>
<li>A really exciting BYOC (bring your own controls) set of functions</li>
</ul>
<p>Mostly, though, I&#8217;ve tried to focus on one thing: reducing the code needed to build a UI.</p>
<p>To that end, here are a few more additions:</p>
<ul>
<li>Variables for all named controls (no more need to GetControlByName()</li>
<li>-ShowForValue switch on Window which makes it work similarly to Dialog</li>
</ul>
<p>In case you haven&#8217;t looked at this before, here&#8217;s the easy demo:</p>
<pre class="brush: powershell; title: ; notranslate">
$output=Dialog {
    TextBox FirstName
    TextBox LastName
    Calendar Birthdate
}
'{0} {1} was born on {2}' -f $output.FirstName,$output.LastName,$output.Birthdate
</pre>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-1368 size-full" src="http://powershellstation.com/wp-content/uploads/2018/07/wpfbot3000-dataentry.png" alt="" width="256" height="282" /></p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-1369 size-full" src="http://powershellstation.com/wp-content/uploads/2018/07/wpfbot3000-dataentry-output.png" alt="" width="608" height="102" srcset="https://powershellstation.com/wp-content/uploads/2018/07/wpfbot3000-dataentry-output.png 608w, https://powershellstation.com/wp-content/uploads/2018/07/wpfbot3000-dataentry-output-300x50.png 300w" sizes="auto, (max-width: 608px) 100vw, 608px" /></p>
<p>There are tons of features to talk about, and I&#8217;ll be following up with a series of posts illustrating them.</p>
<p>In the meantime, use <strong>Install-Module WPFBot3000</strong> (or <strong>Update-Module WPFBot3000</strong>) and let me know what you think.</p>
<p>Are there things that are missing?</p>
<p>Are there things that are broken?</p>
<p>Is something difficult to do that shouldn&#8217;t be?</p>
<p>Feel free to enter issues in the <a href="https://github.com/MikeShepard/WPFBot3000">github repo</a> or let me know through twitter, email, Reddit, etc.</p>
<p>-Mike</p>
<p>The post <a href="https://powershellstation.com/2018/07/31/wpfbot3000-approaching-1-0/">WPFBot3000 &#8211; Approaching 1.0</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://powershellstation.com/2018/07/31/wpfbot3000-approaching-1-0/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Introducing WPFBot3000</title>
		<link>https://powershellstation.com/2018/07/05/introducing-wpfbot3000/</link>
					<comments>https://powershellstation.com/2018/07/05/introducing-wpfbot3000/#comments</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Fri, 06 Jul 2018 03:00:05 +0000</pubDate>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[WPFBot3000]]></category>
		<guid isPermaLink="false">http://powershellstation.com/?p=1349</guid>

					<description><![CDATA[<p>Preamble After 2 &#8220;intro&#8221; posts about writing a DSL for WPF, I decided to just bit the bullet and publish the project. It has been bubbling around in my head (and in github) for over 6 months and rather than give it out in installments I decided that I would rather just have it in ...</p>
<p><a href="https://powershellstation.com/2018/07/05/introducing-wpfbot3000/" class="more-link">Continue reading &#8216;Introducing WPFBot3000&#8217; &#187;</a></p>
<p>The post <a href="https://powershellstation.com/2018/07/05/introducing-wpfbot3000/">Introducing WPFBot3000</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Preamble</h2>
<p>After 2 &#8220;intro&#8221; posts about writing a DSL for WPF, I decided to just bit the bullet and publish the project. It has been bubbling around in my head (and in github) for over 6 months and rather than give it out in installments I decided that I would rather just have it in front of a bunch of people. You can find WPFBot3000 <a href="https://github.com/MikeShepard/WPFBot3000/">here</a>.</p>
<p><img loading="lazy" decoding="async" class="size-thumbnail wp-image-1359 alignright" src="http://powershellstation.com/wp-content/uploads/2018/07/survey-2316468_640-150x150.png" alt="" width="150" height="150" srcset="https://powershellstation.com/wp-content/uploads/2018/07/survey-2316468_640-150x150.png 150w, https://powershellstation.com/wp-content/uploads/2018/07/survey-2316468_640-300x300.png 300w, https://powershellstation.com/wp-content/uploads/2018/07/survey-2316468_640.png 640w" sizes="auto, (max-width: 150px) 100vw, 150px" /></p>
<h2>Before the code, a few remarks</h2>
<p>A few things I need to say before I get to showing example code. First, naming is hard. The repo for this has been called &#8220;WPF_DSL&#8221; until about 2 hours ago. I decided on the way home from work that it needed a better name. Since it was similar in form to my other DSL project (VisioBot3000), the name should have been obvious to me a long time ago.</p>
<p>Second, the main reasons I wrote this are:</p>
<ul>
<li>As an example of a DSL in PowerShell</li>
<li>To allow for easier creation of WPF windows</li>
<li>Because I&#8217;m really not that good at WPF</li>
</ul>
<p>In light of that last point, if you&#8217;re looking at the code in the repo and you see something particularly horrible, please enter an issue (or even better a pull request with a fix). As far as the first two go, you can be the judge after you&#8217;ve seen some examples.</p>
<h2>Installing WPFBot3000</h2>
<p>WPFBot3000 can be found in the <a href="https://www.powershellgallery.com/">PowerShell Gallery</a>, so if you want to install it for all users you can do this:</p>
<pre class="brush: powershell; title: ; notranslate">
#in an elevated session
Install-Module WPFBot3000
</pre>
<p>Or, if you want to install it for the current user only, do this:</p>
<pre class="brush: powershell; title: ; notranslate">
Install-Module WPFBot3000 -Scope CurrentUser
</pre>
<p>If you&#8217;d rather, you can clone the repo from github (it has examples and tests) and install it from the WPFBot3000 subfolder.</p>
<h2>A first example</h2>
<p>Here&#8217;s a pretty simple example that should look familiar if you read the previous posts.</p>
<pre class="brush: powershell; title: ; notranslate">
Import-Module WPFBot3000
Dialog {
   TextBox FirstName
   TextBox LastName
   TextBox EmailAddress
   DatePicker ReminderDate
}
</pre>
<p>Running that shows a window like this (the gridlines are for debugging layout and they will be going away/configurable in an upcoming release):</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-1351 size-full" src="http://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_dataEntry.png" alt="" width="498" height="211" srcset="https://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_dataEntry.png 498w, https://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_dataEntry-300x127.png 300w" sizes="auto, (max-width: 498px) 100vw, 498px" /></p>
<p>Comparing the code to the examples in the previous posts you&#8217;ll notice the main command is now <strong>Dialog</strong> rather than <strong>Window</strong>.  There is still a <strong>Window</strong> command, but it just outputs the window object.  The <strong>Dialog</strong> command uses <strong>Window</strong> to build the object (after adding an OK and Cancel Button) and then calls ShowDialog() on it.  If the user presses OK, <strong>Dialog</strong> builds an object representing the controls in the window and outputs that object.  The output object has properties that match the names of the controls* in the window:</p>
<p><img loading="lazy" decoding="async" class="size-medium wp-image-1352 alignnone" src="http://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_dataEntryResult-300x102.png" alt="" width="300" height="102" srcset="https://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_dataEntryResult-300x102.png 300w, https://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_dataEntryResult.png 325w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>* Only named controls that know how to return a value</p>
<p>You&#8217;ll also notice that <strong>DatePicker</strong> has been implemented in addition to <strong>TextBox</strong>.</p>
<p>The current list of controls that have been implemented is as follows:</p>
<ul>
<li>Button</li>
<li>CheckBox</li>
<li>ComboBox</li>
<li>CredentialPicker</li>
<li>DatePicker</li>
<li>DirectoryPicker</li>
<li>FilePicker</li>
<li>Grid</li>
<li>GridSplitter</li>
<li>Image</li>
<li>Label</li>
<li>ListBox</li>
<li>MutliLineTextBox</li>
<li>Password</li>
<li>StackPanel</li>
<li>TabControl</li>
<li>TabItem</li>
<li>TextBlock</li>
<li>TextBox</li>
<li>TreeView</li>
</ul>
<h2>Other Features</h2>
<p>I&#8217;m not going to go into every feature present (more posts to come), but here are some teasers:</p>
<ul>
<li>Context Menus</li>
</ul>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1354" src="http://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_contextMenu.png" alt="" width="566" height="177" srcset="https://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_contextMenu.png 566w, https://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_contextMenu-300x94.png 300w" sizes="auto, (max-width: 566px) 100vw, 566px" /></p>
<ul>
<li>Event Handlers</li>
</ul>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1355" src="http://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_event.png" alt="" width="494" height="248" srcset="https://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_event.png 494w, https://powershellstation.com/wp-content/uploads/2018/07/WPFBot3000_event-300x151.png 300w" sizes="auto, (max-width: 494px) 100vw, 494px" /></p>
<ul>
<li>Changing Properties (but not attached or derived properties yet)</li>
</ul>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1357" src="http://powershellstation.com/wp-content/uploads/2018/07/WPF3000_properties.png" alt="" width="567" height="73" srcset="https://powershellstation.com/wp-content/uploads/2018/07/WPF3000_properties.png 567w, https://powershellstation.com/wp-content/uploads/2018/07/WPF3000_properties-300x39.png 300w" sizes="auto, (max-width: 567px) 100vw, 567px" /></p>
<p>That&#8217;s enough for tonight, but I&#8217;ll be posting more in the days and weeks to come.</p>
<p>Let me know what you think. Feel free to post</p>
<p>The post <a href="https://powershellstation.com/2018/07/05/introducing-wpfbot3000/">Introducing WPFBot3000</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://powershellstation.com/2018/07/05/introducing-wpfbot3000/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>A PowerShell WPF DSL (Part 2) &#8211; Getting Control Values</title>
		<link>https://powershellstation.com/2018/06/29/a-powershell-wpf-dsl-part-2-getting-control-values/</link>
					<comments>https://powershellstation.com/2018/06/29/a-powershell-wpf-dsl-part-2-getting-control-values/#comments</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sat, 30 Jun 2018 03:10:45 +0000</pubDate>
				<category><![CDATA[Scripts]]></category>
		<guid isPermaLink="false">http://powershellstation.com/?p=1344</guid>

					<description><![CDATA[<p>Some Background Before I start, I should probably take a minute to explain what a DSL is and why you would want to use one. A DSL (domain-specific language) is a (usually small) language where the vocabulary comes from a specific problem domain (or subject).  Note that this has nothing to do with Active Directory ...</p>
<p><a href="https://powershellstation.com/2018/06/29/a-powershell-wpf-dsl-part-2-getting-control-values/" class="more-link">Continue reading &#8216;A PowerShell WPF DSL (Part 2) &#8211; Getting Control Values&#8217; &#187;</a></p>
<p>The post <a href="https://powershellstation.com/2018/06/29/a-powershell-wpf-dsl-part-2-getting-control-values/">A PowerShell WPF DSL (Part 2) &#8211; Getting Control Values</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Some Background</h2>
<p>Before I start, I should probably take a minute to explain what a DSL is and why you would want to use one.</p>
<p>A <strong>DSL</strong> (domain-specific language) is a (usually small) language where the vocabulary comes from a specific problem domain (or subject).  Note that this has nothing to do with Active Directory domains, so that might have been confusing.</p>
<p>By using words that are naturally used in describing problems in this subject, it is possible to write using the DSL in ways that look less like programming and more like describing the solution.</p>
<p>For instance, in Pester, you might write part of a unit test like this (3.0 syntax):</p>
<pre class="brush: powershell; title: ; notranslate">
It &quot;Has a non-negative result&quot; {
   $result | Should Be GreaterThan 0
}
</pre>
<p>There are some aspects of this that look like PowerShell (the $, the | and the {}), but in general it doesn&#8217;t look much like code. It looks more like a description of the test that we&#8217;re writing.</p>
<p>In the WPF DSL that I&#8217;m describing in these posts, I want to be able to write PowerShell scripts that create WPF applications in a way that the &#8220;WPF&#8221; part of the script is easy. At least, a lot easier than trying to generate XAML or automate the WPF classes using brute force. That being said, the code in my DSL is not some sort of magic, it&#8217;s just PowerShell code.</p>
<p>One interesting aspect of DSLs is that because they don&#8217;t look quite like code, they often ignore coding conventions. Note that the Pester example had a PowerShell cmdlet called &#8220;It&#8221;. No verb-noun convention followed there. Also, Using positional parameters is more common in a DSL. Not a problem, just something to be aware of.</p>
<h2>Getting Control Values</h2>
<p>One of the problems I listed at the end of the <a href="http://powershellstation.com/2018/06/28/starting-a-powershell-dsl-for-wpf-apps/">previous post</a> (#3) was that reading the text property won&#8217;t work once we have other controls to think about besides textboxes.</p>
<p>My solution here has worked out really well. I decided to add a method to any control that I would want to get a value from. The method is called GetControlValue. It is responsible for knowing how to get the values from the control (which, as part of the control object it will have no problem with).</p>
<p>Here&#8217;s the updated <strong>Textbox</strong> function:</p>
<pre class="brush: powershell; title: ; notranslate">
function TextBox {
    &#x5B;CmdletBinding()]
    Param($Name)
    $Properties = @{ Name = $name ;MinWidth=100}
    New-Object System.Windows.Controls.TextBox -Property $properties | 
        Add-Member -Name GetControlValue -MemberType ScriptMethod -Value {$this.Text} -PassThru
}
</pre>
<p>Since it&#8217;s a ScriptMethod, we get to use <strong>$this</strong> to refer to the control, so <strong>$this.Text</strong> is the value we want.</p>
<p>With that in place, we need to update the If statement at the end of the Window function to use the ScriptMethod. Here&#8217;s what it looks like:</p>
<pre class="brush: powershell; title: ; notranslate">
if($window.ShowDialog() -or $true){
if($window.ShowDialog() -or $true){
  $output=&#x5B;Ordered]@{}
  foreach($item in $controls){
    $output&#x5B;$item.Name]=$item.GetControlValue()
  }
  &#x5B;PSCustomObject]$output
}
</pre>
<h2>Conclusion</h2>
<p>Here&#8217;s the checklist now:</p>
<ol>
<li>Only textboxes? Need several other controls</li>
<li>OK/Cancel</li>
<li><del datetime="2018-06-30T03:08:35+00:00">With other controls, reading the text property won’t be a strategy</del></li>
<li>Nested controls</li>
<li>Populating controls</li>
<li>Events</li>
<li>ContextMenus</li>
<li>Setting control properties</li>
</ol>
<p>Stay tuned for more&#8230;</p>
<p>&#8211;Mike</p>
<p>The post <a href="https://powershellstation.com/2018/06/29/a-powershell-wpf-dsl-part-2-getting-control-values/">A PowerShell WPF DSL (Part 2) &#8211; Getting Control Values</a> appeared first on <a href="https://powershellstation.com">PowerShell Station</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://powershellstation.com/2018/06/29/a-powershell-wpf-dsl-part-2-getting-control-values/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
