<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>ngetchell.com - Posts tagged with &quot;PowerShell&quot;</title><description>All blog posts tagged with &quot;PowerShell&quot;</description><link>https://ngetchell.com/</link><item><title>Fun with Certificates</title><link>https://ngetchell.com/blog/fun-with-certificates/</link><guid isPermaLink="true">https://ngetchell.com/blog/fun-with-certificates/</guid><description>Disect certificates for fun and profit.</description><pubDate>Mon, 12 Feb 2024 11:59:41 GMT</pubDate><content:encoded>
&lt;p&gt;After years of running websites, I&apos;ve come across a few simple tricks to help to deal with certificates.
This post is as much for me as it is for the internet. 
I always have issues rewriting or rediscovering this stuff and figured I&apos;d post it so I don&apos;t forget it.&lt;/p&gt;



&lt;h2&gt;Inspecting a Certificate File&lt;/h2&gt;



&lt;p&gt;If you have a local certificate you&apos;d like to inspect, I use openssl to interrogate the file.
This will decode the base64 encoding of the certificate in human readable form.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;openssl&lt;/span&gt;&lt;span&gt; x509&lt;/span&gt;&lt;span&gt; -in&lt;/span&gt;&lt;span&gt; ngetchell.com.cer&lt;/span&gt;&lt;span&gt; -text&lt;/span&gt;&lt;span&gt; -noout&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Slap a &lt;code&gt;| grep After&lt;/code&gt; to the command to get a quick readout of the certificate expiration date.&lt;/p&gt;



&lt;h2&gt;Retrieving Certificate Information from a Web Server&lt;/h2&gt;



&lt;p&gt;Every once in a while, you need to determine the state of an TLS certificate.
&lt;a href=&quot;https://www.ssllabs.com/ssltest/&quot;&gt;SSL Labs&lt;/a&gt; provides a comprehensive inspection of a given site, but it does come with some limits.
For one, it will only check a web server sitting on port 443.
Another is, you have to do it all one at a time.&lt;/p&gt;



&lt;p&gt;If you don’t need to delve deep into the security of the web server, or you need to rapidly iterate through a list of domains, you can use this.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Function&lt;/span&gt;&lt;span&gt; Get-TLSCertificate&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    [&lt;/span&gt;&lt;span&gt;CmdletBinding&lt;/span&gt;&lt;span&gt;()]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    param&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $DomainName&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $Port&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $request &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;System.Net.Sockets.TcpClient&lt;/span&gt;&lt;span&gt;]::new($DomainName&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; $Port)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $stream &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;System.Net.Security.SslStream&lt;/span&gt;&lt;span&gt;]::new($request.GetStream())&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $stream.AuthenticateAsClient($DomainName)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    [&lt;/span&gt;&lt;span&gt;PSCustomObject&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;@&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        DomainName &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $DomainName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        Port &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $Port&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        TargetHostname &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $stream.TargetHostName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        Subject &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $stream.RemoteCertificate.Subject&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        Thumbprint &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $stream.RemoteCertificate.Thumbprint&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        NotAfter &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $stream.RemoteCertificate.NotAfter&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        NotBefore &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $stream.RemoteCertificate.NotBefore&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        ExpirationCountdown &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;New-TimeSpan&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;end $stream.RemoteCertificate.NotAfter &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;start &lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;Get-Date&lt;/span&gt;&lt;span&gt;) ).Days&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        Issuer &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $stream.RemoteCertificate.Issuer&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        TLSProtocol &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $stream.SslProtocol&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        NegotiatedCipherSuite &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $stream.NegotiatedCipherSuite&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        SignatureAlgorithm &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $stream.RemoteCertificate.SignatureAlgorithm.FriendlyName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        Extensions &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; @&lt;/span&gt;&lt;span&gt;($stream.RemoteCertificate.Extensions.oid.friendlyname &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; select &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;unique )&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Get-TLSCertificate&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;DomainName ngetchell &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Port &lt;/span&gt;&lt;span&gt;443&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;I&apos;ve used this during mass certificate rotations to confirm we&apos;d done our job.
When migrating from one wildcard certificate to another, it is important to double-check your work.
We started with an export of our DNS zone and iterated through each sub-domain to make sure the thumbprint changed.
It caught a few that we thought we&apos;d switched but missed for whatever reason.
The script also helped to unearth some services that we believed were behind a load balancer but turns out were not.&lt;/p&gt;



&lt;h2&gt;Generating a CSR from a template file&lt;/h2&gt;



&lt;p&gt;As more and more services support the ACME protocol, manually generating certificate signing requests becomes less and less useful.
Still, there are times you need to know how to generate a certificate.
This template also allows you to add additional Subject Alternative Names, which is useful if your service is known by many names.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;default_bits = 2048&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;default_keyfile = /etc/path/to/private.key&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;encrypt_key = no&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;default_md = sha256&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;prompt = no&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;utf8 = yes&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;distinguished_name = my_req_distinguished_name&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;req_extensions = my_extensions&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;[ my_req_distinguished_name ]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;C = US&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;ST = Parts Unknown&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;L = Death Valley&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;O  = Blog&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;CN = gitlab-web.example.com&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;[ my_extensions ]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;basicConstraints=CA:FALSE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;subjectAltName=@my_subject_alt_names&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;subjectKeyIdentifier = hash&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;[ my_subject_alt_names ]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;DNS.1 = gitlab-web.example.mobile&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;DNS.2 = gitlab-web.example.net&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;To invoke the template, you run the following.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;openssl&lt;/span&gt;&lt;span&gt; req&lt;/span&gt;&lt;span&gt; -new&lt;/span&gt;&lt;span&gt; -out&lt;/span&gt;&lt;span&gt; example.csr&lt;/span&gt;&lt;span&gt; -config&lt;/span&gt;&lt;span&gt; csr.conf&lt;/span&gt;&lt;span&gt; -key&lt;/span&gt;&lt;span&gt; private.key&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content:encoded><category>OpenSSL</category><category>PowerShell</category><category>TLS</category></item><item><title>My PowerShell Journey</title><link>https://ngetchell.com/blog/my-powershell-journey/</link><guid isPermaLink="true">https://ngetchell.com/blog/my-powershell-journey/</guid><description>How my career changed by learing powershell</description><pubDate>Mon, 11 Dec 2023 11:00:12 GMT</pubDate><content:encoded>
&lt;p&gt;As I look back on my sixteen years in information technology, I can&apos;t help but notice the impact PowerShell has had on my career.&lt;/p&gt;



&lt;h2&gt;First Automation&lt;/h2&gt;



&lt;p&gt;My first automations were little batch scripts and AutoHotKey plays.
They did trival tasks like opening multiple Internet Explorer windows and the Active Directory Users and Computers tool to quickly get myself up and running at work.
I&apos;d share them with my coworkers while sitting at a college helpdesk.&lt;/p&gt;



&lt;p&gt;The college systems team asked me to not automate the password reset and to only use the GUI.
They probably saw me for what I was, someone too green to know the potential blast radius of an errant script.&lt;/p&gt;



&lt;p&gt;In my next job at a different college, colleagues viewed my thirst for automation with apathy instead of derision.
You can accomplish a lot in an apathetic setting, as long as you don&apos;t make work for others. &lt;/p&gt;



&lt;p&gt;We had a manual process to generate student accounts.
At this two year institution, we would have around six thousand students registered.
That means, we would turn over about a quarter of the student population every semester (weighed heavily for fall over spring).
This meant that lots of student accounts would need to be created throughout the school year.&lt;/p&gt;



&lt;p&gt;Someone on our helpdesk would copy a file to a domain controller (I know), and load users via a Windows 2000 executable that was copied to a Windows 2003 server.
One person was assigned that task.
When they were out, no student accounts were created.&lt;/p&gt;



&lt;p&gt;I had our Saturday shift on the helpdesk so I threw myself at automating this task.
We could generate csv files from our student information system,   so I fired up Google to see how to process entries in the file.
I found PowerShell through this task and it changed the trajectory of my career.
Importing a csv in PowerShell v2 was a breeze.
Mapping those entries to the Add-ADUser commandlet took no time at all.
Building out the logic needed to update existing users wasn&apos;t much harder.&lt;/p&gt;



&lt;p&gt;It was then that I came to understand the power of automation.&lt;/p&gt;



&lt;h2&gt;Learning Git&lt;/h2&gt;



&lt;p&gt;Once I realized that my scripts were &lt;em&gt;load-bearing&lt;/em&gt;, I figured I needed to store it in a VCS.
In college, I would constantly hack at my programs until they worked.
This brute-force style meant that at some point, my iterating would eventually go off the rails and I needed a way to get back to a known-good state.
The PowerShell community would always mention Git as the go to source control.&lt;/p&gt;



&lt;p&gt;I immediately saw the utility to staging and commit work.
Where previously I was hesitant to iterate, I could now experiment to my heart&apos;s content.&lt;/p&gt;



&lt;p&gt;The Pro Git book by Scott Chacon and Ben Straub was a great resource.
I still read it every few years as a refresher, as I still seem to pull out new tricks on each reread.&lt;/p&gt;



&lt;h2&gt;90 Hours of Training and Month of Lunches&lt;/h2&gt;



&lt;p&gt;It was around this time that I convinced my employer to get me a subscription to CBT Nuggets, where I soon found Don Jones&apos;s 90 hours of PowerShell trainings.
They were still releasing them and I soon caught up as they were released.
My Saturday shifts went towards bettering myself and my career.
Those videos were time well spent.
Don taught me how to program that finally clicked for me.&lt;/p&gt;



&lt;p&gt;I soon bought the Learn PowerShell in a Month of Lunches and PowerShell Toolmaking in a Month of Lunches.
The CBT Nuggets course overlapped a bit, but it helped me gain a better understanding of designing tools for users.&lt;/p&gt;



&lt;h2&gt;Open Source&lt;/h2&gt;



&lt;p&gt;Once I got used to committing, adding, and pushing code, I figured I&apos;d start participating in open source.
I built &lt;a href=&quot;https://github.com/ngetchell/PSPushover&quot;&gt;tooling around the Pushover API&lt;/a&gt; which I still use today.&lt;/p&gt;



&lt;p&gt;&lt;a href=&quot;https://github.com/ngetchell/psgitlab&quot;&gt;PSGitLab&lt;/a&gt; would be my first real foray into managing an open source project. 
It eventually went on to have 14 contributors, some offering up thousands of lines of code to my project.
I learned so much about managing that project and I am the better developer for it.
Development on that project fell off with the birth of my daughter while I was finishing up my degree.&lt;/p&gt;



&lt;h2&gt;Hosting TechSessions&lt;/h2&gt;



&lt;p&gt;Through &lt;a href=&quot;https://powershell.org&quot;&gt;PowerShell.org&lt;/a&gt; I volunteered to edit some of their books and to maintain them over-time.
I can no longer find them, but I remember working on the HTML reporting one.
Update 2023-12-12: James Petty over at PowerShell.org reached out and pointed me to &lt;a href=&quot;https://leanpub.com/creatinghtmlreportsinwindowspowershell&quot;&gt;Creating HTML Reports in Windows PowerShell&lt;/a&gt;.
Not sure if my name is mentioned in it anymore but there it is!&lt;/p&gt;



&lt;p&gt;From there, I began hosting the &lt;a href=&quot;https://www.youtube.com/playlist?list=PLfeA8kIs7Cockjl15f_iEfm3_p2KJIoPZ&quot;&gt;TechSession&lt;/a&gt; webinars for the site.
There, I got to chat with community members like Don Jones, Jason Helmick, Dave Wyatt, Steven Murawski, Mike F. Robbins, and others.&lt;/p&gt;



&lt;h2&gt;PowerShell Summit of 2015&lt;/h2&gt;



&lt;p&gt;My trip to the summit began with my employer, sending me off to Charlotte to attend.
I was able to put faces to the names I&apos;d bumped into over the years.
The content was great, the side conversations were out of this world, and I loved the entire experience.&lt;/p&gt;



&lt;p&gt;Mike F. Robbins did a great talk on setting up your own PS repository for your modules.
Dave Wyatt went over storing credentials securely.
There was talks about paralellism from a technician that oversees thousands of servers at an ISP.&lt;/p&gt;



&lt;p&gt;I even got to meet Jeffrey Snover.
Twice.
One time I got to share a beer with him.
He is funnier in person than he is online or in his talks, which I didn&apos;t think was possible.&lt;/p&gt;



&lt;h2&gt;Other Thoughts&lt;/h2&gt;



&lt;p&gt;PowerShell has been good for me.
Being a computer science dropout, it was satisfying to overcome the beginner stage and delve deep into a programming language.
Solving actual issues while learning new concepts. 
Now, I&apos;m able to bounce between a few languages and am dangerous in a few others.
I don&apos;t think I would have had the career, the job satisfaction, or the fun without PowerShell.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Monitoring Cron and Scheduled Tasks With Healthchecks.io</title><link>https://ngetchell.com/blog/monitoring-cron-and-scheduled-tasks-with-healthchecksio/</link><guid isPermaLink="true">https://ngetchell.com/blog/monitoring-cron-and-scheduled-tasks-with-healthchecksio/</guid><description>Keeping an eye on web servers that stop serving pages or hard drive that fill up are monitoring basics.</description><pubDate>Mon, 18 Sep 2023 11:38:51 GMT</pubDate><content:encoded>
&lt;p&gt;Keeping an eye on web servers that stop serving pages or hard drive that fill up are monitoring basics. 
Check for a state,  do a little computation, or check a threshold is pretty simple to understand. 
Most monitoring applications give you the ability to make sure a Scheduled Tasks returns a zero exit code, but what happens when the task never runs?
You want to monitor the lack of an event.
This is where Healthchecks.io comes into play. &lt;/p&gt;



&lt;p&gt;I found HealthChecks.io while recovering from a personal data loss. 
My backups hadn&apos;t run in months and while the data wasn&apos;t important, it was tedious to restore everything back to working order.
What I needed was a &lt;a href=&quot;https://en.wikipedia.org/wiki/Dead_man%27s_switch&quot;&gt;dead man&apos;s switch&lt;/a&gt;.
Lesson learned.&lt;/p&gt;



&lt;h2&gt;Configure&lt;/h2&gt;



&lt;p&gt;To add a check, click the big green button.
You&apos;ll be greeted with a screen to configure your check.
Give it a good name.
This is part of the notification you&apos;ll receive.&lt;/p&gt;



&lt;figure&gt;&lt;img src=&quot;https://ngetchell.com/wp-media/2026/07/monitor-create-screenshot.png&quot; alt=&quot;HealthChecks.io&quot; /&gt;&lt;/figure&gt;



&lt;p&gt;Healthcheck gives you examples to get you started.
Pretty much any language you&apos;d want to start from.&lt;/p&gt;



&lt;figure&gt;&lt;img src=&quot;https://ngetchell.com/wp-media/2026/07/monitor-examples.png&quot; alt=&quot;Examples in various programming languages&quot; /&gt;&lt;/figure&gt;



&lt;p&gt;They offer tons of integrations so you can connect your favorite apps up to receive the alerts.
You can even hook it up to OpsGenie or PagerDuty as part of an on-call rotation.
I&apos;m partial to Pushover.&lt;/p&gt;



&lt;figure&gt;&lt;img src=&quot;https://ngetchell.com/wp-media/2026/07/monitor-integrations.png&quot; alt=&quot;List of integrations&quot; /&gt;&lt;/figure&gt;



&lt;p&gt;You can &lt;a href=&quot;https://healthchecks.io/docs/measuring_script_run_time/&quot;&gt;time the duration of a job&lt;/a&gt; if you use the &lt;code&gt;/start&lt;/code&gt; endpoint at the beginning of your script.&lt;/p&gt;



&lt;p&gt;The &lt;a href=&quot;https://healthchecks.io/pricing/&quot;&gt;free plan gives you a generous 20 checks&lt;/a&gt;.
They offer a &lt;a href=&quot;https://healthchecks.io/docs/self_hosted/&quot;&gt;self-hosting&lt;/a&gt; option.
This should allow you to keep track of your cron jobs or automated tasks.
I use it to make sure my hugo blog is completely rebuilt on a weekly basis.
The possibilities are endless.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Expiring Group Memberships</title><link>https://ngetchell.com/blog/expiring-group-memberships/</link><guid isPermaLink="true">https://ngetchell.com/blog/expiring-group-memberships/</guid><description>Take advantage of the new AD feature of expiring group memberships</description><pubDate>Wed, 13 Feb 2019 11:00:00 GMT</pubDate><content:encoded>
&lt;p&gt;As a systems administrator working with Active Directory your probably proficient in granting access to network resources.
How good are you at &lt;em&gt;removing&lt;/em&gt; permissions once the access is no longer needed?
Probably not as good. Enter Expiring Group Membership in Active Directory.
You can specify how long an object belongs in a group.
Active Directory handles the removal for you.&lt;/p&gt;



&lt;p&gt;To use Expiring Group Memberships, make sure that the feature is enabled in your forest.
This is a feature added in Server 2016 and is not on by default.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;## If Enabled EnabledScopes &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;## won&apos;t be empty&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Forest &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-ADForest&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Get-ADOptionalFeature&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Identity &lt;/span&gt;&lt;span&gt;&apos;Privileged Access Management Feature&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;## Enable Privileged Access&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$enableADOptionalFeatureSplat &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; @&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Scope &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;ForestOrConfigurationSet&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Target &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $Forest&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Identity &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;Privileged Access Management Feature&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Enable-ADOptionalFeature&lt;/span&gt;&lt;span&gt; @enableADOptionalFeatureSplat&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Existing groups should work but if you don&apos;t have one, create a group now.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$newADGroupSplat &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; @&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    GroupCategory &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;Security&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    DisplayName &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &quot;Temporary Membership&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    GroupScope &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;Global&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Name &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;TempGroup&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;New-ADGroup&lt;/span&gt;&lt;span&gt; @newADGroupSplat&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Now add the membership using the MemberTimeToLive parameter.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$addADGroupMemberSplat &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; @&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Members &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;ngetchell&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    MemberTimeToLive &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; ( &lt;/span&gt;&lt;span&gt;New-Timespan&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Days &lt;/span&gt;&lt;span&gt;365&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Identity &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;TempGroup&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Add-ADGroupMember&lt;/span&gt;&lt;span&gt; @addADGroupMemberSplat&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h3&gt;Expiring Membership Report&lt;/h3&gt;



&lt;p&gt;Now to generate a report to show off a members and their membership timespan. You could even &lt;a href=&quot;https://ngetchell.com/export-to-excel/&quot;&gt;pipe to Excel&lt;/a&gt; if you&apos;d prefer.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-ADGroup&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Identity TempGroup &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;ShowMemberTimeToLive &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Properties members &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ExpandProperty members &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    ForEach-Object&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    if&lt;/span&gt;&lt;span&gt; ( &lt;/span&gt;&lt;span&gt;$_&lt;/span&gt;&lt;span&gt; -match&lt;/span&gt;&lt;span&gt; &apos;&amp;lt;TTL=&apos;&lt;/span&gt;&lt;span&gt; ) {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $ttlstring&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; $DN &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $_&lt;/span&gt;&lt;span&gt; -split&lt;/span&gt;&lt;span&gt; &apos;&amp;gt;&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;int&lt;/span&gt;&lt;span&gt;]$ttl &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $ttlstring &lt;/span&gt;&lt;span&gt;-replace&lt;/span&gt;&lt;span&gt; &apos;&amp;lt;TTL=&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $Timespan &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; New-Timespan&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Seconds $ttl&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;pscustomobject&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;@&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            MemberDN   &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $DN &lt;/span&gt;&lt;span&gt;-replace&lt;/span&gt;&lt;span&gt; &quot;^,&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; &quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            TTL        &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $Timespan&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            ExpirypublishDate:&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;((&lt;/span&gt;&lt;span&gt;Get-Date&lt;/span&gt;&lt;span&gt;).Add($Timespan))&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        } &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    else&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;pscustomobject&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;@&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            MemberDN   &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $_&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            TTL        &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            ExpirypublishDate:&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        } &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;} &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Export-Excel&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path ~\Desktop\ExpiringGroupMembers.xlsx&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content:encoded><category>PowerShell</category></item><item><title>Logging PowerShell Scripts</title><link>https://ngetchell.com/blog/logging-powershell-scripts/</link><guid isPermaLink="true">https://ngetchell.com/blog/logging-powershell-scripts/</guid><description>As you progress from running commands at the console, to scripting tedious work, to automating entire processes you still need to keep an eye on whats running. Nobody likes figuring out what went wrong on in a process by debugging your script. You should integrate logging into any scripts that run unattended. Logging saves time […]</description><pubDate>Wed, 23 Jan 2019 09:21:39 GMT</pubDate><content:encoded>
&lt;p&gt;As you progress from running commands at the console, to scripting tedious work, to automating entire processes you still need to keep an eye on whats running.
Nobody likes figuring out what went wrong on in a process by debugging your script.
You should integrate logging into any scripts that run unattended.
Logging saves time and helps surface errors in your scripts.
Luckily, saving to a log file in PowerShell is simple.&lt;/p&gt;



&lt;h2&gt;Out-File&lt;/h2&gt;



&lt;p&gt;Out-file is a very simple way to handle writing to a file.
Simply put Out-File at the end of your pipeline to save output to a file.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$File &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &quot;~\Desktop\Out-File.log&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&apos;[Error]: Service failed to restart&apos;&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Out-File&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;File $File &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Append&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You can also catch errors and put the contents of the error into a file.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$File &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &quot;~\Desktop\Out-File.log&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;try&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Invoke-RestMethod&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;URI &lt;/span&gt;&lt;span&gt;&apos;https://doesnotexist&apos;&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ErrorAction Stop&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;} &lt;/span&gt;&lt;span&gt;catch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $ErrorOutput &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $_&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $ErrorOutput &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Out-File&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;File $File &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Append&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;Tee-Object&lt;/h2&gt;



&lt;p&gt;The &lt;a href=&quot;https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-6&quot;&gt;Tee-Object&lt;/a&gt; cmdlet allows you to split the direction of the pipeline.
If you have a Linux background this will sound familar.
The pipeline output still continues on but you can save off pipeline output into a file.
This makes it easy to see what&apos;s going on when your at the console since the output still appears on the screen but you can still save output for later viewing.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$File &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &quot;~\Desktop\Tee-Object.log&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Result &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name PowerShell &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Tee-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;FilePath $File &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Append &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Result &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Property Name&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;CPU&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;ID &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Tee-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;FilePath $File &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Append&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You can see that the first command saves the output of Get-Process to both the file on your desktop as well as in the $Results variable.
Then, we pipe the previous results out, manipulate the output via Select-Object, then call Tee-Object again.
This time, the output goes to the console window as well as the log file.&lt;/p&gt;



&lt;p&gt;Using Tee-Object is a great way to keep pipeline output in the console and in a permanent log.
As with Out-File, remember to use the -Append parameter.
You probably don’t want to overwrite the log file with each write.&lt;/p&gt;



&lt;h2&gt;Write to the Event Log&lt;/h2&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$Logname &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;Getchell.org&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Source &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;Automated Script&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$NewLog &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; @&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Logname &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $Logname&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Source &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $Source&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;try&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    New-EventLog&lt;/span&gt;&lt;span&gt; @NewLog &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;ErrorAction Stop&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;} &lt;/span&gt;&lt;span&gt;catch&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;System.InvalidOperationException&lt;/span&gt;&lt;span&gt;] {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    # Ignore if source already exists&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$InformationalLog &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; @&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Logname &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $Logname&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Source &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $Source&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    EntryType &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;Information&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Message &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;Verbose informational message&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    EventId &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; 19&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Write-EventLog&lt;/span&gt;&lt;span&gt; @InformationalLog&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;Other Considerations&lt;/h2&gt;



&lt;h3&gt;Object Serialization&lt;/h3&gt;



&lt;p&gt;Working with objects can be a pain to format for logging purposes.
If you use the default pipeline view, you &lt;a href=&quot;https://ngetchell.com/posts/never-lose-work/&quot;&gt;may lose data due to the PowerShell formatting system&lt;/a&gt;.
A quick way to get around this is to pipe out to ConvertTo-Json &lt;em&gt;before&lt;/em&gt; writing the pipeline to a log.
This will serialize the object so it can be written to disk without data loss.
ConvertTo-Json will also expand any nested properties, something &lt;code&gt;Select-Object -Property *&lt;/code&gt; and the &lt;code&gt;Format-*&lt;/code&gt; cmdlets won&apos;t do.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$File &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &quot;~\Desktop\object-json.log&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Get-Service&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name BITS &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    ConvertTo-Json&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Tee-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;FilePath $File &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Append&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h3&gt;Log Filenames&lt;/h3&gt;



&lt;p&gt;Another thing to consider is to name logs with timestamp data.
If you ever have to debug your automated script you’ll thank yourself later for keeping each run of your process in separate files.
I usually use the following convention:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$Log &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &quot;.\log\process-name-&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;( &lt;/span&gt;&lt;span&gt;Get-Date&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Format FileDateTime )&lt;/span&gt;&lt;span&gt;.log&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Get-Date has a built-in format that keeps invalid characters out a date/time string for use with filenames.
I reference this &lt;em&gt;constantly&lt;/em&gt;.&lt;/p&gt;



&lt;h3&gt;Viewing Logs in Real-Time&lt;/h3&gt;



&lt;p&gt;I prefer to keep logs as files as I have more experience with grep and with the Event Viewer.
For log running processes I &lt;a href=&quot;https://ngetchell.com/posts/logging-powershell-scripts/&quot;&gt;tail the open log files&lt;/a&gt; to see progress in real-time.
This is great for debugging scheduled tasks where you aren&apos;t at the console.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Get-Command -Syntax vs Get-Help</title><link>https://ngetchell.com/blog/get-command-vs-get-help/</link><guid isPermaLink="true">https://ngetchell.com/blog/get-command-vs-get-help/</guid><description>Wait, is Get-Help or Get-Command right? At the PowerShell Summit 2015 I witnessed Lee Holmes state that Get-Command is always the better way to look up the syntax of a cmdlet. What did he mean by that? Get-Help and Get-Command are two of the only three cmdlets you need to know. The other being Get-Member. […]</description><pubDate>Wed, 12 Dec 2018 09:00:00 GMT</pubDate><content:encoded>
&lt;p&gt;Wait, is Get-Help or Get-Command right? At the PowerShell Summit 2015 I witnessed Lee Holmes state that Get-Command is always the better way to look up the syntax of a &lt;a href=&quot;https://ngetchell.com/blog/intro-to-cmdlets/&quot;&gt;cmdlet&lt;/a&gt;.
What did he mean by that? Get-Help and Get-Command are two of the only three cmdlets you need to know.
The other being Get-Member.
Why do you need both Get-Command AND Get-Help?&lt;/p&gt;



&lt;p&gt;A quick glance at the output of both commands reveals that the syntax parameter for Get-Command is similar to the help provided by Get-Help.
Their function is very similar but derive their information from slightly different sources.
When they show conflicting information, which one is correct?&lt;/p&gt;



&lt;h2&gt;Get-Help Limitations&lt;/h2&gt;



&lt;p&gt;To understand the limitations of Get-Help, you need to know where Get-Help gets it&apos;s content from.
Get-Help shows the MAML or Comment-Based help written by the module author.
It may also show generic help populated by PowerShell at run time.
PowerShell will attempt to give you &lt;em&gt;something&lt;/em&gt; when you ask for help on a cmdlet that doesn&apos;t provide any.&lt;/p&gt;



&lt;p&gt;The help built into PowerShell also needs to be updated before you can rely on it.
The installed help has to correspond to the version you&apos;re running.&lt;/p&gt;



&lt;h2&gt;Get-Command Syntax&lt;/h2&gt;



&lt;p&gt;Get-Command with the Syntax parameter ignores whatever the module author wrote for help and looks directly at the code on your machine to build out what parameters the cmdlet supports.&lt;/p&gt;



&lt;p&gt;The distinction is important when the help, or documentation of code is out of date.
Another example would be if you used Update-Help and pulled down help for a &lt;em&gt;newer&lt;/em&gt; version of the help than what you are running locally.
Maybe a parameter was renamed, removed, or added in the help to reflect new functionality that you simply don&apos;t have yet.&lt;/p&gt;



&lt;h2&gt;Source of Truth&lt;/h2&gt;



&lt;p&gt;The truth is, Get-Command -Syntax should be considered the source of truth when you are sitting at the console.
It works out of the box, there isn&apos;t a need to download anything for it to function, and it doesn&apos;t rely on the module author to provide accurate documentation.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Random Man Page in PowerShell</title><link>https://ngetchell.com/blog/random-man-page-in-powershell/</link><guid isPermaLink="true">https://ngetchell.com/blog/random-man-page-in-powershell/</guid><description>PowerShell is a programming language and console application that comes with &quot;batteries included&quot;. The help system and documentation is built in. Granted, it arrives in an outdated form for built-in modules and requires an Update-Help to be complete. A man page is crucial for understanding commands in Linux. One of the ways I learn new […]</description><pubDate>Wed, 14 Nov 2018 08:59:29 GMT</pubDate><content:encoded>
&lt;p&gt;PowerShell is a programming language and console application that comes with &quot;batteries included&quot;.
The help system and documentation is built in.
Granted, it arrives in an outdated form for built-in modules and requires an Update-Help to be complete.
A man page is crucial for understanding commands in Linux.&lt;/p&gt;



&lt;p&gt;One of the ways I learn new technology is to read the man page.
It isn&apos;t the most efficient way to learn, I prefer a combination of books and video training, but I &lt;em&gt;always&lt;/em&gt; learn something new, every time I read a man page.
I find that the &lt;a href=&quot;https://ngetchell.com/posts/intro-to-cmdlets/&quot;&gt;cmdlets&lt;/a&gt; I know best generate a big surprise when I learn something new about them.
It helps me round out my knowledge and fill in the gaps.&lt;/p&gt;



&lt;p&gt;The PowerShell About help system is as close as PowerShell gets to the man pages found on a Linux box.
To select a random About topic to read about look at the following code.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;# Update Help so you have all help&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Update-Help&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;# Get A Topic&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Topic &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Help&lt;/span&gt;&lt;span&gt; about_&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ExpandProperty Name &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Unique &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Get-Random&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Count &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;# Display the Help File&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Get-Help&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Full &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;name $Topic&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Turning it into a function is simple.
Slap it in your profile if you want it at your disposal.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;# Validated on PS Core 6.1.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Function&lt;/span&gt;&lt;span&gt; Get-RandomAboutHelp&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $ProgressPreference &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;SilentlyContinue&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $Topic &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Help&lt;/span&gt;&lt;span&gt; about_&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ExpandProperty Name &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Unique &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Get-Random&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Count &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Get-Help&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Full &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;name $Topic &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; out-string&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Get-RandomAboutHelp&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;Task Scheduler Email&lt;/h2&gt;



&lt;p&gt;If you&apos;re interested in automating an email message with a random about topic page try using Task Scheduler and the code below to schedule the email on daily, weekly, or monthly intervals.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$Body &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-RandomAboutHelp&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Splat &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; @&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    To         &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;user@domain.com&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    from       &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;PSHelp@powershell.org&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Subject    &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;Daily Help Message&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Body       &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $Body &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    SmtpServer &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;smtp.domain.com&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Send-MailMessage&lt;/span&gt;&lt;span&gt; @Splat&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;Linux Man Pages&lt;/h2&gt;



&lt;p&gt;In case you&apos;re wondering now I do it in bash, I use the apripos, awk, and xargs commands then send it to the console.
You could also save it to a file and attach it in an email but it is outside the scope of this article.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;apropos&lt;/span&gt;&lt;span&gt; .&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; awk&lt;/span&gt;&lt;span&gt; &apos;{print $1}&apos;&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; sort&lt;/span&gt;&lt;span&gt; -R&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; head&lt;/span&gt;&lt;span&gt; -1&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; xargs&lt;/span&gt;&lt;span&gt; man&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content:encoded><category>PowerShell</category></item><item><title>PSGitLab v3.0.1 Released</title><link>https://ngetchell.com/blog/psgitlab-v3-0-1-released/</link><guid isPermaLink="true">https://ngetchell.com/blog/psgitlab-v3-0-1-released/</guid><description>A ton of work went into the v3 version of PSGitLab, both on my part and that of the community. There are new contributors as well as familiar names in the changelog and I am thankful for all of the help. My goal of releasing an open source project to help others has been greatly […]</description><pubDate>Wed, 10 Oct 2018 08:30:55 GMT</pubDate><content:encoded>
&lt;p&gt;A ton of work went into the v3 version of PSGitLab, both on my part and that of the community.
There are new contributors as well as familiar names in the changelog and I am thankful for all of the help.
My goal of releasing an open source project to help others has been greatly exceeded by the contribution of those in the PowerShell community.
Over the next few months, I hope to make it easier for new contributors to jump in and add coverage to the GitLab API.&lt;/p&gt;



&lt;h2&gt;Enhancements and Fixes&lt;/h2&gt;



&lt;ul&gt;

&lt;li&gt;[Enhancement] &lt;a href=&quot;https://github.com/ngetchell/PSGitLab/blob/master/ReleaseNotes.md&quot;&gt;ReleaseNotes.md&lt;/a&gt; for end users to keep up with what changed version to version.&lt;/li&gt;


&lt;li&gt;[Fix] Support for 204 HTTP status codes on DELETE so there aren&apos;t errors thrown when any of the Remove-* functions are called.&lt;/li&gt;


&lt;li&gt;[Fix] Hide archived projects by default restored to default (Simon Heather)&lt;/li&gt;


&lt;li&gt;[Fix] Switched from POST to PUT verbs on Block and Unblock to follow the GitLab API reference.&lt;/li&gt;


&lt;li&gt;[Enhancement] Get-GitLabGroup added (Eduardo de Moura Rodrigues)&lt;/li&gt;


&lt;li&gt;[Enhancement] Disable to Progress Bar when running Invoke-WebRequest (Simon Heather)&lt;/li&gt;


&lt;li&gt;[Enhancement] Code Cleanup (Wojciech Sciesinski)&lt;/li&gt;


&lt;li&gt;[Fix] Support for TLS 1.2 if not enabled on client&lt;/li&gt;


&lt;li&gt;[Enhancement] Get-GitLabIssue (Robin Malik)&lt;/li&gt;


&lt;li&gt;[Fix] Changed API endpoint for Get-GitLabProject to follow the GitLab API reference.&lt;/li&gt;

&lt;/ul&gt;



&lt;h2&gt;Improved Documentation&lt;/h2&gt;



&lt;p&gt;Announcing the &lt;a href=&quot;https://github.com/ngetchell/PSGitLab/wikihttps://github.com/ngetchell/PSGitLab/wiki&quot;&gt;PSGitLab wiki&lt;/a&gt;! Over time, I will work to fill in the gaps in regards to starting out with PSGitLab then to go over advanced configuration to get the most out of your cli experience.&lt;/p&gt;



&lt;p&gt;Another place for improvement will be developer documentation.
I would like as many people contributing to PSGitLab as possible.
That means, drastically reducing the barrier to entry for people starting out with PowerShell.
I hope the developer on-boarding docs would aid in that.&lt;/p&gt;



&lt;p&gt;The goal will be to add all existing features to the wiki then roll out new documentation as new features are added.
Look for more in this space soon.&lt;/p&gt;



&lt;h2&gt;The Future for PSGitLab&lt;/h2&gt;



&lt;p&gt;In the future, I will be looking to &lt;a href=&quot;https://github.com/ngetchell/PSGitLab/issues/125&quot;&gt;drastically simplify&lt;/a&gt; the build and test process, upgrade to &lt;a href=&quot;https://github.com/ngetchell/PSGitLab/issues/152&quot;&gt;Pester v4 syntax&lt;/a&gt;, &lt;a href=&quot;https://github.com/ngetchell/PSGitLab/issues/137&quot;&gt;detect the project url&lt;/a&gt; via git remote, better &lt;a href=&quot;https://ngetchell.com/blog/generic-pester-tests/&quot;&gt;default pester tests&lt;/a&gt;, and various other &lt;a href=&quot;https://github.com/ngetchell/PSGitLab/issues&quot;&gt;enhancement requests&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;For now, I will work to make sure the new v3 of PSGitLab didn’t introduce anymore bugs (hence 3.0.1).&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Import a Module from Other Computers</title><link>https://ngetchell.com/blog/import-a-module-from-other-computers/</link><guid isPermaLink="true">https://ngetchell.com/blog/import-a-module-from-other-computers/</guid><description>PowerShell comes with a simple way to install a module using PowerShellGet and the Find/Install Module cmdlets. Did you know however that you can import modules, over the network, from a computer that already has them installed? They aren&apos;t installed locally and when you run the commands, PowerShell will seamlessly run them in the PowerShell […]</description><pubDate>Wed, 14 Mar 2018 11:49:21 GMT</pubDate><content:encoded>
&lt;p&gt;PowerShell comes with a simple way to install a module using &lt;a href=&quot;https://ngetchell.com/blog/powershellget-introduction/&quot;&gt;PowerShellGet&lt;/a&gt; and the Find/Install Module cmdlets.
Did you know however that you can import modules, &lt;em&gt;over the network&lt;/em&gt;, from a computer that already has them installed? They aren&apos;t installed locally and when you run the commands, PowerShell will seamlessly run them in the PowerShell process running on the remote computer.&lt;/p&gt;



&lt;p&gt;I am constantly hopping onto different computers at work and not all of the computers have the RSAT tools for Active Directory administration.
Using the Import-Module with the PSSession parameter lets me use the local console for administration.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$Session &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; New-PSSession&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Computername DC&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Import-Module&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;PSSession $Session &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Name ActiveDirectory&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Get-ADUser&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;identity ngetchell&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The results come back to your own console even though the module resides on the remote box.
If you&apos;ve ever administered an Exchange Online tenant from PowerShell you&apos;ve likely used this feature.
Here, we import the entire session, not just one module into your current, local session.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$Params &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; @&lt;/span&gt;&lt;span&gt;{ &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    ConfigurationName &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;Microsoft.Exchange&apos;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Authentication    &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;Basic&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    AllowRedirection  &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $true&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    AllowClobber      &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $true&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    ConnectionUri     &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;https://outlook.office365.com/powershell-liveid/&apos;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Credential        &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; ( &lt;/span&gt;&lt;span&gt;Get-Credential&lt;/span&gt;&lt;span&gt; ) &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;} &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Session &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; New-PSSession&lt;/span&gt;&lt;span&gt; @Params &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Import-PSSession&lt;/span&gt;&lt;span&gt; $Session&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content:encoded><category>PowerShell</category></item><item><title>Git Commit Messages and Hooks</title><link>https://ngetchell.com/blog/git-commit-messages-hooks/</link><guid isPermaLink="true">https://ngetchell.com/blog/git-commit-messages-hooks/</guid><description>Maintaining integrity in your code is hard. Git hooks are an easy way to manage your workflow so you never commit code that doesn’t meet your standards. How do you know if the changes you made introduced bugs? Testing of course. Do you know if your code follows best practices? To figure that out, you’d […]</description><pubDate>Tue, 27 Feb 2018 06:30:24 GMT</pubDate><content:encoded>
&lt;p&gt;Maintaining integrity in your code is hard.
Git &lt;a href=&quot;https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks&quot;&gt;hooks&lt;/a&gt; are an easy way to manage your workflow so you never commit code that doesn’t meet your standards.&lt;/p&gt;



&lt;p&gt;How do you know if the changes you made introduced bugs? Testing of course.
Do you know if your code follows best practices? To figure that out, you’d use a linter.
In PowerShell the community uses &lt;a href=&quot;https://ngetchell.com/blog/work-pester-testing/&quot;&gt;Pester&lt;/a&gt; for testing and PSScriptAnalyzer for making sure you follow community standards.
Git hooks let you validate your code &lt;em&gt;before&lt;/em&gt; it is committed in &lt;a href=&quot;https://ngetchell.com/blog/use-source-control/&quot;&gt;Git&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;Another useful feature that Git provides is the ability to pre-populate your commit message.
Maybe your commit messages would benefit from template or maybe a reminder to describe your changes.&lt;/p&gt;



&lt;h2&gt;Pre-Commit Hooks&lt;/h2&gt;



&lt;p&gt;With the pre-commit hook the key is to make sure your hook exits correctly.
Every initialized repository comes with a sample git hooks.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-ChildItem&lt;/span&gt;&lt;span&gt; .git\hooks\ &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Recurse&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Directory: Git:\project\.git\hooks&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Mode LastWriteTime Length Name&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; -------------&lt;/span&gt;&lt;span&gt; ------&lt;/span&gt;&lt;span&gt; ----&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;478&lt;/span&gt;&lt;span&gt; applypatch&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;msg.sample&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;896&lt;/span&gt;&lt;span&gt; commit&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;msg.sample&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;189&lt;/span&gt;&lt;span&gt; post&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;update.sample&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;424&lt;/span&gt;&lt;span&gt; pre&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;applypatch.sample&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;1642&lt;/span&gt;&lt;span&gt; pre&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;commit&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;1642&lt;/span&gt;&lt;span&gt; pre&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;commit.sample&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;1348&lt;/span&gt;&lt;span&gt; pre&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;push.sample&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;4898&lt;/span&gt;&lt;span&gt; pre&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;rebase.sample&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;544&lt;/span&gt;&lt;span&gt; pre&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;receive.sample&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;1239&lt;/span&gt;&lt;span&gt; prepare&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;commit&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;msg.sample&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;a&lt;/span&gt;&lt;span&gt;----&lt;/span&gt;&lt;span&gt; 11&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2017&lt;/span&gt;&lt;span&gt; 8&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt; PM &lt;/span&gt;&lt;span&gt;3610&lt;/span&gt;&lt;span&gt; update.sample&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;To start, create a pre-commit file in the .git\hooks\ directory located in your repository.
Since this is a PowerShell blog we’re going to use a bash script to invoke PowerShell.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;#!/bin/sh&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe&lt;/span&gt;&lt;span&gt; -ExecutionPolicy&lt;/span&gt;&lt;span&gt; Bypass&lt;/span&gt;&lt;span&gt; -NoProfile&lt;/span&gt;&lt;span&gt; -File&lt;/span&gt;&lt;span&gt; &apos;.git\hooks\pre-commit.ps1&apos;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;In the pre-commit.ps1 file you can write standard PowerShell code.
Write-Host can be used to write errors to the screen.&lt;/p&gt;



&lt;p&gt;What governs whether a commit message is saved or not is the exit code PowerShell.exe throws.
If you’d like to keep someone from being able to commit, add the following:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Write-Host&lt;/span&gt;&lt;span&gt; &quot;Aborting Commit&quot;&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ForegroundColor Red&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;exit&lt;/span&gt;&lt;span&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h3&gt;PSScriptAnalyzer&lt;/h3&gt;



&lt;p&gt;Consider a file named alias.ps1 needs to be added to your repository but was copy and pasted from the PowerShell console.
Now I don’t know about you, but I try to save as many characters as I can when so I use lots of aliases.&lt;/p&gt;



&lt;p&gt;When I go to commit the quick script I get an error.
Notice your prompt, I still have one file sitting in the staging area.
The script I attempted to put into source control didn’t meet the standards from PSScriptAnalyzer.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$Results &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Invoke-ScriptAnalyzer&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Severity Error&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; Warning .\ &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Recurse&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt; ( $Results.count &lt;/span&gt;&lt;span&gt;-gt&lt;/span&gt;&lt;span&gt; 0&lt;/span&gt;&lt;span&gt; ) {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    &quot;Found {0} issues&quot;&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; $Results.Count&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $Results&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    exit&lt;/span&gt;&lt;span&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h3&gt;Pester&lt;/h3&gt;



&lt;p&gt;If you&apos;ve been writing Pester tests with your work you can also leverage your work to make sure you always commit clean code.
Consider the the following tests:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Describe &lt;/span&gt;&lt;span&gt;&quot;Addition&quot;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    It &lt;/span&gt;&lt;span&gt;&quot;Can&apos;t Add&quot;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        5&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; should be &lt;/span&gt;&lt;span&gt;4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;It is designed to fail to illustrate the ability to keep git from finalizing your commit.
Our pre-commit.ps1 file will look similar to our previous one.
It will abort the commit on any failing Pester tests.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$Results &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Invoke-Pester&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Show Failed&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; describe &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;PassThru&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt; ( $Results.FailedCount &lt;/span&gt;&lt;span&gt;-gt&lt;/span&gt;&lt;span&gt; 0&lt;/span&gt;&lt;span&gt; ) {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    exit&lt;/span&gt;&lt;span&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h3&gt;Other Uses&lt;/h3&gt;



&lt;p&gt;You can also use pre-commit hooks to sign your PowerShell files to make sure they comply with security practices on your network.
Another use could be to put your .ps1 files through a code formater that makes sure you&apos;re following company code styles.&lt;/p&gt;



&lt;h2&gt;Commit Messages&lt;/h2&gt;



&lt;p&gt;Commit messages have a nasty habit of devolving.&lt;/p&gt;



&lt;figure&gt;&lt;img src=&quot;https://ngetchell.com/wp-media/2026/07/commit-message-hooks-xkcd.png&quot; alt=&quot;XKCD&quot; /&gt;&lt;/figure&gt;



&lt;p&gt;To combat this tendency git has a configuration where you can add information and instructions to your commit message so you are reminded to leave the useful comments.&lt;/p&gt;



&lt;p&gt;First, create a text file with your template commit message.
Here is a simple example of a commit message that keeps you on track.
Remember, anything that begins with a ‘#&apos; character is ignored in a commit message.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;## Subject &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;## Body&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;## Files Changed&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;## Link to Issue in tracker&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;To associate the template with your local repository use the following.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;git&lt;/span&gt;&lt;span&gt; config&lt;/span&gt;&lt;span&gt; --global&lt;/span&gt;&lt;span&gt; commit.template&lt;/span&gt;&lt;span&gt; .&lt;/span&gt;&lt;span&gt;\c&lt;/span&gt;&lt;span&gt;ommit_template.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content:encoded><category>PowerShell</category></item><item><title>Poor Man’s GUI</title><link>https://ngetchell.com/blog/poor-mans-gui/</link><guid isPermaLink="true">https://ngetchell.com/blog/poor-mans-gui/</guid><description>Write a quick UI around your PowerShell function</description><pubDate>Tue, 13 Feb 2018 10:00:00 GMT</pubDate><content:encoded>
&lt;p&gt;If you’re like me, you try to automate everything through the PowerShell console.
Automate employee account creation, easy.
Check the registry on 500 remote servers, wouldn’t break a sweat.
How about delegating your script to a junior systems administrator or maybe a help desk technician? That isn’t so easy.
You have to trap errors, sanitize inputs, and generally guide the user through documentation.
After all that, trust that you’re underling knows their way around the console.
Maybe you need a GUI.&lt;/p&gt;



&lt;p&gt;Sometimes it is easier to break with the PowerShell conventions and introduce some user interaction into the process.
With that you can use Read-Host, Out-GridView, and Show-Command.&lt;/p&gt;



&lt;h2&gt;Read-Host&lt;/h2&gt;



&lt;p&gt;Read-Host is meant to handle text input from the console at run-time.
It can be useful for specifying server names in a script or adding a filter to a search.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$ProcessToKill &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Read-Host&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Prompt &lt;/span&gt;&lt;span&gt;&apos;What process should we kill?&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Stop-Process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name $processtokill&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;figure&gt;&lt;img src=&quot;https://ngetchell.com/wp-media/2026/07/poor-man-gui.png&quot; alt=&quot;Landscape&quot; /&gt;&lt;/figure&gt;



&lt;p&gt;The drawback to this is there is usually a better way to input text in the console.
If you’re using Read-Host for usernames and passwords you’re better off with &lt;a href=&quot;https://ngetchell.com/posts/credentials/&quot;&gt;Get-Credential&lt;/a&gt;.
If you’re running a cmdlet that requires input, the console will prompt you for it.&lt;/p&gt;



&lt;p&gt;In other words, Read-Host can only bring you so far.
Time to mimic GUI applications in the console.&lt;/p&gt;



&lt;h2&gt;Out-GridView&lt;/h2&gt;



&lt;p&gt;Out-GridView offers up a picker for quick and dirty tasks like killing processes.
The following code will let you select one process to stop.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Process&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Out-GridView&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Title &lt;/span&gt;&lt;span&gt;&apos;Process to Kill&apos;&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;OutputMode Single &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Stop-Process&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Pressing the OK button will end the notepad.exe object down the pipeline to Stop-Process.&lt;/p&gt;



&lt;figure&gt;&lt;img src=&quot;https://ngetchell.com/wp-media/2026/07/poor-man-gui-1.png&quot; alt=&quot;Process to Kill&quot; /&gt;&lt;/figure&gt;



&lt;p&gt;This is also useful for removing Active Directory accounts for those who are used to a GUI application.
Get all users, select your victims, and remove their accounts.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-ADUser&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Filter &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Out-GridView&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Title &lt;/span&gt;&lt;span&gt;&apos;Users to Disable&apos;&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;OutputMode Multiple &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Remove-ADUser&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;confirm:&lt;/span&gt;&lt;span&gt;$false&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;With the -OuputMode Multiple you can select any number of accounts to remove.&lt;/p&gt;



&lt;h2&gt;Show-Command&lt;/h2&gt;



&lt;p&gt;Show-Command allows for a GUI with built-in help button.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Function&lt;/span&gt;&lt;span&gt; Write-Screen&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    param&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $Sender&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $Message&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $WriteHost &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &quot;[{0}]: {1}&quot;&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; $Sender&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; $Message&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Clear-Host&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Write-Host&lt;/span&gt;&lt;span&gt; $WriteHost&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Show-Command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;NoCommonParameter &lt;/span&gt;&lt;span&gt;Write-Screen&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;figure&gt;&lt;img src=&quot;https://ngetchell.com/wp-media/2026/07/poor-man-gui-2.png&quot; alt=&quot;Write-Screen&quot; /&gt;&lt;/figure&gt;



&lt;p&gt;This trick is also great for keeping track of all of the types of accounts you have to create.
Most of the time, adding a new employee requires more than just an Active Directory account.
Hide all of that complexity behind a controller function and hand the GUI application off to the junior administrator.
Using abstraction to hide complexity.&lt;/p&gt;



&lt;p&gt;![New-Employee](../../assets/poor-man-gui-3.png&lt;/p&gt;



&lt;p&gt;&lt;em&gt;Note: I’ve had &lt;a href=&quot;https://github.com/lzybkr/PSReadLine/issues/198&quot;&gt;better luck&lt;/a&gt; running Show-Command with &lt;a href=&quot;https://ngetchell.com/posts/turn-off-psreadline/&quot;&gt;PSReadline turned off&lt;/a&gt;.
The issue has been raised as a &lt;a href=&quot;https://github.com/lzybkr/PSReadLine/issues/198&quot;&gt;PSReadLine GitHub issue&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;



&lt;p&gt;&lt;em&gt;Updated:&lt;/em&gt; Lots of people asked about how I created the GUI behind the New-Employee function GUI.
I just used a defined parameter set and show command.
I recreated it in a &lt;a href=&quot;https://gist.github.com/ngetchell/9313dce01e5ee48b2e93e43ca832e4fd&quot;&gt;GitHub Gist&lt;/a&gt;.
There isn’t too much you can customize beyond this but you also don’t have to edit any XAML!.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Function&lt;/span&gt;&lt;span&gt; New-Employee&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    [&lt;/span&gt;&lt;span&gt;cmdletbinding&lt;/span&gt;&lt;span&gt;()]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    param&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;Parameter&lt;/span&gt;&lt;span&gt;(Mandatory)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $EmployeeID&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;Parameter&lt;/span&gt;&lt;span&gt;(Mandatory)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $FirstName&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;Parameter&lt;/span&gt;&lt;span&gt;(Mandatory)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $LastName&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;Parameter&lt;/span&gt;&lt;span&gt;(ParameterSetName&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&apos;IT Admin&apos;&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;switch&lt;/span&gt;&lt;span&gt;]$ITPermissions&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;Parameter&lt;/span&gt;&lt;span&gt;(ParameterSetName&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&apos;HR Associate&apos;&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;switch&lt;/span&gt;&lt;span&gt;]$HRPerms&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;Parameter&lt;/span&gt;&lt;span&gt;(ParameterSetName&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&apos;Sales Associate&apos;&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;switch&lt;/span&gt;&lt;span&gt;]$SalesPerms&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;Parameter&lt;/span&gt;&lt;span&gt;(ParameterSetName&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&apos;Contractor&apos;&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;switch&lt;/span&gt;&lt;span&gt;]$Contractor&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;ValidateSet&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&quot;IT&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; &quot;HR&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; &quot;Sales&quot;&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $NetworkShares &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;IT&apos;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;switch&lt;/span&gt;&lt;span&gt;]$O365Enabled&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Show-Command&lt;/span&gt;&lt;span&gt; New-Employee&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content:encoded><category>PowerShell</category></item><item><title>Using ThreadJob for Performance</title><link>https://ngetchell.com/blog/using-threadjob-for-performance/</link><guid isPermaLink="true">https://ngetchell.com/blog/using-threadjob-for-performance/</guid><description>Parallelizing work in PowerShell has been a drag. Runspaces are too complicated to spin up and background jobs are too resource intensive. There is a parallel foreach parameter when using workflows but I&apos;ve never been able to figure workflows out. I&apos;ve always used Invoke-Parallel and PoshRSJob to accomplish most speed related tasks but now there […]</description><pubDate>Fri, 26 Jan 2018 10:00:46 GMT</pubDate><content:encoded>
&lt;p&gt;Parallelizing work in PowerShell has been a drag.
Runspaces are too complicated to spin up and background jobs are too resource intensive.
There is a parallel foreach parameter when using workflows but I&apos;ve never been able to figure workflows out.
I&apos;ve always used &lt;a href=&quot;https://github.com/RamblingCookieMonster/Invoke-Parallel&quot;&gt;Invoke-Parallel&lt;/a&gt; and &lt;a href=&quot;https://github.com/proxb/PoshRSJob&quot;&gt;PoshRSJob&lt;/a&gt; to accomplish most speed related tasks but now there is a new module in town.
The PowerShell team has just released to the PowerShell Gallery a new module called &lt;a href=&quot;https://www.powershellgallery.com/packages/ThreadJob/&quot;&gt;ThreadJob&lt;/a&gt; to handle spinning up multiple, lightweight jobs in PowerShell.
Background jobs themselves tend to take a lot of CPU cycles to initialize and can cause great strains on memory.
Consider the following code:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Job&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Remove-Job&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Force&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Measure-Command&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;..&lt;/span&gt;&lt;span&gt;10&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; ForEach-Object&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        Start-Job&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ArgumentList &lt;/span&gt;&lt;span&gt;$_&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ScriptBlock {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            Param&lt;/span&gt;&lt;span&gt;($Arg) &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $arg &lt;/span&gt;&lt;span&gt;%&lt;/span&gt;&lt;span&gt; 2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Get-Job&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Receive-Job&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Wait&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;First, remove all previous jobs running in this session.
Then wrap everything in a measure-command script block to test the speed.
Create 10 integers and throw them into the pipeline.
From there, start a job where the job performs the modulus operation on an argument.
Simple stuff.
If you open task manager jobs spin up their own PowerShell instance to complete the work.&lt;/p&gt;



&lt;p&gt;Threads, on the other hand, do not open multiple processes.
The ThreadJob module leverages the process that spawned them.
The code is exactly the same, just substituting Start-Job with Start-ThreadJob.
Once the ThreadJob starts you interact with it like any other job.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Job&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Remove-Job&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Force&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Measure-Command&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;..&lt;/span&gt;&lt;span&gt;10&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; ForEach-Object&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        Start-ThreadJob&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ArgumentList &lt;/span&gt;&lt;span&gt;$_&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ScriptBlock {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            Param&lt;/span&gt;&lt;span&gt;($Arg) &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $arg &lt;/span&gt;&lt;span&gt;%&lt;/span&gt;&lt;span&gt; 2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Get-Job&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Receive-Job&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Wait&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The results are incredible.
Even with such a small sample test, ThreadJob took 1/10th the time that background jobs use.
Give 100 jobs a try.
My computer couldn&apos;t handle 100 background jobs in a reasonable amount of time.&lt;/p&gt;



&lt;p&gt;Currently, there are a few drawbacks to using a ThreadJob over a background job.
If a background job hangs, only that process hangs.
All other jobs keep chugging away.
If you have a job that hangs with ThreadJob the entire queue is affected.
The team also hasn&apos;t implemented the $Using variable so make sure you structure your parameter blocks to give your scripts all the parameters it needs.&lt;/p&gt;



&lt;p&gt;Example code can be found at the following &lt;a href=&quot;https://gist.github.com/ngetchell/d98d0c3f5140ddff040328900f900b75&quot;&gt;gist&lt;/a&gt;.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Deploying PowerShell Down-level</title><link>https://ngetchell.com/blog/deploying-powershell-level/</link><guid isPermaLink="true">https://ngetchell.com/blog/deploying-powershell-level/</guid><description>There have been many great features added to PowerShell throughout the years. Lots of new cmdlets come through the Remote Server Administration Tools (RSAT) or baked into the new version of the operating system. Some features we’re deemed so important that they were back-ported to older operating systems like Windows 7. Remember that Windows 7 […]</description><pubDate>Thu, 25 Jan 2018 10:00:42 GMT</pubDate><content:encoded>
&lt;p&gt;There have been many great features added to PowerShell throughout the years. 
Lots of new cmdlets come through the Remote Server Administration Tools (RSAT) or baked into the new version of the operating system.
Some features we’re deemed so important that they were back-ported to older operating systems like Windows 7.
Remember that Windows 7 came with Windows Management Framework (WMF) 2 so updates are definitely needed.
The best PowerShell experience is still going to be using the latest Windows operating system with the latest WMF installed.&lt;/p&gt;



&lt;h2&gt;Features&lt;/h2&gt;



&lt;h3&gt;Package Management&lt;/h3&gt;



&lt;p&gt;This has been my favorite addition to PowerShell since version 2.
The ability to install community modules has been great and has opened the administration plane way beyond what is default and in-box.
Also, updates to the built in modules can be found on the &lt;a href=&quot;https://www.powershellgallery.com/&quot;&gt;PowerShell Gallery&lt;/a&gt;.&lt;/p&gt;



&lt;h3&gt;Desired State Configuration (DSC)&lt;/h3&gt;



&lt;p&gt;At the PowerShell Summit I heard something that finally made DSC click in my mind.
DSC will ‘make it so’.
A framework built instead of on imperative programming but on declarative programming.
You write your &lt;em&gt;Documentation&lt;/em&gt; in a specific format and DSC &lt;em&gt;Makes it so.&lt;/em&gt;
All of the previous work on PowerShell pays off with the ability to use DSC to control your Windows boxes.&lt;/p&gt;



&lt;h3&gt;PowerShell Classes&lt;/h3&gt;



&lt;p&gt;Jeffrey Snover talks about being yelled at by people on the Azure team for not supporting more programming like constructs.
Classes was the response.
This is a step beyond building PowerShell functions and is a more traditional way of object-oriented programming.&lt;/p&gt;



&lt;h3&gt;Transaction and Security Logging&lt;/h3&gt;



&lt;p&gt;The newest releases of PowerShell can log all of your PowerShell usage into the event viewer.
This is super helpful if you’re attempting to figure out what malware written in PowerShell is doing on the machine.
The event log traces can even be encrypted and forwarded so you know the attacker hasn’t altered the logs.&lt;/p&gt;



&lt;h2&gt;Upgrade Path&lt;/h2&gt;



&lt;p&gt;With upgrading PowerShell you are expected to install the entire Windows Management Framework (WMF) install.
It is also required that you upgrade the WMF versions in order. 
No jumping from v2 to v5.1. Here are the Knowledge base articles for the downloads.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Windows Management Framework 5.1&lt;/strong&gt;&lt;/p&gt;



&lt;figure&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;OS&lt;/th&gt;&lt;th&gt;Knowledge Base&lt;/th&gt;&lt;th&gt;Platform&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Server 2012&lt;/td&gt;&lt;td&gt;KB3191565&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Win 7&lt;/td&gt;&lt;td&gt;KB3191566&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Server 2008 R2&lt;/td&gt;&lt;td&gt;KB3191566&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Win 7&lt;/td&gt;&lt;td&gt;KB3191566&lt;/td&gt;&lt;td&gt;x86&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Win 8.1&lt;/td&gt;&lt;td&gt;KB3191564&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Server 2012 R2&lt;/td&gt;&lt;td&gt;KB3191564&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Win 8.1&lt;/td&gt;&lt;td&gt;KB3191564&lt;/td&gt;&lt;td&gt;x86&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;



&lt;p&gt;&lt;strong&gt;Windows Management Framework 5&lt;/strong&gt;&lt;/p&gt;



&lt;figure&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;OS&lt;/th&gt;&lt;th&gt;Knowledge Base&lt;/th&gt;&lt;th&gt;Platform&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Server 2012&lt;/td&gt;&lt;td&gt;KB3134759&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Win 7&lt;/td&gt;&lt;td&gt;KB3134760&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Server 2008 R2&lt;/td&gt;&lt;td&gt;KB3134760&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Win 7&lt;/td&gt;&lt;td&gt;KB3134760&lt;/td&gt;&lt;td&gt;x86&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Win 8.1&lt;/td&gt;&lt;td&gt;KB3134758&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Server 2012 R2&lt;/td&gt;&lt;td&gt;KB3134758&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Win 8.1&lt;/td&gt;&lt;td&gt;KB3134758&lt;/td&gt;&lt;td&gt;x86&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;



&lt;p&gt;&lt;strong&gt;Windows Management Framework 4&lt;/strong&gt;&lt;/p&gt;



&lt;figure&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;OS&lt;/th&gt;&lt;th&gt;Knowledge Base&lt;/th&gt;&lt;th&gt;Platform&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Server 2012&lt;/td&gt;&lt;td&gt;KB2799888&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Win 7&lt;/td&gt;&lt;td&gt;KB2819745&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Server 2008 R2&lt;/td&gt;&lt;td&gt;KB2819745&lt;/td&gt;&lt;td&gt;x64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Win 7&lt;/td&gt;&lt;td&gt;KB2819745&lt;/td&gt;&lt;td&gt;x86&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/figure&gt;



&lt;h2&gt;Importing into WSUS&lt;/h2&gt;



&lt;p&gt;The task of installing the updates is even easier if you have Windows Server Update Services (WSUS).
You can import the KBs directly through the WSUS console to push out to your fleet.&lt;/p&gt;



&lt;p&gt;Open Update Services, right click on Updates and select Import Updates.&lt;/p&gt;



&lt;p&gt;Install the ActiveX component.Add the updates you’d like to import.&lt;/p&gt;



&lt;p&gt;Use the &lt;em&gt;Import directly into Windows Server Update Services&lt;/em&gt; feature.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>PowerShell Core 6.0 Released</title><link>https://ngetchell.com/blog/powershell-core-6-0-released/</link><guid isPermaLink="true">https://ngetchell.com/blog/powershell-core-6-0-released/</guid><description>PowerShell Core 6.0 has been released thanks to the hard work of the PowerShell Team. It is a stripped down version of PowerShell that runs cross-platform. That means PowerShell for Linux, MacOS, and even ARM based devices. All new development will go into PowerShell Core so it is time to jump on the bandwagon and […]</description><pubDate>Wed, 10 Jan 2018 20:34:15 GMT</pubDate><content:encoded>
&lt;p&gt;PowerShell Core 6.0 has been released thanks to the &lt;a href=&quot;https://github.com/powershell/powershell/issues?q=is%3Aissue+is%3Aclosed&quot;&gt;hard work&lt;/a&gt; of the PowerShell Team.
It is a stripped down version of PowerShell that runs cross-platform.
That means PowerShell for Linux, MacOS, and even ARM based devices.
All new development will go into PowerShell Core so it is time to jump on the bandwagon and &lt;a href=&quot;https://ngetchell.com/posts/get-involved-powershell/&quot;&gt;get involved&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;If you run into issues make sure to &lt;a href=&quot;https://github.com/PowerShell/PowerShell/issues&quot;&gt;report them&lt;/a&gt;.
If you’re interested in proposing big changes check out the &lt;a href=&quot;https://github.com/PowerShell/PowerShell-RFC&quot;&gt;PowerShell-RFC&lt;/a&gt; to submit your ideas or drop by the &lt;a href=&quot;https://github.com/PowerShell/PowerShell-RFC/blob/master/CommunityCall/RecurringCommunityCall.ics&quot;&gt;Community Call&lt;/a&gt;.&lt;/p&gt;



&lt;h2&gt;Install&lt;/h2&gt;



&lt;p&gt;Here is a quick script to install the x64 version of PowerShell Core on a Windows box.
This uses &lt;a href=&quot;https://twitter.com/JeffHicks&quot;&gt;Jeff Hick&lt;/a&gt;‘s &lt;a href=&quot;https://github.com/jdhitsolutions/PSReleaseTools&quot;&gt;PSReleaseTools&lt;/a&gt; and a little trick using Invoke-Item.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Install-Module&lt;/span&gt;&lt;span&gt; PSReleaseTools&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$DownloadURL &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-PSReleaseAsset&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Family Windows &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Where-Object&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;span&gt;$_.Format&lt;/span&gt;&lt;span&gt; -eq&lt;/span&gt;&lt;span&gt; &apos;MSI&apos;&lt;/span&gt;&lt;span&gt; -and&lt;/span&gt;&lt;span&gt; $_.Filename&lt;/span&gt;&lt;span&gt; -like&lt;/span&gt;&lt;span&gt; &quot;*x64*&quot;&lt;/span&gt;&lt;span&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Invoke-WebRequest&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Uri $DownloadURL.url &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;OutFile &lt;/span&gt;&lt;span&gt;&quot;~\Downloads\&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;($DownloadURL.FileName)&lt;/span&gt;&lt;span&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Invoke-Item&lt;/span&gt;&lt;span&gt; ~\Downloads\&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;($DownloadURL.Filename)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;AMA&lt;/h2&gt;



&lt;p&gt;Make sure to checkout the &lt;a href=&quot;https://techcommunity.microsoft.com/t5/PowerShell-AMA/bd-p/PowerShellAMA&quot;&gt;PowerShell AMA&lt;/a&gt; in celebration of PSCore going GA! It starts January 11th at 9:00 AM PT.
Have your questions answered by the inventor of PowerShell.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Generate Random Passwords</title><link>https://ngetchell.com/blog/generate-random-passwords/</link><guid isPermaLink="true">https://ngetchell.com/blog/generate-random-passwords/</guid><description>Whether you’re at a help desk resetting passwords or setting up service accounts, you always need to be able to generate good random passwords. You know, the kind nobody wants to type more than once. The correct horse battery staple method popularized by XKCD is where you string together four words to create passwords with […]</description><pubDate>Thu, 15 Jun 2017 08:30:35 GMT</pubDate><content:encoded>
&lt;p&gt;Whether you’re at a help desk resetting passwords or setting up service accounts, you always need to be able to generate good &lt;em&gt;random&lt;/em&gt; passwords.
You know, the kind nobody wants to type more than once.&lt;/p&gt;



&lt;p&gt;The &lt;a href=&quot;https://xkcd.com/936/&quot;&gt;correct horse battery staple&lt;/a&gt; method popularized by XKCD is where you string together four words to create passwords with lots of entropy.
There are cryptographers who question how well something like that would work.
&lt;a href=&quot;https://www.schneier.com/blog/archives/2014/03/choosing_secure_1.html&quot;&gt;Bruce Schneier advises against such methods&lt;/a&gt;.&lt;/p&gt;



&lt;blockquote&gt;
&lt;p&gt;This is why the oft-cited XKCD scheme for generating passwords — string together individual words like “correcthorsebatterystaple” — is no longer good advice.
The password crackers are on to this trick.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;With that fad out the door, we might as well go back to the tried and true &lt;em&gt;random&lt;/em&gt; password.
Passwords that are still safe against brute force attacks.
Below are two functions I use to generate new passwords.&lt;/p&gt;



&lt;h2&gt;Generating Passwords&lt;/h2&gt;



&lt;p&gt;First up is ConvertFrom-CharToPhonetic.
This function does one thing.
It turns characters into the &lt;a href=&quot;https://en.wikipedia.org/wiki/NATO_phonetic_alphabet&quot;&gt;NATO phonetic alphabet&lt;/a&gt; equivalent.
It also capitalizes the word when the character is capitalized.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Function&lt;/span&gt;&lt;span&gt; ConvertFrom-CharToPhonetic&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    param&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        &amp;amp;&lt;/span&gt;&lt;span&gt;#91;Parameter(Mandatory = $true, ValueFromPipeline = $true)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        &amp;amp;&lt;/span&gt;&lt;span&gt;#91;string]$String&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    BEGIN&lt;/span&gt;&lt;span&gt; { }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    PROCESS&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        foreach&lt;/span&gt;&lt;span&gt; ( $Char &lt;/span&gt;&lt;span&gt;in&lt;/span&gt;&lt;span&gt; $String.GetEnumerator() ) {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $Translator &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; @&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;a&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Alfa&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;b&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Bravo&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;c&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Charlie&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;d&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Delta&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;e&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Echo&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;f&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Foxtrot&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;g&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Golf&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;h&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Hotel&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;i&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;India&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;j&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Juliett&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;k&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Kilo&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;l&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Lima&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;m&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Mike&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;n&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;November&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;o&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Oscar&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;p&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Papa&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;q&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Quebec&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;r&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Romeo&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;s&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Sierra&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;t&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Tango&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;u&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Uniform&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;v&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Victor&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;w&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Whiskey&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;x&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;X-ray&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;y&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Yankee&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;z&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;Zulu&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;0&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;zero&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;1&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;one&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;2&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;two&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;3&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;three&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;4&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;four&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;5&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;five&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;6&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;six&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;7&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;seven&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;8&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;eight&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;9&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;nine&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;*&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;asterisk&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;+&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;plus&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;,&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;comma&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;-&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;dash&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;.&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;period&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                &apos;/&apos;&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span&gt; &apos;forward slash&apos;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            &amp;amp;&lt;/span&gt;&lt;span&gt;#91;string]$Value = $Translator.GetEnumerator() | Where-Object { $_.Name -eq $Char } | Select-Object -ExpandProperty Value&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            if&lt;/span&gt;&lt;span&gt; ( $Char &lt;/span&gt;&lt;span&gt;-match&lt;/span&gt;&lt;span&gt; &apos;&amp;amp;#91;0-9]&apos;&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                $msg &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;{0} - {1}&apos;&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; $msg&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; $Value.toUpper()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            elseif&lt;/span&gt;&lt;span&gt; ( $Char &lt;/span&gt;&lt;span&gt;-cmatch&lt;/span&gt;&lt;span&gt; &apos;&amp;amp;#91;a-z]&apos;&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                $msg &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;{0} - {1}&apos;&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; $msg&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; $Value.tolower()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            elseif&lt;/span&gt;&lt;span&gt; ( $Char &lt;/span&gt;&lt;span&gt;-cmatch&lt;/span&gt;&lt;span&gt; &apos;&amp;amp;#91;A-Z]&apos;&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                $msg &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;{0} - {1}&apos;&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; $msg&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; $Value.toUpper()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            elseif&lt;/span&gt;&lt;span&gt; ( $Char &lt;/span&gt;&lt;span&gt;-cmatch&lt;/span&gt;&lt;span&gt; &apos;&amp;amp;#91;*+,-./]&apos;&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                $msg &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;{0} - {1}&apos;&lt;/span&gt;&lt;span&gt; -f&lt;/span&gt;&lt;span&gt; $msg&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; $Value.toUpper()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            }            &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            Remove-Variable&lt;/span&gt;&lt;span&gt; Char&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    END&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $msg.Substring(&lt;/span&gt;&lt;span&gt;3&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; $&lt;/span&gt;&lt;span&gt;($msg.Length &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt; 3&lt;/span&gt;&lt;span&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Get-RandomPassword has one parameter and it is length.
Pass in how long you’d like your string to be.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Function&lt;/span&gt;&lt;span&gt; Get-RandomPassword&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    param&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        &amp;amp;&lt;/span&gt;&lt;span&gt;#91;Parameter(Mandatory = $true)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        &amp;amp;&lt;/span&gt;&lt;span&gt;#91;int]$Length&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $ReturnString &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $AvailableChar &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; 42&lt;/span&gt;&lt;span&gt;..&lt;/span&gt;&lt;span&gt;57&lt;/span&gt;&lt;span&gt; +&lt;/span&gt;&lt;span&gt; 65&lt;/span&gt;&lt;span&gt;..&lt;/span&gt;&lt;span&gt;90&lt;/span&gt;&lt;span&gt; +&lt;/span&gt;&lt;span&gt; 97&lt;/span&gt;&lt;span&gt;..&lt;/span&gt;&lt;span&gt;122&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $AvailableChar &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Get-Random&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Count $Length &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; ForEach-Object&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $ReturnString &lt;/span&gt;&lt;span&gt;+=&lt;/span&gt;&lt;span&gt; &amp;amp;&lt;/span&gt;&lt;span&gt;#91;char]&amp;amp;#91;byte]$_&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Write-Host&lt;/span&gt;&lt;span&gt; &quot;Phonetic Spelling -&amp;gt; &lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;ConvertFrom-CharToPhonetic&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;string $ReturnString)&lt;/span&gt;&lt;span&gt;&quot;&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ForegroundColor Yellow&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Write-Output&lt;/span&gt;&lt;span&gt; $ReturnString&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Using both functions together produce a random password with the phonetic spelling printed to the console.&lt;/p&gt;



&lt;h2&gt;Is Get-Random Secure?&lt;/h2&gt;



&lt;p&gt;You may of seen echos on the internet that Get-Random isn’t secure for password generation.
I reached out to &lt;a href=&quot;http://www.leeholmes.com/blog/&quot;&gt;Lee Holmes&lt;/a&gt; via Twitter and he confirmed that, as of v4, &lt;a href=&quot;https://twitter.com/Lee_Holmes/status/870414027473666048&quot;&gt;Get-Random is safe to use for password generation&lt;/a&gt;.
Lee is a Lead Security Architect for Azure Management at Microsoft.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Adding Updates to a Wim File</title><link>https://ngetchell.com/blog/adding-updates-to-a-wim-file/</link><guid isPermaLink="true">https://ngetchell.com/blog/adding-updates-to-a-wim-file/</guid><description>Even with Microsoft releasing new Windows 10 builds on a twice-yearly basis, there is still a case to be made to slipstream updates into your install media.</description><pubDate>Thu, 08 Jun 2017 08:30:22 GMT</pubDate><content:encoded>
&lt;p&gt;Even with Microsoft releasing new Windows 10 builds on a twice-yearly basis, there is still a case to be made to slipstream updates into your install media.
First, you never have to worry about whether your computer gets needed patches.
If you build in protection against the Wanna Cry malware by patching &lt;a href=&quot;https://technet.microsoft.com/en-us/library/security/ms17-010.aspx&quot;&gt;MS17-010&lt;/a&gt; you can.
Second, it saves a decent amount of time during computer provisioning.
No need to push down the original copy of a file as well as the updated one included in the latest Windows update.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Function&lt;/span&gt;&lt;span&gt; Update-WindowsImageFile&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    [&lt;/span&gt;&lt;span&gt;cmdletbinding&lt;/span&gt;&lt;span&gt;()]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    param&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;Parameter&lt;/span&gt;&lt;span&gt;(Mandatory &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $true&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;string&lt;/span&gt;&lt;span&gt;]$Path&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;Parameter&lt;/span&gt;&lt;span&gt;(Mandatory &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $true&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;string&lt;/span&gt;&lt;span&gt;]$MountPath&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;string&lt;/span&gt;&lt;span&gt;]$UpdateDirectory &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &quot;C:\windows\SoftwareDistribution\Download\&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;Parameter&lt;/span&gt;&lt;span&gt;(Mandatory &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $true&lt;/span&gt;&lt;span&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        [&lt;/span&gt;&lt;span&gt;int&lt;/span&gt;&lt;span&gt;]$ImageIndex&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $WimPath &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Resolve-Path&lt;/span&gt;&lt;span&gt; $Path&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $MountPath &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Resolve-Path&lt;/span&gt;&lt;span&gt; $MountPath&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    $UpdatePath &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Resolve-Path&lt;/span&gt;&lt;span&gt; $UpdateDirectory&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Mount-WindowsImage&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path $MountPath &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Index $ImageIndex &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;ImagePath $WimPath&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Get-ChildItem&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path $UpdatePath &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Include &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;.cab &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Recurse &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; ForEach-Object&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        $FileName &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $_.BaseName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        try&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            Add-WindowsPackage&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;PackagePath &lt;/span&gt;&lt;span&gt;$_.FullName&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path $MountPath&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        catch&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            Write-Error&lt;/span&gt;&lt;span&gt; &quot;Unable to install $Filename&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Dismount-WindowsImage&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path $MountPath &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Save&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;Gather Updates Manually&lt;/h2&gt;



&lt;p&gt;Next you gather the updates bring up a fresh install, image it, then install Windows updates.
The “C:\windows\SoftwareDistribution\Download\” directory should have all of the updates you’d need.
Be aware that express updates cannot be added to a wim file.
Express updates allow computers to download only the new bits needed from this month’s patches.
You have to keep your computer up-to-date to be able to use express updates.
For this exercise we’ll be using the cumulative updates.&lt;/p&gt;



&lt;p&gt;When you run this you’ll likely get errors when certain Windows updates fail to install.
The error message will contain the KB and if the file name contains the word ‘express’ you need to download the full update at the &lt;a href=&quot;https://www.catalog.update.microsoft.com&quot;&gt;Microsoft Update Catalog&lt;/a&gt;.&lt;/p&gt;



&lt;h2&gt;Download the latest Cumulative Update&lt;/h2&gt;



&lt;p&gt;A man that goes by &lt;a href=&quot;https://github.com/keithga&quot;&gt;keithga on GitHub&lt;/a&gt; wrote a create script to identify and download the latest cumulative update for your build.
You can find the &lt;a href=&quot;https://gist.github.com/keithga/1ad0abd1f7ba6e2f8aff63d94ab03048&quot;&gt;Gist&lt;/a&gt; on GitHub.
Click the Raw button to get a copy-and-pasteable version of the script and save it as Get-LatestUpdate.ps1.&lt;/p&gt;



&lt;p&gt;To use the script do the following:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;\Get-LatestUpdate.ps1&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Build &lt;/span&gt;&lt;span&gt;15063&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Download &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Path .\&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Downloading the latest cumulative update should start your install.wim file off on the right foot.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Never Lose Your Work at the Console</title><link>https://ngetchell.com/blog/never-lose-work/</link><guid isPermaLink="true">https://ngetchell.com/blog/never-lose-work/</guid><description>If you’re like me, every once in a while you have a dash of brilliance, write the perfect one-liner, but forget to record your work. You know you solved this problem already, but none of your documentation bears witness. You’re a trapeze artist without a safety net when you work at the console. Now, between […]</description><pubDate>Wed, 26 Oct 2016 07:20:18 GMT</pubDate><content:encoded>
&lt;p&gt;If you’re like me, every once in a while you have a dash of brilliance, write the perfect one-liner, but forget to record your work.
You know you solved this problem already, but none of your documentation bears witness.
You’re a trapeze artist without a safety net when you work at the console.
Now, between transcripts, saving previous output, and HistoryPX, you won’t have to worry.&lt;/p&gt;



&lt;h2&gt;Transcripts&lt;/h2&gt;



&lt;p&gt;Transcripts are exactly what you think they are.
They are a character for character representations of what happened at the console.
To start saving a transcript you run the &lt;em&gt;Start-Transcript&lt;/em&gt; cmdlet with a filepath.
Transcripts will store all of your commands as well as whatever is written to the pipeline using &lt;a href=&quot;https://ngetchell.com/posts/formatting-output/&quot;&gt;Out-Default&lt;/a&gt;.
Stopping a transcript is as easy as running &lt;em&gt;Stop-Transcript&lt;/em&gt;.&lt;/p&gt;



&lt;p&gt;If you ever log a bug report with any open-source modules on GitHub attaching your transcript log is a great idea.
The developer gets more than a vague error report and you’re more likely to get your bug squashed.&lt;/p&gt;



&lt;p&gt;If your as lazy as I am, you likely don’t want to have to remember to run a transcript cmdlet at the beginning of every PowerShell session.
That sounds too much like work.
Instead, add the following code to your PowerShell profile.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$publishDate:(&lt;/span&gt;&lt;span&gt;Get-Date&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;format &lt;/span&gt;&lt;span&gt;&quot;yyyy-MM-dd-hh-mm-ss&quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Start-Transcript&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path ~\Documents\WindowsPowerShell\Transcripts&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;$Date.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;No more remembering and you have a log of all of your work.
Your transcripts will be stored in the Transcripts folder in WindowsPowerShell.&lt;/p&gt;



&lt;h2&gt;Out-Variable&lt;/h2&gt;



&lt;p&gt;For something less formal than a transcript you can use the OutVariable parameter for the &lt;a href=&quot;https://ngetchell.com/posts/formatting-output/&quot;&gt;Out-Default&lt;/a&gt; cmdlet.
&lt;em&gt;Out-Default&lt;/em&gt; runs whenever there is something left over in the pipeline.
That is what writes to the console.&lt;/p&gt;



&lt;p&gt;We can leverage a little-known feature called Default Parameter Values to save the output.
Here, you specify what cmdlet, what parameter, and what value to pass to the parameter.
Now whenever the cmdlet is run, the value is passed to the specified parameter.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;PS:&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; $PSDefaultParameterValues[&lt;/span&gt;&lt;span&gt;&apos;out-default:outvariable&apos;&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &apos;PreviousOutput&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;PS:&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; Get-Process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name PowerShell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-------&lt;/span&gt;&lt;span&gt;  ------&lt;/span&gt;&lt;span&gt;    -----&lt;/span&gt;&lt;span&gt;      -----&lt;/span&gt;&lt;span&gt;     ------&lt;/span&gt;&lt;span&gt;     --&lt;/span&gt;&lt;span&gt;  --&lt;/span&gt;&lt;span&gt; -----------&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    375&lt;/span&gt;&lt;span&gt;      24&lt;/span&gt;&lt;span&gt;    48072&lt;/span&gt;&lt;span&gt;      90832&lt;/span&gt;&lt;span&gt;       0.39&lt;/span&gt;&lt;span&gt;   8116&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    594&lt;/span&gt;&lt;span&gt;      34&lt;/span&gt;&lt;span&gt;    87088&lt;/span&gt;&lt;span&gt;     132444&lt;/span&gt;&lt;span&gt;       3.33&lt;/span&gt;&lt;span&gt;   9196&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    380&lt;/span&gt;&lt;span&gt;      24&lt;/span&gt;&lt;span&gt;    46064&lt;/span&gt;&lt;span&gt;      88872&lt;/span&gt;&lt;span&gt;       0.48&lt;/span&gt;&lt;span&gt;   9336&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    669&lt;/span&gt;&lt;span&gt;      34&lt;/span&gt;&lt;span&gt;    66748&lt;/span&gt;&lt;span&gt;     110692&lt;/span&gt;&lt;span&gt;       2.89&lt;/span&gt;&lt;span&gt;  10784&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;PS:&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; $PreviousOutput&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-------&lt;/span&gt;&lt;span&gt;  ------&lt;/span&gt;&lt;span&gt;    -----&lt;/span&gt;&lt;span&gt;      -----&lt;/span&gt;&lt;span&gt;     ------&lt;/span&gt;&lt;span&gt;     --&lt;/span&gt;&lt;span&gt;  --&lt;/span&gt;&lt;span&gt; -----------&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    375&lt;/span&gt;&lt;span&gt;      24&lt;/span&gt;&lt;span&gt;    48072&lt;/span&gt;&lt;span&gt;      90832&lt;/span&gt;&lt;span&gt;       0.39&lt;/span&gt;&lt;span&gt;   8116&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    594&lt;/span&gt;&lt;span&gt;      34&lt;/span&gt;&lt;span&gt;    87088&lt;/span&gt;&lt;span&gt;     132444&lt;/span&gt;&lt;span&gt;       3.33&lt;/span&gt;&lt;span&gt;   9196&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    380&lt;/span&gt;&lt;span&gt;      24&lt;/span&gt;&lt;span&gt;    46064&lt;/span&gt;&lt;span&gt;      88872&lt;/span&gt;&lt;span&gt;       0.48&lt;/span&gt;&lt;span&gt;   9336&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    669&lt;/span&gt;&lt;span&gt;      34&lt;/span&gt;&lt;span&gt;    66748&lt;/span&gt;&lt;span&gt;     110692&lt;/span&gt;&lt;span&gt;       2.94&lt;/span&gt;&lt;span&gt;  10784&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;After running the above code you can now retrieve any previous pipeline output that was sent to the console screen.
This is also something you can put in your profile so you don’t have to remember.&lt;/p&gt;



&lt;h2&gt;HistoryPX&lt;/h2&gt;



&lt;p&gt;&lt;a href=&quot;http://kirkmunro.com/&quot;&gt;Kirk Munro&lt;/a&gt; has written a beautiful module for handling your PowerShell history.
There is even talks with &lt;a href=&quot;https://github.com/PowerShell/PowerShell-RFC/issues/27&quot;&gt;bringing HistoryPX into PowerShell&lt;/a&gt; so it is installed by default.&lt;/p&gt;



&lt;p&gt;For now though, you install it using the following.
Note: SnippetPx is also a module written by Kirk.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Install-Module&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;AllowClobber HistoryPx&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;SnippetPx&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Then, all you have to do import the HistoryPx module and you’re off to the races.
Notice how once you import the module you automatically get the previous output saved in the &lt;em&gt;$&lt;/em&gt;__ variable.
You also get the ability to grab the output from previous commands using &lt;em&gt;Get-History&lt;/em&gt; AND you get measure-command statistics.
All for simply importing HistoryPx.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Git:&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; Import-Module&lt;/span&gt;&lt;span&gt; historypx&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Git:&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; get-process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;name powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-------&lt;/span&gt;&lt;span&gt;  ------&lt;/span&gt;&lt;span&gt;    -----&lt;/span&gt;&lt;span&gt;      -----&lt;/span&gt;&lt;span&gt;     ------&lt;/span&gt;&lt;span&gt;     --&lt;/span&gt;&lt;span&gt;  --&lt;/span&gt;&lt;span&gt; -----------&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    375&lt;/span&gt;&lt;span&gt;      24&lt;/span&gt;&lt;span&gt;    48040&lt;/span&gt;&lt;span&gt;      90816&lt;/span&gt;&lt;span&gt;       0.39&lt;/span&gt;&lt;span&gt;   8116&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    594&lt;/span&gt;&lt;span&gt;      34&lt;/span&gt;&lt;span&gt;    87080&lt;/span&gt;&lt;span&gt;     132440&lt;/span&gt;&lt;span&gt;       3.33&lt;/span&gt;&lt;span&gt;   9196&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    380&lt;/span&gt;&lt;span&gt;      24&lt;/span&gt;&lt;span&gt;    46032&lt;/span&gt;&lt;span&gt;      88856&lt;/span&gt;&lt;span&gt;       0.48&lt;/span&gt;&lt;span&gt;   9336&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    889&lt;/span&gt;&lt;span&gt;      36&lt;/span&gt;&lt;span&gt;    73336&lt;/span&gt;&lt;span&gt;     118452&lt;/span&gt;&lt;span&gt;       3.97&lt;/span&gt;&lt;span&gt;  10784&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;PS:&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; $__&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-------&lt;/span&gt;&lt;span&gt;  ------&lt;/span&gt;&lt;span&gt;    -----&lt;/span&gt;&lt;span&gt;      -----&lt;/span&gt;&lt;span&gt;     ------&lt;/span&gt;&lt;span&gt;     --&lt;/span&gt;&lt;span&gt;  --&lt;/span&gt;&lt;span&gt; -----------&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    375&lt;/span&gt;&lt;span&gt;      24&lt;/span&gt;&lt;span&gt;    48040&lt;/span&gt;&lt;span&gt;      90816&lt;/span&gt;&lt;span&gt;       0.39&lt;/span&gt;&lt;span&gt;   8116&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    594&lt;/span&gt;&lt;span&gt;      34&lt;/span&gt;&lt;span&gt;    87080&lt;/span&gt;&lt;span&gt;     132440&lt;/span&gt;&lt;span&gt;       3.33&lt;/span&gt;&lt;span&gt;   9196&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    380&lt;/span&gt;&lt;span&gt;      24&lt;/span&gt;&lt;span&gt;    46032&lt;/span&gt;&lt;span&gt;      88856&lt;/span&gt;&lt;span&gt;       0.48&lt;/span&gt;&lt;span&gt;   9336&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    889&lt;/span&gt;&lt;span&gt;      36&lt;/span&gt;&lt;span&gt;    73336&lt;/span&gt;&lt;span&gt;     118452&lt;/span&gt;&lt;span&gt;       3.97&lt;/span&gt;&lt;span&gt;  10784&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;PS:&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; Get-History&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;  Id CommandLine                    Duration       Success &lt;/span&gt;&lt;span&gt;#Err #Out #Src Output&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;  --&lt;/span&gt;&lt;span&gt; -----------&lt;/span&gt;&lt;span&gt;                    --------&lt;/span&gt;&lt;span&gt;       -------&lt;/span&gt;&lt;span&gt; ----&lt;/span&gt;&lt;span&gt; ----&lt;/span&gt;&lt;span&gt; ----&lt;/span&gt;&lt;span&gt; ------&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;  18&lt;/span&gt;&lt;span&gt; Clear-History&lt;/span&gt;&lt;span&gt;                  00&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;00&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;00.002&lt;/span&gt;&lt;span&gt;   True&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;  19&lt;/span&gt;&lt;span&gt; Import-Module&lt;/span&gt;&lt;span&gt; historypx        &lt;/span&gt;&lt;span&gt;00&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;00&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;00.010&lt;/span&gt;&lt;span&gt;   True&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;  20&lt;/span&gt;&lt;span&gt; get-process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;name powershell   &lt;/span&gt;&lt;span&gt;00&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;00&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;00.021&lt;/span&gt;&lt;span&gt;   True         &lt;/span&gt;&lt;span&gt;4&lt;/span&gt;&lt;span&gt;    1&lt;/span&gt;&lt;span&gt;    {System.Diagnostics.Process (powershell)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;  21&lt;/span&gt;&lt;span&gt; $__                            &lt;/span&gt;&lt;span&gt;00&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;00&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt;00.019&lt;/span&gt;&lt;span&gt;   True         &lt;/span&gt;&lt;span&gt;4&lt;/span&gt;&lt;span&gt;    1&lt;/span&gt;&lt;span&gt;    {System.Diagnostics.Process (powershell)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;PS:&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;Get-History&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Id &lt;/span&gt;&lt;span&gt;20&lt;/span&gt;&lt;span&gt;).Output&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-------&lt;/span&gt;&lt;span&gt;  ------&lt;/span&gt;&lt;span&gt;    -----&lt;/span&gt;&lt;span&gt;      -----&lt;/span&gt;&lt;span&gt;     ------&lt;/span&gt;&lt;span&gt;     --&lt;/span&gt;&lt;span&gt;  --&lt;/span&gt;&lt;span&gt; -----------&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    375&lt;/span&gt;&lt;span&gt;      24&lt;/span&gt;&lt;span&gt;    48040&lt;/span&gt;&lt;span&gt;      90816&lt;/span&gt;&lt;span&gt;       0.39&lt;/span&gt;&lt;span&gt;   8116&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    594&lt;/span&gt;&lt;span&gt;      34&lt;/span&gt;&lt;span&gt;    87080&lt;/span&gt;&lt;span&gt;     132440&lt;/span&gt;&lt;span&gt;       3.33&lt;/span&gt;&lt;span&gt;   9196&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    380&lt;/span&gt;&lt;span&gt;      24&lt;/span&gt;&lt;span&gt;    46032&lt;/span&gt;&lt;span&gt;      88856&lt;/span&gt;&lt;span&gt;       0.48&lt;/span&gt;&lt;span&gt;   9336&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    889&lt;/span&gt;&lt;span&gt;      36&lt;/span&gt;&lt;span&gt;    73336&lt;/span&gt;&lt;span&gt;     118452&lt;/span&gt;&lt;span&gt;       4.27&lt;/span&gt;&lt;span&gt;  10784&lt;/span&gt;&lt;span&gt;   8&lt;/span&gt;&lt;span&gt; powershell&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;With DefaultParameters, transcripts, and HistoryPx you no longer have an excuse to lose your work.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Tail a File in PowerShell</title><link>https://ngetchell.com/blog/tail-a-file-in-powershell/</link><guid isPermaLink="true">https://ngetchell.com/blog/tail-a-file-in-powershell/</guid><description>In my limited Linux administration experience I got used to dealing with text. Text documents that held configuration files, text manipulation in the pipeline, text everywhere. Every search was just a grep away. When troubleshooting in Linux you’re constantly reading log files. Checking for changes and seeing if your what you’re flushing comes out the […]</description><pubDate>Wed, 19 Oct 2016 07:20:57 GMT</pubDate><content:encoded>
&lt;p&gt;In my limited Linux administration experience I got used to dealing with text.
Text documents that held configuration files, text manipulation in the pipeline, text everywhere.
Every search was just a grep away.&lt;/p&gt;



&lt;p&gt;When troubleshooting in Linux you’re constantly reading log files.
Checking for changes and seeing if your what you’re flushing comes out the correct pipe.
A tool that made the job easier was the tail command with the -f argument.
This allows you to &lt;em&gt;follow&lt;/em&gt; whatever is appended to the file in question.
You could now navigate to your webpage and see the apache access.log file written to in real-time.
I always wanted something like that in Windows.&lt;/p&gt;



&lt;h2&gt;Get-Content&lt;/h2&gt;



&lt;p&gt;That is where Get-Content comes into play.
Normally, Get-Content retrieves whatever is in your file, line by line.
That’s useful for piping computer names into another function.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Content&lt;/span&gt;&lt;span&gt; Computers.txt &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Get-RebootingPendingStatus&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You can also use Get-Content -Raw to work with the entire file at once.
Maybe you’re running a Regular Expression against an HTML file (ewwww I know) and line by line doesn’t cut it.
For that, the raw option is available.&lt;/p&gt;



&lt;p&gt;We, however, are interested in the -Tail parameter (I wonder where Microsoft got the name for that?!!?!) along with the -Wait parameter.
Imagine the following example:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$FilePath &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &quot;~\Desktop\Tail.txt&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;..&lt;/span&gt;&lt;span&gt;100&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; ForEach-Object&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    &quot;echo &lt;/span&gt;&lt;span&gt;$_&lt;/span&gt;&lt;span&gt;&quot;&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Out-File&lt;/span&gt;&lt;span&gt; $FilePath &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Append&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Start-Sleep&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Seconds &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;I know this is a bit contrived but this example will generate text to the tail.txt file located on your desktop.
We add Start-Sleep so we have time to fire up Get-Content.
When you run this the For each loop will run 100 times and will echo the loop counter to the tail file.
&lt;strong&gt;Run this then open up ANOTHER PowerShell window.&lt;/strong&gt; You should begin to see the results trickle in.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;PS:\&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; Get-Content&lt;/span&gt;&lt;span&gt; ~\Desktop\Tail.txt &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Tail &lt;/span&gt;&lt;span&gt;10&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Wait&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;6&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;9&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;10&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;11&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;12&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;13&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;14&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;echo &lt;/span&gt;&lt;span&gt;15&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This will show the last 10 lines and wait for any more that get appended.
Ctrl+C a couple times breaks out of the wait loop.&lt;/p&gt;



&lt;p&gt;This example could have easily been an application install trace, an IIS log, or the markdown file I used to write this post!&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Update-ModuleManifest is Back</title><link>https://ngetchell.com/blog/update-modulemanifest-back/</link><guid isPermaLink="true">https://ngetchell.com/blog/update-modulemanifest-back/</guid><description>Starting with Windows Management Framework 5.1 PowerShell now comes with Update-ModuleManifest. This is after Update-ModuleManifest broke and was removed from WMF 5. WMF 5.1 has been added to Windows 10 build 14342 and can be installed using the fast ring. Note: If you’ve been relying on a wildcard to load all of your exported functions […]</description><pubDate>Wed, 01 Jun 2016 15:02:40 GMT</pubDate><content:encoded>
&lt;p&gt;Starting with &lt;a href=&quot;https://blogs.msdn.microsoft.com/powershell/2016/04/06/windows-management-framework-5-0-updates-and-wmf-5-1/&quot;&gt;Windows Management Framework 5.1&lt;/a&gt; PowerShell now comes with Update-ModuleManifest.
This is after Update-ModuleManifest &lt;a href=&quot;https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/13799043-update-modulemanifest-flattening-functionstoexport&quot;&gt;broke&lt;/a&gt; and was removed from WMF 5.&lt;/p&gt;



&lt;p&gt;WMF 5.1 has been added to Windows 10 build 14342 and can be installed using the fast ring.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you’ve been relying on a wildcard to load all of your exported functions you may run into issues.&lt;/p&gt;



&lt;p&gt;See, using wildcards cause up to &lt;a href=&quot;https://www.sapien.com/blog/2016/03/24/exporting-from-modules-a-reminder/&quot;&gt;15 seconds&lt;/a&gt; of lag when loading the module.
The new Update-ModuleManifest now explicitly creates an empty collection if you don’t provide input to the corresponding parameter.
Make sure to explicitly state which functions, variables, and cmdlets.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>How I Work: Pester Testing</title><link>https://ngetchell.com/blog/work-pester-testing/</link><guid isPermaLink="true">https://ngetchell.com/blog/work-pester-testing/</guid><description>Ever since the 2015 North America PowerShell Summit I’ve become addicted to Pester testing. I use it for Unit Testing as well as Operational Validation. Not only the Pester open source but it is actually included in Windows 10. The rumor at the summit was that this was the first open source software built into […]</description><pubDate>Mon, 23 May 2016 09:43:25 GMT</pubDate><content:encoded>
&lt;p&gt;Ever since the 2015 North America PowerShell Summit I’ve become addicted to &lt;a href=&quot;https://github.com/pester/Pester&quot;&gt;Pester&lt;/a&gt; testing.
I use it for Unit Testing as well as &lt;a href=&quot;https://pshirwin.wordpress.com/2016/04/29/operational-readiness-validation-gotchas/&quot;&gt;Operational Validation&lt;/a&gt;.
Not only the Pester open source but it is actually included in Windows 10.
The rumor at the summit was that this was the first open source software built into Windows.
This is truly a new Microsoft.&lt;/p&gt;



&lt;p&gt;I also use &lt;a href=&quot;https://ngetchell.com/posts/generic-pester-tests/&quot;&gt;Generic Pester Tests&lt;/a&gt; to make sure my code stays up to my standards.
Exported functions should have great help.
Modules should be able to pass automated tests for publishing and consistency purposes.
A constant reminder that your code won’t be able to be published from the &lt;a href=&quot;https://www.powershellgallery.com/&quot;&gt;PowerShell Gallery&lt;/a&gt; or that your code is currently without help really motivates me to do better.&lt;/p&gt;



&lt;h2&gt;TDD&lt;/h2&gt;



&lt;p&gt;I now follow the Test-Drive Development (TDD) method for producing my PowerShell code.
I prototype my function enough to get it to show up in an automated Pester test, write the Pester tests to define my inputs and outputs of my new function, then write the actual function.
This forces me to think before I type.
I have to know exactly how the function will perform because I have already defined it’s interface through the Pester tests.&lt;/p&gt;



&lt;p&gt;To make sure I’m accomplishing all of my goals enforced by Pester I add a second console window to my &lt;a href=&quot;https://conemu.github.io/&quot;&gt;ConEmu&lt;/a&gt; window that simply runs Pester tests on loop.
To get the tests to run on file save I use &lt;a href=&quot;https://github.com/smurawski/PowerShellGuard&quot;&gt;PowerShell Guard&lt;/a&gt; written by &lt;a href=&quot;https://twitter.com/StevenMurawski&quot;&gt;Steven Murawski&lt;/a&gt; and run the following command after it is installed.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;New-guard&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path Git:\CIUtils\ &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Recurse &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;TestCommand &lt;/span&gt;&lt;span&gt;Invoke-Pester&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Wait&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;When I work I usually open up a smaller console window inside of ConEmu and whenever I change I file it kicks off the specified tests.&lt;/p&gt;



&lt;p&gt;Now, after ever change I make to code I get the instant feedback if one of my changes broke any of the functionality expected from my functions.
This keeps me from investing time solving problems that I don’t need to solve.
If I fail a test, I go and fix it.
I don’t find out hours later that I introduced a breaking change then built on top of that bad code.
It forces good habits and has served me well while creating &lt;a href=&quot;https://www.powershellgallery.com/packages/PSPushover/1.0.1&quot;&gt;PSPushover&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;What does your process look like when you write your code?&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Generic Pester Tests</title><link>https://ngetchell.com/blog/generic-pester-tests/</link><guid isPermaLink="true">https://ngetchell.com/blog/generic-pester-tests/</guid><description>Writing good Pester Tests is hard. Use your PowerShell knowledge to make things easier with Generic Pester Tests. Module Testing There are many requirements for module manifest to work everywhere. You need a root module to load your .PSM1, you need a version number so PowerShell knows which version to load into the console at […]</description><pubDate>Mon, 16 May 2016 09:07:05 GMT</pubDate><content:encoded>
&lt;p&gt;Writing good Pester Tests is hard.
Use your PowerShell knowledge to make things easier with Generic Pester Tests.&lt;/p&gt;



&lt;h2&gt;Module Testing&lt;/h2&gt;



&lt;p&gt;There are many requirements for module manifest to work everywhere.
You need a root module to load your .PSM1, you need a version number so PowerShell knows which version to load into the console at runtime, and there should also be identifying information for more information.
If you plan on publishing to the &lt;a href=&quot;https://www.powershellgallery.com/&quot;&gt;PowerShell Gallery&lt;/a&gt; you also need to include a description.
Why not force those good habits with a Generic module test.&lt;/p&gt;



&lt;p&gt;My module structure as show by &lt;strong&gt;tree /F /A&lt;/strong&gt; is as follows for my CIUtils module.
You’ll see some familar files.
I have my &lt;a href=&quot;https://git-scm.com/docs/gitignore&quot;&gt;gitignore&lt;/a&gt;, my pester tests in the Tests folder, and my module source code in a folder named after the module.
Inside of the module folder is the Public and Private folders.
Public folders contains functions in PS1 files that are exported to the console when the module is loaded.
The private folder is similar but is not exported for outside use.&lt;/p&gt;



&lt;p&gt;The first thing my Generic module test does is load the module file.
Since my modules are laid out in a predictable fashion I can write a script to handle them.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$ModuleName &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Split-Path&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;Resolve-Path&lt;/span&gt;&lt;span&gt; &quot;&lt;/span&gt;&lt;span&gt;$PSScriptRoot&lt;/span&gt;&lt;span&gt;\..\&quot;&lt;/span&gt;&lt;span&gt; ) &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Leaf&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$ModuleManifest &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Resolve-Path&lt;/span&gt;&lt;span&gt; &quot;&lt;/span&gt;&lt;span&gt;$PSScriptRoot&lt;/span&gt;&lt;span&gt;\..\$ModuleName\$ModuleName.psd1&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Import-Module&lt;/span&gt;&lt;span&gt; $ModuleManifest&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This is something I put at the top of every one of my Pester tests.
It loads the module for testing no matter what folder I call it from.
&lt;strong&gt;Note: Make sure to run ‘Remove-Module $ModuleName’ at the bottom of the test to remove the module from the console.&lt;/strong&gt;&lt;/p&gt;



&lt;p&gt;Now comes the testing of the module itself.
I use the Test-ModuleManifest cmdlet to confirm that I have a valid manifest.
I also test that the guid is valid, the root module is populated, the version and be converted to the .NET type [Version], and that there is a description for the PowerShell Gallery.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Describe &lt;/span&gt;&lt;span&gt;&apos;Module Information&apos;&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Tags &lt;/span&gt;&lt;span&gt;&apos;Command&apos;&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Context &lt;/span&gt;&lt;span&gt;&apos;Manifest Testing&apos;&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        It &lt;/span&gt;&lt;span&gt;&apos;Valid Module Manifest&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                $&lt;/span&gt;&lt;span&gt;Script&lt;/span&gt;&lt;span&gt;:Manifest &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Test-ModuleManifest&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path $ModuleManifest &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;ErrorAction Stop &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;WarningAction SilentlyContinue&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            } &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Should Not &lt;/span&gt;&lt;span&gt;Throw&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        It &lt;/span&gt;&lt;span&gt;&apos;Valid Manifest Name&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $&lt;/span&gt;&lt;span&gt;Script&lt;/span&gt;&lt;span&gt;:Manifest.Name &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Should be $ModuleName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        It &lt;/span&gt;&lt;span&gt;&apos;Generic Version Check&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $&lt;/span&gt;&lt;span&gt;Script&lt;/span&gt;&lt;span&gt;:Manifest.Version &lt;/span&gt;&lt;span&gt;-as&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;Version&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Should Not BeNullOrEmpty&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        It &lt;/span&gt;&lt;span&gt;&apos;Valid Manifest Description&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $&lt;/span&gt;&lt;span&gt;Script&lt;/span&gt;&lt;span&gt;:Manifest.Description &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Should Not BeNullOrEmpty&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        It &lt;/span&gt;&lt;span&gt;&apos;Valid Manifest Root Module&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $&lt;/span&gt;&lt;span&gt;Script&lt;/span&gt;&lt;span&gt;:Manifest.RootModule &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Should Be &lt;/span&gt;&lt;span&gt;&quot;$ModuleName.psm1&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        It &lt;/span&gt;&lt;span&gt;&apos;Valid Manifest GUID&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $&lt;/span&gt;&lt;span&gt;Script&lt;/span&gt;&lt;span&gt;:Manifest.Guid &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; SHould be &lt;/span&gt;&lt;span&gt;&apos;df5fcbbb-0f5a-4f6d-a7d1-2127ca0b3955&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        It &lt;/span&gt;&lt;span&gt;&apos;No Format File&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $&lt;/span&gt;&lt;span&gt;Script&lt;/span&gt;&lt;span&gt;:Manifest.ExportedFormatFiles &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Should BeNullOrEmpty&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        It &lt;/span&gt;&lt;span&gt;&apos;Required Modules&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $&lt;/span&gt;&lt;span&gt;Script&lt;/span&gt;&lt;span&gt;:Manifest.RequiredModules &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Should BeNullOrEmpty&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Context &lt;/span&gt;&lt;span&gt;&apos;Exported Functions&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        It &lt;/span&gt;&lt;span&gt;&apos;Proper Number of Functions Exported&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $ExportedCount &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Module $ModuleName &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Measure-Object&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ExpandProperty Count&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $FileCount &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-ChildItem&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path &lt;/span&gt;&lt;span&gt;&quot;&lt;/span&gt;&lt;span&gt;$PSScriptRoot&lt;/span&gt;&lt;span&gt;\..\$ModuleName\Public&quot;&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Filter &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;.ps1 &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Measure-Object&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ExpandProperty Count&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            $ExportedCount &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Should be $FileCount&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Another thing I do is match all of the PS1 files in the Public folder to make sure my module exports the correct amount of functions.
This helps catching renaming issues when a function name and the name of a PS1 file don’t match.&lt;/p&gt;



&lt;p&gt;All of these tests should be a good place to start from to make sure your module is up to snuff.&lt;/p&gt;



&lt;h2&gt;Function Analysis&lt;/h2&gt;



&lt;p&gt;Generic Pester tests can also be used to check that your functions contain the necessary help for your users.
I grab all of the exported functions and check to see if the Synopsis, Description and at least one Example are present.
This forces good habits when creating your functions.
Make &lt;a href=&quot;https://twitter.com/juneb_get_help&quot;&gt;June Blender&lt;/a&gt; proud with your help.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Module $ModuleName &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; ForEach-Object&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Describe &lt;/span&gt;&lt;span&gt;&apos;Help&apos;&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Tags &lt;/span&gt;&lt;span&gt;&apos;Help&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        Context &lt;/span&gt;&lt;span&gt;&quot;Function - &lt;/span&gt;&lt;span&gt;$_&lt;/span&gt;&lt;span&gt;&quot;&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            It &lt;/span&gt;&lt;span&gt;&apos;Synopsis&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                Get-Help&lt;/span&gt;&lt;span&gt; $_&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ExpandProperty synopsis &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; should not benullorempty&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            It &lt;/span&gt;&lt;span&gt;&apos;Description&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                Get-Help&lt;/span&gt;&lt;span&gt; $_&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ExpandProperty Description &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; should not benullorempty&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            It &lt;/span&gt;&lt;span&gt;&apos;Examples&apos;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                $Examples &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Help&lt;/span&gt;&lt;span&gt; $_&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ExpandProperty Examples &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Measure-Object&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;                $Examples.Count &lt;/span&gt;&lt;span&gt;-gt&lt;/span&gt;&lt;span&gt; 0&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Should be &lt;/span&gt;&lt;span&gt;$true&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;If you also run Pester tests to keep your modules, functions, or other works in line let me know in the comments.
A link to a GitHub Gist is best!&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Export to Excel</title><link>https://ngetchell.com/blog/export-to-excel/</link><guid isPermaLink="true">https://ngetchell.com/blog/export-to-excel/</guid><description>If you handle any sort of data in your job you’ve likely run into the common PowerShell cmdlets for dealing with data; Import-CSV, Export-CSV, Import-CliXML, and Export-Clixml. Sometimes, automation requires the processing of data. CSV and XML are both great ways to store and send data. The only thing is, no human chooses to manipulate […]</description><pubDate>Tue, 12 Apr 2016 08:25:00 GMT</pubDate><content:encoded>
&lt;p&gt;If you handle any sort of data in your job you’ve likely run into the common PowerShell cmdlets for dealing with data; Import-CSV, Export-CSV, Import-CliXML, and Export-Clixml. Sometimes, automation requires the processing of data. CSV and XML are both great ways to store and send data. The only thing is, no human &lt;strong&gt;chooses&lt;/strong&gt; to manipulate data in CSV or XML. That is, for better or for worse, in the realm of Excel.&lt;/p&gt;



&lt;h2&gt;Opening in Excel&lt;/h2&gt;



&lt;p&gt;Excel has the ability to natively open CSV files, the text import wizard can handle copy and pasting of delimited information, and Power Query offers the ability to use as &lt;a href=&quot;https://support.office.com/en-us/article/Connect-to-an-Excel-or-CSV-file-Power-Query-fc377b2e-a742-4dea-8d7c-8e0f18c8e765#__toc378183850&quot;&gt;CSV as a data source&lt;/a&gt;. The process from PowerShell to Excel is simple. Use the Export-CSV cmdlet to export your data and if you’re lazy, have PowerShell invoke the file to start up Excel.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Process&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Export-Csv&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path ~\Desktop\junk.csv &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Invoke-Item&lt;/span&gt;&lt;span&gt; ~\Desktop\junk.csv&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;There is a better way.&lt;/p&gt;



&lt;h2&gt;Import Excel&lt;/h2&gt;



&lt;p&gt;&lt;a href=&quot;http://dougfinke.com/blog/introducing-the-powershell-excel-module/&quot;&gt;Doug Finke&lt;/a&gt; has written a PowerShell module for exporting information directly into Excel. Not simply data but charts, conditional text, Pivot Tables, and much more.&lt;/p&gt;



&lt;p&gt;A quick way to tell if there are services you need to look into?&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Service&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Property DisplayName&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;Status&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;StartType &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Export-Excel&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;show &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Path ~\Desktop\Junk.xlsx &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;AutoFilter &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;AutoSize &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;BoldTopRow &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;ConditionalText &lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;( &lt;/span&gt;&lt;span&gt;New-ConditionalText&lt;/span&gt;&lt;span&gt; stop &lt;/span&gt;&lt;span&gt;New-ConditionalText&lt;/span&gt;&lt;span&gt; auto yellow )&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Check out the GitHub page for &lt;a href=&quot;https://github.com/dfinke/ImportExcel&quot;&gt;ImportExcel&lt;/a&gt; to get all of of the installation instructions as well as demonstrations on exactly how to use it. Automate the Excel reports you’ve been manipulating by hand for all of these years.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Installing Modules</title><link>https://ngetchell.com/blog/install-modules/</link><guid isPermaLink="true">https://ngetchell.com/blog/install-modules/</guid><description>Whether you’re writing scripts, functions to automate a repetitive task, or building a whole toolkit you should be familiar with installing modules. Modules let you group functions in a logical way. Creating a bunch of functions that automate part of your Active Directory environment? Group them all into a module. Modules help by letting you […]</description><pubDate>Tue, 05 Apr 2016 08:30:00 GMT</pubDate><content:encoded>
&lt;p&gt;Whether you’re writing scripts, functions to automate a repetitive task, or building a whole toolkit you should be familiar with installing modules.
Modules let you group functions in a logical way.
Creating a bunch of functions that automate part of your Active Directory environment?
Group them all into a module.
Modules help by letting you keep track of the version you have installed on your machine as well as allowing for automatic loading into the current session.&lt;/p&gt;



&lt;h2&gt;Module Contents&lt;/h2&gt;



&lt;p&gt;What makes up a module.
At the basic level, all you need is a .psm1 file with a function in it.
From there, you may have a module manifest file (.psd1) file that tracks the meta-data of your module (name, version, description, etc).
There can be help files, formatting files, as well as DLLs to help you complete the job.&lt;/p&gt;



&lt;h2&gt;Install Modules via File Copy&lt;/h2&gt;



&lt;p&gt;When installing modules from the internet or making your own you should be storing them in certain folders to make sure every PowerShell console window you open has access to them.
Running Import-Module -Path “C:\FakePath.psd1” isn’t a scalable solution.
There is an environment variable baked into PowerShell that determines where it looks for .psm1 and .psd1 files.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;env:&lt;/span&gt;&lt;span&gt;PSModulePath &lt;/span&gt;&lt;span&gt;-split&lt;/span&gt;&lt;span&gt; &quot;;&quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;&quot;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;$Env:PSModule path will return a list of directories PowerShell will search for modules.
The split command simply puts them all on their own line after splitting by the ‘;’ delimiter.
Put your module in one of these folders and any PowerShell console v3 or higher will automatically load your module for you.&lt;/p&gt;



&lt;p&gt;&lt;em&gt;Note: You have to match the folder name to the .psm1 or .psd1 file, otherwise the console will not find the module.&lt;/em&gt;&lt;/p&gt;



&lt;h2&gt;Install Modules via Cmdlets&lt;/h2&gt;



&lt;p&gt;With Windows 10 Microsoft shipped with a module repository called the &lt;a href=&quot;https://powershellgallery.com&quot;&gt;PowerShell Gallery&lt;/a&gt;.
Both Microsoft and the community could upload their modules to a place that can be downloaded from the console.&lt;/p&gt;



&lt;p&gt;The beauty of this method is that you don’t even need to leave the PowerShell console!
You can also grab the latest version of any installed modules very easily.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-InstalledModule&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Update-Module&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;force&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h3&gt;Private Repository&lt;/h3&gt;



&lt;p&gt;If you work for an enterprise and don’t want your code stored off-site or if you just don’t like the idea, you can host your own PowerShellGet repository using IIS.
Boe Prox put together a great guide on setting up a PowerShellGet (formally know as OneGet) repository for your site.
&lt;a href=&quot;http://learn-powershell.net/2014/04/11/setting-up-a-nuget-feed-for-use-with-oneget/&quot;&gt;Setting Up a NuGet Feed For Use with OneGet now PackageManagement&lt;/a&gt;.
This is the guide I followed to setup a repository at my work for easily sharing my modules with co-workers.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Time Your Script with Timespan Objects</title><link>https://ngetchell.com/blog/time-script-with-timespan/</link><guid isPermaLink="true">https://ngetchell.com/blog/time-script-with-timespan/</guid><description>Speed and consistency are the two main reasons people automate tasks using PowerShell. Give your script the same inputs and it should produce the same outputs. The consistency concept is easy. What about how much time is saved using PowerShell? We can achieve this using the Timespan object built into PowerShell. Start and Stop Times […]</description><pubDate>Wed, 30 Mar 2016 08:00:00 GMT</pubDate><content:encoded>
&lt;p&gt;Speed and consistency are the two main reasons people automate tasks using PowerShell.
Give your script the same inputs and it should produce the same outputs.
The consistency concept is easy.
What about how much time is saved using PowerShell? We can achieve this using the Timespan object built into PowerShell.&lt;/p&gt;



&lt;figure&gt;&lt;img src=&quot;https://ngetchell.com/wp-media/2026/07/timespan.png&quot; alt=&quot;XKCD&quot; /&gt;&lt;/figure&gt;



&lt;h2&gt;Start and Stop Times&lt;/h2&gt;



&lt;p&gt;A rudimentary way of keeping track of time in your code is to use Get-Date.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$StartTime &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Date&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Divide&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Number &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Dividend &lt;/span&gt;&lt;span&gt;39&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Divisor &lt;/span&gt;&lt;span&gt;3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$EndTime &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Date&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$EndTime.Subtract($StartTime)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Saving the start time and end times using Get-Date allows you to later subtract the two times to get an object whose type is Timespan.
Timespans are simply the time between two datetime objects.
Want to know how many days until Christmas 2020?&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$Christmas &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Date&lt;/span&gt;&lt;span&gt; 12&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;25&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;2020&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Now &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Date&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Christmas.Subtract($Now) &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ExpandProperty Days&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;Measure-Command&lt;/h2&gt;



&lt;p&gt;Another way to time your scripts is to use the Measure-Command cmdlet.
Measure-Command takes in an expression or script block and spits out how long it took to ran.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt; Measure-command&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;span&gt;Get-Module&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ListAvailable }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This will give you the timespan between the start of the command and the end.&lt;/p&gt;



&lt;h2&gt;Formatting Timespan&lt;/h2&gt;



&lt;p&gt;Simply knowing how long a script took is nice, but how about formatting the output for a report.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Measure-Command&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Start-Sleep&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Seconds (&lt;/span&gt;&lt;span&gt;Get-random&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Minimum &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Maximum &lt;/span&gt;&lt;span&gt;29&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Timespan &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Measure-Command&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Start-Sleep&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Seconds (&lt;/span&gt;&lt;span&gt;Get-random&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Minimum &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Maximum &lt;/span&gt;&lt;span&gt;29&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This should produce output similar to “The command finished in 0:00:10.0013427”.&lt;/p&gt;



&lt;p&gt;Now that you know how to generate timespan objects add the following code to your profile.ps1 file to countdown until New Years.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$CurrentYear &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-date&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ExpandProperty Year&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$NewYears &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Date&lt;/span&gt;&lt;span&gt; &quot;1/1/&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;($CurrentYear &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; 00:00:00&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Timespan &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; $NewYears.Subtract(&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;Get-date&lt;/span&gt;&lt;span&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;&quot;Days Until New Years &lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;($Timespan.Days)&lt;/span&gt;&lt;span&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content:encoded><category>PowerShell</category></item><item><title>Why Use Source Control</title><link>https://ngetchell.com/blog/use-source-control/</link><guid isPermaLink="true">https://ngetchell.com/blog/use-source-control/</guid><description>Source control, whether you’re writing one off scripts or automating intricate processes, is essential to your work. Simply keeping copies of your files scattered across your computer is not good enough. Source control will save you when you can’t figure out what changes you made that caused errors, when you can’t find the current version […]</description><pubDate>Tue, 22 Mar 2016 08:35:00 GMT</pubDate><content:encoded>
&lt;p&gt;Source control, whether you’re writing one off scripts or automating intricate processes, is essential to your work.
Simply keeping copies of your files scattered across your computer is not good enough.
Source control will save you when you can’t figure out what changes you made that caused errors, when you can’t find the &lt;strong&gt;current&lt;/strong&gt; version of your script, or when you have to work with a co-worker on you need to collaborate.&lt;/p&gt;



&lt;h2&gt;Tracking Changes&lt;/h2&gt;



&lt;p&gt;First and foremost, you want to know what changes you’ve made over time, especially when a change you’ve made in production is producing errors.
Simply comparing two text files by hand isn’t how developers check for bugs and neither should IT Pros.
Good source control will show you exactly what has changed between two versions of your code and allow you to revert back to the working file.
This concept is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Atomic_commit&quot;&gt;atomic changes&lt;/a&gt; and allows you to see exactly what changed over time.&lt;/p&gt;



&lt;h2&gt;Git&lt;/h2&gt;



&lt;p&gt;Git was created by Linus Torvalds, yes, the &lt;a href=&quot;https://en.wikipedia.org/wiki/Linus_Torvalds&quot;&gt;Linus Tarvolds&lt;/a&gt; that created the Linux kernel.
Linus was unhappy with the source control that the Linux kernel was kept in so he wrote his own.&lt;/p&gt;



&lt;p&gt;The &lt;a href=&quot;https://github.com/search?utf8=%E2%9C%93&amp;amp;q=language%3Apowershell+language%3APowerShell&amp;amp;type=Repositories&amp;amp;ref=advsearch&amp;amp;l=PowerShell&amp;amp;l=&quot;&gt;PowerShell community uses Git&lt;/a&gt; and Microsoft is even releasing components of PowerShell on Github as the &lt;a href=&quot;https://github.com/PowerShell&quot;&gt;PowerShell Team&lt;/a&gt;.
If you’re wondering which source control system to use, just pick Git.&lt;/p&gt;



&lt;p&gt;&lt;a href=&quot;https://git-for-windows.github.io/&quot;&gt;Git for Windows&lt;/a&gt; even bundles some great unix applications so you can use Grep, ssh, and vim from your Windows command prompt.&lt;/p&gt;



&lt;h2&gt;Collaboration&lt;/h2&gt;



&lt;p&gt;As mentioned before, Microsoft is publishing PowerShell code on Github for anyone to make a change.
If you don’t like how a DSC resource works, make a change and ask them to accept your changes.
Boom, you’ve contributed to the PowerShell ecosystem.&lt;/p&gt;



&lt;p&gt;More likely, your sharing code between co-workers while on the job.
Without source control you’re likely unable to tell who made what change and for what reason.
Source control also gives you auditing features that simple file management doesn’t give you.&lt;/p&gt;



&lt;h2&gt;Automatic Testing&lt;/h2&gt;



&lt;p&gt;Imagine the entire business running off of an automation you wrote.
You provision new customers from the ERP system quickly and it allows sales to increase their changes of landing big deals.
The whole company relies on your script to run constantly but now your boss tells you the company needs a new feature to your automation.
How do you know if any changes you make break the functionality of your script?&lt;/p&gt;



&lt;p&gt;The answer is, testing.
You can sit there and run your script through all different sorts of tests by hand, &lt;strong&gt;or&lt;/strong&gt; you can leverage source control and automatic testing to make sure you haven’t broken anything.
Windows 10 shipped with the &lt;a href=&quot;https://github.com/pester/Pester&quot;&gt;Pester&lt;/a&gt; testing framework and if you know how to write the tests correctly you can know with certainty that your code changes won’t break production.&lt;/p&gt;



&lt;p&gt;Once you have your changes tested make sure they run atomatically.
&lt;a href=&quot;https://jenkins-ci.org/&quot;&gt;Jenkins&lt;/a&gt;, &lt;a href=&quot;https://about.gitlab.com/gitlab-ci/&quot;&gt;GitLab CI&lt;/a&gt;, &lt;a href=&quot;https://www.appveyor.com/&quot;&gt;AppVeyor&lt;/a&gt;, and many others allow you to grab your code, run your tests, and let you know automatically if they cause errors or not.
Collaborating with someone? These systems can check &lt;strong&gt;their&lt;/strong&gt; code before you incorporate it into yours, that way you don’t bring in any breaking changes.&lt;/p&gt;



&lt;h2&gt;Time To Start&lt;/h2&gt;



&lt;p&gt;It is time to learn Git and source control in general.
Check out Mike F.
Robbins blog post &lt;a href=&quot;http://mikefrobbins.com/2016/01/21/getting-started-with-the-git-version-control-system/&quot;&gt;Getting Started with the Git Version Control System&lt;/a&gt;, Warren Frame’s post &lt;a href=&quot;http://ramblingcookiemonster.github.io/GitHub-For-PowerShell-Projects/&quot;&gt;GitHub For PowerShell Projects&lt;/a&gt;, as well as Warren’s &lt;a href=&quot;http://powershell.org/wp/techsession-webinars/&quot;&gt;TechSession Webinar&lt;/a&gt;  &lt;a href=&quot;http://powershell.org/wp/event/techsession-a-crash-course-in-version-control-and-git/&quot;&gt;A Crash Course in Version Control and Git&lt;/a&gt;.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Turn Off PSReadline</title><link>https://ngetchell.com/blog/turn-off-psreadline/</link><guid isPermaLink="true">https://ngetchell.com/blog/turn-off-psreadline/</guid><description>Beginning with Windows Management Framework 5 Microsoft decided to ship Pester and PSReadline baked into the framework. Pester is a testing framework and PSReadline is a handy utility that brings some bash functionality to the PowerShell console. PSReadline brings syntax highlighting and amazing multi-line editing to the console and I don’t know if I could […]</description><pubDate>Sun, 21 Feb 2016 00:28:10 GMT</pubDate><content:encoded>
&lt;p&gt;Beginning with Windows Management Framework 5 Microsoft decided to ship Pester and PSReadline baked into the framework.
&lt;a href=&quot;https://github.com/pester/Pester&quot;&gt;Pester&lt;/a&gt; is a testing framework and PSReadline is a handy utility that brings some bash functionality to the PowerShell console.&lt;/p&gt;



&lt;p&gt;PSReadline brings syntax highlighting and amazing multi-line editing to the console and I don’t know if I could go without.
Alas, not all modules are right for all people so we’re going to go and figure out how to remove PSReadline.&lt;/p&gt;



&lt;p&gt;First, we need to dive into how modules get loaded.
Normally, at the console, when you’d like to run a cmdlet from an unloaded module you simply run the command and powershell will dynamically load it &lt;em&gt;(Note: That is as of v3.
Version 1 and 2 required you to run Import-Module before running any cmdlets from the module)&lt;/em&gt;.&lt;/p&gt;



&lt;p&gt;You’ll notice however that PSReadline runs even before you run any cmdlets, let alone ones from the module.
To get around this you’ll have to edit your PowerShell profile.
The profile is a PS1 file that runs whenever you load the console or Integrated Scripting Environment.&lt;/p&gt;



&lt;p&gt;You simply need to edit the file found at ~\Documents\WindowsPowerShell\profile.ps1 and add the following.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Remove-Module&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name PSReadline&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;To handle this all from the console simply run:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Add-Content&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Value &lt;/span&gt;&lt;span&gt;&quot;`r`n Remove-Module PSReadline&quot;&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Path &lt;/span&gt;&lt;span&gt;$PROFILE&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Exit out of the console and reopen it.
You’ll see that PSReadline is no longer running in your session.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>PSPushover</title><link>https://ngetchell.com/blog/pspushover/</link><guid isPermaLink="true">https://ngetchell.com/blog/pspushover/</guid><description>I just recently published a module to the PowerShell Gallery called PSPushover and it couldn’t have been easier. Pushover.net is an alerting service I use to notify me of different events through IFTTT and I wanted a way to send off alerts from my PowerShell scripts. Some of my scripts are long running and I’d […]</description><pubDate>Fri, 19 Feb 2016 16:29:24 GMT</pubDate><content:encoded>
&lt;p&gt;I just recently published a module to the &lt;a href=&quot;https://www.powershellgallery.com/&quot;&gt;PowerShell Gallery&lt;/a&gt; called &lt;a href=&quot;https://www.powershellgallery.com/packages/PSPushover/&quot;&gt;PSPushover&lt;/a&gt; and it couldn’t have been easier.&lt;/p&gt;



&lt;p&gt;&lt;a href=&quot;https://pushover.net&quot;&gt;Pushover.net&lt;/a&gt; is an alerting service I use to notify me of different events through &lt;a href=&quot;https://ifttt.com&quot;&gt;IFTTT&lt;/a&gt; and I wanted a way to send off alerts from my PowerShell scripts.
Some of my scripts are long running and I’d like to know whether it finished in error or not.&lt;/p&gt;



&lt;p&gt;I plan on providing better help and better documentation in the README.md but otherwise I’m really proud of my work.&lt;/p&gt;



&lt;p&gt;To install simply run and you’ll have it installed.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Find-Module&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name PSPushover &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Install-Module&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Force&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Check out the &lt;a href=&quot;https://github.com/PSPushover/PSPushover&quot;&gt;PSPushover repository&lt;/a&gt; on GitHub.
Contributions are welcome.
time-script-with-timespan&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Pipelines and Objects</title><link>https://ngetchell.com/blog/pipelines-and-objects/</link><guid isPermaLink="true">https://ngetchell.com/blog/pipelines-and-objects/</guid><description>Two strong points of PowerShell are the ability to work with Pipelines and Objects. PowerShell is built on top of .NET and has the ability to work with .NET objects as well as sending and receiving information from the pipeline. Objects To developers, asking them to go from an object based language to one that […]</description><pubDate>Fri, 20 Nov 2015 08:00:26 GMT</pubDate><content:encoded>
&lt;p&gt;Two strong points of PowerShell are the ability to work with Pipelines and Objects.
PowerShell is built on top of .NET and has the ability to work with .NET objects as well as sending and receiving information from the pipeline.&lt;/p&gt;



&lt;h2&gt;Objects&lt;/h2&gt;



&lt;p&gt;To developers, asking them to go from an object based language to one that parses text for input/output would get you laughed at.
That is exactly why when Microsoft decided to write a new console and scripting language they decided to work with objects instead of text parsing.&lt;/p&gt;



&lt;p&gt;Those familiar with administrating Unix operating systems are aware of programs like grep, sed, and awk.
Those three programs allow the administrator to take text as input, manipulate the text, and output commands for the next program.&lt;/p&gt;



&lt;p&gt;Windows is an operating system built around Application Programming Interfaces (API) which allow sophisticated interactions with the underlying OS.
Those APIs return objects.
Objects contain attributes which house information about that specific object as well as methods, or little functions that can be performed on the object.
There are many other properties that apply to objects but those are the important ones.&lt;/p&gt;



&lt;p&gt;PowerShell, through &lt;a href=&quot;https://ngetchell.com/posts/intro-to-cmdlets/&quot;&gt;cmdlets&lt;/a&gt;, allow access to the Windows API, surfacing information about processes, services, files, and more.
These types of objects come with rich information and allow you to interact with them in a safe way.&lt;/p&gt;



&lt;p&gt;To find out what type of object you’re working with in PowerShell pipe any ‘Get’ command to the cmdlet Get-Member.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt; Get-Process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name &lt;/span&gt;&lt;span&gt;Powershell.exe&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Get-Member&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You’ll notice some interesting information on the console.
First, you see the type of object sent to Get-Member.
The process object is part of the System.Diagnostic object library is referred to by System.Diagnostic.Process.
The name is long to make sure that there aren’t type name collisions if there are two completely different types of process objects on a computer.&lt;/p&gt;



&lt;p&gt;Next you get the name of the property, property type in member type, and definition.
The property name is how you access the information inside of the object.
To list the Name,Threads,ID, and HandleCount you can use select-object.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name Powershell &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Select-Object&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Property Name&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;Threads&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;ID&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;HandleCount&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;Pipeline&lt;/h2&gt;



&lt;p&gt;The pipeline is really a important concept.
The idea is that you have small programs that do one thing for you.
Get-Process retrieves processes.
Set-ADUser will manipulate a user in Active Directory.
Cmdlets work best when strung together, one outputting objects, another taking objects as inputs.
Consider the following:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-ADUser&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Identity NGetchell &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Set-ADUser&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Title &lt;/span&gt;&lt;span&gt;&quot;Automation Wizard&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Get-ADUser goes out and finds my user account.
It then pushes the Microsoft.ActiveDirectory.Management.ADUser object into Set-ADUser.
Set-ADUser will now set the title of the incoming object to ‘Automation Wizard’.
In this scenario only one user object was manipulated.
Image your 1,000+ employee company has been purchased.
You’ve been tasked with changing the Company field in AD for each employee.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-ADUser&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;filter &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Set-ADUser&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Company &lt;/span&gt;&lt;span&gt;&apos;Getchell.org&apos;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You can now go home early since you completed hours of manual work in seconds.
You earned it.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Get Involved in PowerShell</title><link>https://ngetchell.com/blog/get-involved-powershell/</link><guid isPermaLink="true">https://ngetchell.com/blog/get-involved-powershell/</guid><description>I got a secret for you. The PowerShell community needs your voice. Your perspective on things. You might think that the community has enough talented people out there but you’d be wrong. It is time to get involved. The truth is, PowerShell has gotten big. Really big. It now covers the console shell, desired state […]</description><pubDate>Wed, 18 Nov 2015 08:00:04 GMT</pubDate><content:encoded>
&lt;p&gt;I got a secret for you.
The PowerShell community needs your voice.
Your perspective on things.
You might think that the community has enough talented people out there but you’d be wrong.
It is time to get involved.&lt;/p&gt;



&lt;p&gt;The truth is, PowerShell has gotten big.
Really big.
It now covers the console shell, desired state configuration, and nearly every Microsoft product.
Heck, with Nano server you’ll be expected to configure it using PowerShell remoting.
It doesn’t matter how talented the people in the community are, PowerShell just keeps growing and growing.&lt;/p&gt;



&lt;p&gt;Have I convinced you? If I have, you may wonder, how do I get involved in the PowerShell community?&lt;/p&gt;



&lt;ul&gt;

&lt;li&gt;Twitter – Twitter has become, for me, the best place for near real-time interaction with those in the community.
Follow some members of the PowerShell community (maybe &lt;a href=&quot;http://twitter.com/getch3028&quot;&gt;me&lt;/a&gt; for example?) and check to see who they follow and retweet.
Interact with them and you’ll see they will respond.&lt;/li&gt;


&lt;li&gt;Slack – Slack is a chat application used for team collaboration and the PowerShell community has a Slack team.
Head over to &lt;a href=&quot;http://slack.poshcode.org/&quot;&gt;http://slack.poshcode.org/&lt;/a&gt; to get an invite.
Be ready to help others with their questions when you feel you can answer them.
See how other people use PowerShell.&lt;/li&gt;


&lt;li&gt;PowerShell.org Blog and Forums – You have what it takes to answer questions on the PowerShell.org forums.
Help someone troubleshoot their environment.
You’ll find that you might have to do a little research to be able to answer questions.
That is good for you and the person you help.&lt;/li&gt;


&lt;li&gt;GitHub – You need a &lt;a href=&quot;http://github.com&quot;&gt;GitHub&lt;/a&gt; account.
Period.
Microsoft is releasing more and more code as open-source and nearly all community code is shared through it.
Star projects you like.
Watch projects you’d like to keep up on.
Submit a merge request when you find a bug.&lt;/li&gt;


&lt;li&gt;Blog – Blogging helps the community as the reach of PowerShell grows.
Help by filling in the spots where the documentation is lacking so people don’t have to go through the same pain you did.
Chronicle a new project you’re doing at work.
People are probably trying to accomplish a similar task where they work.&lt;/li&gt;


&lt;li&gt;Local User Groups – PowerShell.org has &lt;a href=&quot;http://powershell.org/wp/user-groups/&quot;&gt;User Groups&lt;/a&gt; that meet on a monthly basis and can get you networked with other PowerShell professionals.
PowerShell didn’t click with me until I saw how OTHER people were using it.
I got it then.
Make sure to present at the user group.
That will help you push your knowledge past what you think you know to what you really know.&lt;/li&gt;


&lt;li&gt;TechSession Webinars – Not near a User Group? Watch a &lt;a href=&quot;http://powershell.org/wp/techsession-webinars/&quot;&gt;TechSession&lt;/a&gt; webinar.
Ask questions during it.
Thank the presenter when it’s all over on Twitter.
Think you have what it takes to present? Email [TechSessions], I know a guy (me) who can schedule and promote the webinar.&lt;/li&gt;

&lt;/ul&gt;



&lt;p&gt;This wasn’t meant to be a comprehensive list but a good starting point.
If you have other ideas for getting involved in the PowerShell community leave a comment!&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Formatting Output</title><link>https://ngetchell.com/blog/formatting-output/</link><guid isPermaLink="true">https://ngetchell.com/blog/formatting-output/</guid><description>Formatting output from cmdlets doesn’t have to be complicated. PowerShell ships with cmdlets that can take the output from other cmdlets and display the information in a pretty way. Format-Custom, Format-List, Format-Table, and Format-Wide are the ways to present data at the console. Out-Default Out-Default is a cmdlet you likely have never heard of but […]</description><pubDate>Mon, 16 Nov 2015 08:00:23 GMT</pubDate><content:encoded>
&lt;p&gt;Formatting output from &lt;a href=&quot;https://ngetchell.com/posts/intro-to-cmdlets/&quot;&gt;cmdlets&lt;/a&gt; doesn’t have to be complicated.
PowerShell ships with cmdlets that can take the output from other cmdlets and display the information in a pretty way.
Format-Custom, Format-List, Format-Table, and Format-Wide are the ways to present data at the console.&lt;/p&gt;



&lt;h2&gt;Out-Default&lt;/h2&gt;



&lt;p&gt;Out-Default is a cmdlet you likely have never heard of but rely on whenever you spit an object to the console.
Out-Default is the cmdlet that figures out which way to format the information you have piped out.
Try this example to see what I mean.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name powershell &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Select-Object&lt;/span&gt;&lt;span&gt; Handles&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;ID&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;CPU&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The console should return a table with headers of Handles, Name, ID and CPU utilization and a row for each powershell.exe process you have open.
Seems simple right? Now add Working Set memory (WS) as one of the properties you want returned to the console and run the following:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name powershell &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Select-Object&lt;/span&gt;&lt;span&gt; Handles&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;Name&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;ID&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;CPU&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;WS&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Odd, we no longer get a table, we get a list.
It is almost as if we changed the pipeline from Format-Table to Format-List.
This is what Out-Default does in the background for you.
It knows that four headers in a table will display fine most of the time in the console window but five columns of information is pushing it.
With five columns Out-Default now formats the output using lists.
Out-Default, &lt;a href=&quot;http://blogs.msdn.com/b/powershell/archive/2006/04/30/586973.aspx&quot;&gt;while invisible&lt;/a&gt;, is formatting the console output for you.&lt;/p&gt;



&lt;h2&gt;Expressions&lt;/h2&gt;



&lt;p&gt;If you’d like to see the values displayed with different property names or as calculated fields you have use expressions to accomplish the task.&lt;/p&gt;



&lt;p&gt;In this example I want the process name to show as ProcessName and the working set memory to be named RAM and have it be expressed in Megabytes.
*Note: Carriage returns after the pipeline character will continue the pipeline onto the next line.
This is used to improve the readability of your code. *&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name powershell&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Format-List&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Property &lt;/span&gt;&lt;span&gt;@&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        Label&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&quot;ProcessName&quot;&lt;/span&gt;&lt;span&gt;;Expression&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;span&gt;$_.Name&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    @&lt;/span&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;        Label&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&quot;RAM&quot;&lt;/span&gt;&lt;span&gt;;Expression&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;{ &lt;/span&gt;&lt;span&gt;$_.WorkingSet&lt;/span&gt;&lt;span&gt; /&lt;/span&gt;&lt;span&gt; 1&lt;/span&gt;&lt;span&gt;MB&lt;/span&gt;&lt;span&gt; -as&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;int&lt;/span&gt;&lt;span&gt;] }&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;We used the Property argument in Format-List to return our custom output.
The syntax used is a hash table containing Label and Expression keys.
The value should be a string and an expression should be a script block.
This same syntax works for Select-Object as well.&lt;/p&gt;



&lt;h2&gt;Custom Format Files&lt;/h2&gt;



&lt;p&gt;You may wonder how Out-Default is smart enough to chose which properties to show and which to hide.
The answer is, it isn’t smart enough.
The developer of the cmdlet chooses what to show and what not to. 
If we poke around in the module manifest of the Microsoft.PowerShell.Diagnostics module at “C:\windows\System32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Diagnostics\Microsoft.PowerShell.Diagnostics.psd1” you can see the FormatsToProcess field and two format.ps1xml files. 
Those two files dictate how the object information is shown.&lt;/p&gt;



&lt;h2&gt;Gotchas&lt;/h2&gt;



&lt;p&gt;Something to keep in mind.
The Format cmdlets change the object type in the pipeline.
That means if you were piping process objects into Format-List you no longer get process objects out.
If we pipe the output of one of the format cmdlets into Get-Member we find that we get objects of type Microsoft.PowerShell.Commands.Internal.Format.FormatEndData.
Hardly anything we can work with.&lt;/p&gt;



&lt;p&gt;As a rule of thumb, the Format cmdlets should be the last thing on the pipeline, unless you are using an Out cmdlet after.
Out-Printer will print your formatted objects without issue.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Introduction to Cmdlets</title><link>https://ngetchell.com/blog/intro-to-cmdlets/</link><guid isPermaLink="true">https://ngetchell.com/blog/intro-to-cmdlets/</guid><description>For years Microsoft has played a trick on systems administrators. They convinced you that you could administer Windows Servers at the same scale that Linux administrators could. While that sentiment is true the tooling wasn’t always geared towards system administrators. You had MS-DOS and batch files that you could use to automate anything you could […]</description><pubDate>Thu, 03 Sep 2015 08:00:27 GMT</pubDate><content:encoded>
&lt;p&gt;For years Microsoft has played a trick on systems administrators.
They convinced you that you could administer Windows Servers at the same scale that Linux administrators could.
While that sentiment is true the tooling wasn’t always geared towards system administrators.
You had MS-DOS and batch files that you could use to automate anything you could do at the command line as well as VB scripts for more programmatic automation.
The trouble is, batch lacks an interface into most of the underlying OS and VB is a full-blown programming language.
When Microsoft released PowerShell in 2006 they aimed to cater to those who wanted more from batch and less “dev stuff” than VB.&lt;/p&gt;



&lt;p&gt;&lt;a href=&quot;https://twitter.com/jsnover&quot;&gt;Jeffrey Snover&lt;/a&gt; envisioned the console and scripting language built on top of Microsoft’s .Net Framework and could extend the .Net Framework.
Objects created in PowerShell were .Net objects. But PowerShell is more than just a console application.
Microsoft has opened up the underlying OS to PowerShell in a way it never has before for the operations team.&lt;/p&gt;



&lt;p&gt;PowerShell Cmdlets (short for CommandLet) center around the Unix Philosophy of &lt;a href=&quot;https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well&quot;&gt;Do One Thing and Do it Well&lt;/a&gt;.
The &lt;em&gt;Start-Process&lt;/em&gt; cmdlet only starts a process.
&lt;em&gt;Stop-Process&lt;/em&gt; only stops them.
There isn’t some overarching process command that does both.
PowerShell abstracts the .Net, WMI, and C++ away so you don’t have to care how the process is created.
A PowerShell cmdlet does one thing, and one thing VERY well.&lt;/p&gt;



&lt;h2&gt;Naming Conventions&lt;/h2&gt;



&lt;p&gt;Cmdlets come in many types.
They deal with different object types like stored credentials, ip addresses, strings, numbers, and many more but the conventions stay the same.
Cmdlets follow the &lt;strong&gt;Verb-Noun&lt;/strong&gt; naming convention.
The nouns are singular even though they can output more than one object.
The Cmdlet names also follow the &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/x2dbyw72%28v=vs.71%29.aspx&quot;&gt;Pascal&lt;/a&gt; capitalization style where every word is capitalized.&lt;/p&gt;



&lt;p&gt;These naming conventions make it easy to find new commands.
Looking for everything dealing with services?&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Noun Service&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You now get back a whole list of cmdlets that work with services.
The same works for searching for verbs.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Verb write&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You can now see all cmdlets that can write.
Both can be used with wildcards.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Verb write &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Noun out&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;Approved Verbs&lt;/h2&gt;



&lt;p&gt;When writing functions you are required to come up with a new for the function.
It comes from the function declaration.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Function&lt;/span&gt;&lt;span&gt; New-Cmdlet&lt;/span&gt;&lt;span&gt; { &lt;/span&gt;&lt;span&gt;param&lt;/span&gt;&lt;span&gt;( $Verb&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; $Noun ) &lt;/span&gt;&lt;span&gt;Write-Output&lt;/span&gt;&lt;span&gt; ‘$Verb-$Noun’&lt;/span&gt;&lt;span&gt; } &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;New-Cmdlet&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Noun Cmdlet &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;Verb New&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;New is a verb approved by Microsoft to run in PowerShell.
Here is how you get a list of approved verbs.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Verb&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; Out-gridView&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;We pipe the list to out-gridview so we can sort by name or by group.
Stick with these verbs when writing functions.
It will make discoverability of your functions easier for people who work with your functions and will work perfectly when you bundle up functions into a module.&lt;/p&gt;



&lt;h2&gt;Googleability&lt;/h2&gt;



&lt;p&gt;Googleability is a made up word.
Made up, yet we you know exactly what I mean.
How easy is something to google. When I search for &lt;a href=&quot;http://www.microsoftvirtualacademy.com/&quot;&gt;Microsoft Virtual Academy&lt;/a&gt; on Google using the search term ‘MVA’ I get a bunch of sites I’m not looking for.
I want something specific and am forced to search by the full name of the site.
The results I want are hidden in noise.&lt;/p&gt;



&lt;p&gt;The word cmdlet doesn’t mean anything besides PowerShell CommandLet.
This makes searching for online documentation of cmdlets simple.
Simply search on “cmdlet Write-Information” to get exact hits on what you’re looking for.
I’m not sure if this was by design but it certainly makes finding help easy online.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Introduction: PowerShell Direct</title><link>https://ngetchell.com/blog/introduction-powershell-direct/</link><guid isPermaLink="true">https://ngetchell.com/blog/introduction-powershell-direct/</guid><description>PowerShell Direct is a new feature to Windows Management Framework version 5 that allows for Windows hosts to run PowerShell commands against a Hyper-V guest. Think of this as PowerShell Remoting without the need to enable remoting on the guest operating system. Your guest doesn’t have to configure the firewall to allow for remoting. You […]</description><pubDate>Fri, 12 Jun 2015 08:00:02 GMT</pubDate><content:encoded>
&lt;p&gt;&lt;a href=&quot;http://blogs.technet.com/b/virtualization/archive/2015/05/14/powershell-direct-running-powershell-inside-a-virtual-machine-from-the-hyper-v-host.aspx&quot;&gt;PowerShell Direct&lt;/a&gt; is a new feature to Windows Management Framework version 5 that allows for Windows hosts to run PowerShell commands against a Hyper-V guest.
Think of this as PowerShell Remoting without the need to enable remoting on the guest operating system.
Your guest doesn’t have to configure the firewall to allow for remoting.
You don’t even need a network card.&lt;/p&gt;



&lt;p&gt;Instead of the Hyper-V rolling out their own PowerShell Direct remoting tool Microsoft opted to integrate PowerShell Direct into the PSSession cmdlets.
Notice when you run Get-Command against Enter-PSSession you get eight different parameter sets.&lt;/p&gt;



&lt;p&gt;&lt;em&gt;Note: This only works on Windows 10/Server vNext hosts to Windows 10/Server vNext guests.&lt;/em&gt;&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;PS:&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; Get-Command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name &lt;/span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Syntax&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-ComputerName&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;string&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-EnableNetworkAccess&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-Credential&lt;/span&gt;&lt;span&gt; &amp;lt;pscredential&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-ConfigurationName&lt;/span&gt;&lt;span&gt; &amp;lt;string&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-Port&lt;/span&gt;&lt;span&gt; &amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-UseSSL&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-ApplicationName&lt;/span&gt;&lt;span&gt; &amp;lt;string&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-SessionOption&lt;/span&gt;&lt;span&gt; &amp;lt;PSSessionOption&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-Authentication&lt;/span&gt;&lt;span&gt; &amp;lt;AuthenticationMechanism&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-CertificateThumbprint&lt;/span&gt;&lt;span&gt; &amp;lt;string&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;&amp;lt;CommonParameters&amp;gt;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt; [[&lt;/span&gt;&lt;span&gt;-Session&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;&amp;lt;PSSession&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;&amp;lt;CommonParameters&amp;gt;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt; [[&lt;/span&gt;&lt;span&gt;-ConnectionUri&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;&amp;lt;uri&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-EnableNetworkAccess&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-Credential&lt;/span&gt;&lt;span&gt; &amp;lt;pscredential&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-ConfigurationName&lt;/span&gt;&lt;span&gt; &amp;lt;string&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-AllowRedirection&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-SessionOption&lt;/span&gt;&lt;span&gt; &amp;lt;PSSessionOption&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-Authentication&lt;/span&gt;&lt;span&gt; &amp;lt;AuthenticationMechanism&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-CertificateThumbprint&lt;/span&gt;&lt;span&gt; &amp;lt;string&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;&amp;lt;CommonParameters&amp;gt;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-InstanceId&lt;/span&gt;&lt;span&gt; &amp;lt;guid&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;&amp;lt;CommonParameters&amp;gt;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt; [[&lt;/span&gt;&lt;span&gt;-Id&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;&amp;lt;CommonParameters&amp;gt;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-Name&lt;/span&gt;&lt;span&gt; &amp;lt;string&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;&amp;lt;CommonParameters&amp;gt;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-VMId&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;guid&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-Credential&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;pscredential&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-ConfigurationName&lt;/span&gt;&lt;span&gt; &amp;lt;string&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;&amp;lt;CommonParameters&amp;gt;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-VMName&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;string&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-Credential&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;pscredential&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-ConfigurationName&lt;/span&gt;&lt;span&gt; &amp;lt;string&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;&amp;lt;CommonParameters&amp;gt;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-ContainerId&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;string&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; [&lt;/span&gt;&lt;span&gt;-ConfigurationName&lt;/span&gt;&lt;span&gt; &amp;lt;string&amp;gt;&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;-RunAsAdministrator&lt;/span&gt;&lt;span&gt;] [&lt;/span&gt;&lt;span&gt;&amp;lt;CommonParameters&amp;gt;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The last two Enter-PSSession -VMGuid and Enter-PSSession -VMName are new in Windows 10.
They allow you to enter a remote session from a Hyper-V host.
When running against a Hyper-V guest you need to provide &lt;a href=&quot;https://ngetchell.com/posts/credentials/&quot;&gt;PSCredentials&lt;/a&gt; in order to authenticate.&lt;/p&gt;



&lt;p&gt;As of the Windows 10 Build 10130 there are only three commands that have a -VMName or -VMGuid parameter name.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;PS:&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; Get-Command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ParameterName VMGUID&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;VMName&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;CommandType     Name                                               Version    Source&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-----------&lt;/span&gt;&lt;span&gt;     ----&lt;/span&gt;&lt;span&gt;                                               -------&lt;/span&gt;&lt;span&gt;    ------&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Cmdlet          &lt;/span&gt;&lt;span&gt;Enter-PSSession&lt;/span&gt;&lt;span&gt;                                    3.0&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;0.0&lt;/span&gt;&lt;span&gt;    Microsoft.PowerShell.Core&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Cmdlet          &lt;/span&gt;&lt;span&gt;Get-PSSession&lt;/span&gt;&lt;span&gt;                                      3.0&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;0.0&lt;/span&gt;&lt;span&gt;    Microsoft.PowerShell.Core&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Cmdlet          &lt;/span&gt;&lt;span&gt;Invoke-Command&lt;/span&gt;&lt;span&gt;                                     3.0&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;0.0&lt;/span&gt;&lt;span&gt;    Microsoft.PowerShell.Core&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Cmdlet          &lt;/span&gt;&lt;span&gt;New-PSSession&lt;/span&gt;&lt;span&gt;                                      3.0&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;0.0&lt;/span&gt;&lt;span&gt;    Microsoft.PowerShell.Core&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Cmdlet          &lt;/span&gt;&lt;span&gt;Remove-PSSession&lt;/span&gt;&lt;span&gt;                                   3.0&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;0.0&lt;/span&gt;&lt;span&gt;    Microsoft.PowerShell.Core&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;To run Get-Process against a VM.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$Credential &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Credential&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Invoke-Command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;VMName &lt;/span&gt;&lt;span&gt;&quot;Windows 10&quot;&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Credential $Credential &lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span&gt;ScriptBlock { &lt;/span&gt;&lt;span&gt;Get-Process&lt;/span&gt;&lt;span&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The possibilities are endless when you can run jobs, invoke commands, and work interactively with a guest virtual machine.
It is plain to see why a technology like this is important.
Begin able to manage your virtual machines through a dedicated and secure management interface.
Look for more announcements from the &lt;a href=&quot;http://blogs.technet.com/b/virtualization/&quot;&gt;Hyper-V blog&lt;/a&gt;.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>Credentials</title><link>https://ngetchell.com/blog/credentials/</link><guid isPermaLink="true">https://ngetchell.com/blog/credentials/</guid><description>Have you ever tried running a script only to find that your user account doesn’t have the proper rights? You could start up another PowerShell session using the ‘Run as Different User’ option but wouldn’t you rather a PowerShell way? There is. PowerShell offers the PSCredential object type that allows you to store and retrieve […]</description><pubDate>Thu, 11 Jun 2015 08:00:09 GMT</pubDate><content:encoded>
&lt;p&gt;Have you ever tried running a script only to find that your user account doesn’t have the proper rights?
You could start up another PowerShell session using the ‘Run as Different User’ option but wouldn’t you rather a PowerShell way?
There is.
PowerShell offers the PSCredential object type that allows you to store and retrieve credentials.
This comes built into the Microsoft.PowerShell.Security module.&lt;/p&gt;



&lt;p&gt;Running Get-Credential prompts the user for a username and password.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt; Get-Credential&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Message &lt;/span&gt;&lt;span&gt;&quot;Creds Please&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;To fill the username prompt in simply use the -Username argument.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Credential&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Username LebowskiTheDude&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;PSCredential objects can be stored in variables just like any other object in PowerShell.
Here the prompt comes up and when you click ‘OK’ the output of Get-Credential is stored in the $Credentials variable.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$Credentials &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Get-Credential&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;PSCredentials can also be stored to disk with high fidelity.
Saving a PSCredential object in a Command Line XML file allows for the importing at a later time.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Credential&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Username LebowskiTheDude &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    Export-clixml&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;path c:\credentials.xml &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$Credentials &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; Import-clixml&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;path c:\credentials.xml&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You’ll notice when you open up the resulting .xml file you can see the username but the password is encrypted.
Only you can import the file.
When another use tries to import it they get the following.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;PS:\&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; Import-Clixml&lt;/span&gt;&lt;span&gt; C:\credentials.xml &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Import-Clixml&lt;/span&gt;&lt;span&gt; : Key not valid &lt;/span&gt;&lt;span&gt;for&lt;/span&gt;&lt;span&gt; use &lt;/span&gt;&lt;span&gt;in&lt;/span&gt;&lt;span&gt; specified state. At line:&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt; char:&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt; +&lt;/span&gt;&lt;span&gt; Import-Clixml&lt;/span&gt;&lt;span&gt; C:\credentials.xml &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; CategoryInfo : NotSpecified: (:) [&lt;/span&gt;&lt;span&gt;Import-Clixml&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; CryptographicException &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; FullyQualifiedErrorId : System.Security.Cryptography.CryptographicException&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;Microsoft.PowerShell.Commands.Import ClixmlCommand&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Get-Credential and the PSCredential object are extremely useful.
To find out all of the commands that except the PSCredential object you can check with Get-Command.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;get-command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;ParameterType PSCredential&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content:encoded><category>PowerShell</category></item><item><title>Beyond Syntax: Pester Testing</title><link>https://ngetchell.com/blog/beyond-syntax-pester-testing/</link><guid isPermaLink="true">https://ngetchell.com/blog/beyond-syntax-pester-testing/</guid><description>A TechSession episode where we discussing going beyond the easy stuff in pester.</description><pubDate>Tue, 09 Jun 2015 18:00:08 GMT</pubDate><content:encoded>




&lt;p&gt;Sorry that I missed the first minute.
I forgot to his the record button.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item><item><title>PowerShellGet Introduction</title><link>https://ngetchell.com/blog/powershellget-introduction/</link><guid isPermaLink="true">https://ngetchell.com/blog/powershellget-introduction/</guid><description>With PowerShell version 5 Microsoft released a way of installing modules using PowerShell. Before v5 you would have to copy modules into specific folders where the module folder name has to be exactly has the module .psd1 file. Getting it right for someone who wasn’t writing modules was hard. I know at work I would […]</description><pubDate>Tue, 26 May 2015 08:00:18 GMT</pubDate><content:encoded>
&lt;p&gt;With PowerShell version 5 Microsoft released a way of installing modules using PowerShell.
Before v5 you would have to copy modules into specific folders where the module folder name has to be exactly has the module .psd1 file.
Getting it right for someone who wasn’t writing modules was hard.
I know at work I would simply copy the files for them into C:WindowsSystem32WindowsPowerShellv1.0Modules so the modules could be loaded in the user’s session.&lt;/p&gt;



&lt;p&gt;Those days are thankfully gone.
PowerShellGet works off of the NuGet package management framework devised for Visual Studio and allows anyone to install Modules with ease.
Shipping currently in the latest v5 version users can install modules with the following command:&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Find-Module&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Name Powershellcookbook &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Install-Module&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Verbose&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;You’ll notice that by default PowerShell does not trust the repository in which you are downloading from.
PowerShell ships with a module gallery populated with modules from the community.
These are not modules vetted by Microsoft but some modules do come from Microsoft employees.
The PowerShellCookbook module happens to be written by &lt;a href=&quot;http://www.leeholmes.com/blog/&quot;&gt;Lee Holmes&lt;/a&gt;, a Microsoft employee who works on Windows Server.
Other modules are written by Microsoft MVPs and other respectable leaders in the community.
There is a chance that the content you download could be malicious.
Always inspect any module you download from any unverified source.&lt;/p&gt;



&lt;p&gt;In order to checkout repository information run Get-PSRepository.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-PSRepository&lt;/span&gt;&lt;span&gt; |&lt;/span&gt;&lt;span&gt; format-list&lt;/span&gt;&lt;span&gt; *&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Notice how the InstallationPolicy property is set to untrusted.
You should keep it untrusted since you don’t know who is actually posting the module.
In the future you may stand up your own NuGet repository where you vet all published content.
Then, you can set your repository to trusted to bypass any confirmations.&lt;/p&gt;



&lt;p&gt;Running Install-Module again and excepting the confirmation means that you now have the module installed.
Running Get-InstalledModule reveals a list of Modules you’ve installed from Install-Module.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-InstalledModule&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Version Name Repository Description &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;-------&lt;/span&gt;&lt;span&gt; ----&lt;/span&gt;&lt;span&gt; ----------&lt;/span&gt;&lt;span&gt; -----------&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;1.3&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt; PowerShellCookbook PSGallery Sample scripts &lt;/span&gt;&lt;span&gt;from&lt;/span&gt;&lt;span&gt; the Windows PowerShell Cookbook&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;To confirm we actually have PowerShellCookbook installed we run on of the cmdlets named Show-Object.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Get-Process&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;name Powershell &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;span&gt; Show-Object&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Show-Object is useful for exploring new object types.
You can drill into the objects and their properties in a visual way to see exactly what is in them.&lt;/p&gt;



&lt;p&gt;When new versions of modules come out you simply have to run Update-Module to get the latest version.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;Update-Module&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Be sure to check out the other commands inside of PowerShellGet.&lt;/p&gt;



&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;get-command&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span&gt;Module powershellget&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content:encoded><category>PowerShell</category></item><item><title>Why Write About PowerShell</title><link>https://ngetchell.com/blog/why-write-about-powershell/</link><guid isPermaLink="true">https://ngetchell.com/blog/why-write-about-powershell/</guid><description>In one word: Community. I’m one of those IT Pros who entered IT without formal training. I have no degrees in any of the IT related disciplines, I am almost completely self taught. I excelled in the field due to my ability to find solutions to problems online and in my confidence that if I […]</description><pubDate>Fri, 24 Apr 2015 17:00:41 GMT</pubDate><content:encoded>
&lt;p&gt;In one word: Community.
I’m one of those IT Pros who entered IT without formal training.
I have no degrees in any of the IT related disciplines, I am almost completely self taught.
I excelled in the field due to my ability to find solutions to problems online and in my confidence that if I broke something I could likely fix it.&lt;/p&gt;



&lt;p&gt;Creating documentation has never been a strong skill for me.
I have a habit of finding solutions online to problems, trying the suggestion then moving on to the next solution.
Rarely do I report whether the proposed solution worked or not.&lt;/p&gt;



&lt;p&gt;That ends with this blog.&lt;/p&gt;



&lt;p&gt;I recently attended the PowerShell Summit 2015 in Charlotte, NC and was overwhelmed by the feeling that we attendees were all in this together.&lt;/p&gt;



&lt;p&gt;Don Jones, Summit organizer and PowerShell MVP, made a speech that really hit home.
In a speech that should launch 140 blogs Don called on us to step up and contribute.
It isn’t enough to merely attend the Summit or buy PowerShell books written by community leaders.&lt;/p&gt;



&lt;p&gt;It is time to step up.&lt;/p&gt;
</content:encoded><category>PowerShell</category></item></channel></rss>