mmwps.wordpress.com Open in urlscan Pro
192.0.78.12  Public Scan

Submitted URL: https://psmagic.net/
Effective URL: https://mmwps.wordpress.com/
Submission: On April 24 via api from US — Scanned from NL

Form analysis 2 forms found in the DOM

POST https://subscribe.wordpress.com

<form method="post" action="https://subscribe.wordpress.com" accept-charset="utf-8" style="display: none;">
  <div>
    <input type="email" name="email" placeholder="Enter your email address" class="actnbr-email-field" aria-label="Enter your email address">
  </div>
  <input type="hidden" name="action" value="subscribe">
  <input type="hidden" name="blog_id" value="69542994">
  <input type="hidden" name="source" value="https://mmwps.wordpress.com/">
  <input type="hidden" name="sub-type" value="actionbar-follow">
  <input type="hidden" id="_wpnonce" name="_wpnonce" value="789ddf2c2b">
  <div class="actnbr-button-wrap">
    <button type="submit" value="Sign me up"> Sign me up </button>
  </div>
</form>

<form id="jp-carousel-comment-form">
  <label for="jp-carousel-comment-form-comment-field" class="screen-reader-text">Write a Comment...</label>
  <textarea name="comment" class="jp-carousel-comment-form-field jp-carousel-comment-form-textarea" id="jp-carousel-comment-form-comment-field" placeholder="Write a Comment..."></textarea>
  <div id="jp-carousel-comment-form-submit-and-info-wrapper">
    <div id="jp-carousel-comment-form-commenting-as">
      <fieldset>
        <label for="jp-carousel-comment-form-email-field">Email (Required)</label>
        <input type="text" name="email" class="jp-carousel-comment-form-field jp-carousel-comment-form-text-field" id="jp-carousel-comment-form-email-field">
      </fieldset>
      <fieldset>
        <label for="jp-carousel-comment-form-author-field">Name (Required)</label>
        <input type="text" name="author" class="jp-carousel-comment-form-field jp-carousel-comment-form-text-field" id="jp-carousel-comment-form-author-field">
      </fieldset>
      <fieldset>
        <label for="jp-carousel-comment-form-url-field">Website</label>
        <input type="text" name="url" class="jp-carousel-comment-form-field jp-carousel-comment-form-text-field" id="jp-carousel-comment-form-url-field">
      </fieldset>
    </div>
    <input type="submit" name="submit" class="jp-carousel-comment-form-button" id="jp-carousel-comment-form-button-submit" value="Post Comment">
  </div>
</form>

Text Content

MAKING MAGIC WITH POWERSHELL


USING POWERSHELL TO AUTOMATE, ERADICATE, AND SIMPLIFY TASKS

Menu Skip to content
 * Home
 * Getting Started
   * Cheat Sheet
 * Episodes
 * About


AUDIT ALL THE AZURE KEYVAULTS!

Leave a reply


THE PROBLEM

We have a multi-region service that uses geo-located Azure KeyVaults to manage
secrets. We had not been auditing changes and access to these vaults. Oops.
Enabling auditing for the first time requires:

 * Creating storage co-located for every location we wish to audit (note, this
   is not per KeyVault)
 * Adding Diagnostics Settings for each of the KeyVaults to enable the auditing
   with the correct, geo-located storage account as a backing store

Since there were 15 active regions, it seemed like some magic was in order.

What follows is an abbreviated exploration of how I tackled this problem. Rest
assured, there were many false steps and red text getting from A to B to C; and
while I have elided those false starts, I still thought there was some value in
the step-by-step approach taken, versus a neatly-packaged
“magic-trick-in-a-box”.
Continue reading →


This entry was posted in Episodes and tagged Add-AzureAccount, Azure,
Export-Csv, Get-AzureRmStorageAccount, Import-Csv, KeyVault,
Login-AzureRmAccount, New-AzureRmStorageAccount, Select-AzureSubscription,
Select-Object, Set-AzureRmContext, Set-AzureRmDiagnosticSetting on February 15,
2017 by mmwps.


WHOIS

Leave a reply


THE PROBLEM

UNIX has many great tools, among them ‘whois’, but in the windows domain world
there really isn’t a readily available analog. I’ve looked!
In looking, I found this; which is close, but had a number of rough edges to my
eye. After a few tweaks, I thought perhaps others would appreciate the end
result:
Continue reading →


This entry was posted in Episodes and tagged AAD, Add-Member, New-Object,
ParameterSet, pscustomobject on February 1, 2017 by mmwps.


MONITOR PROCESS STARTS

Leave a reply

Well, I’ve been heads down for 2 years (2 years?!).  This post was drafted all
those 2 years ago, and I find that I needed to remind myself how to monitor
process starts for use in a new project.  Since I was digging around in this
post anyway, I figured I could at least make sure it saw the light of day.

Enjoy!

Continue reading →

This entry was posted in Episodes and tagged Format-Table, Get-Event,
Get-EventSubscriber, Get-WmiObject, Register-WmiEvent, Unregister-Event, wmi on
January 19, 2017 by mmwps.


WHY THE PIPELINE IS (ALMOST) ALWAYS YOUR FRIEND

Leave a reply


THE PROBLEM


WHEN SHOULD I USE THE PIPELINE?

(Almost) Always.


WHAT IF I WANT TO CREATE AN ARRAY OF VALUES? SHOULD I USE AN ARRAY, AN
ARRAYLIST, OR A LIST?

None of the above, the pipeline is just as fast, and cleaner (really).


OK SERIOUSLY, WHEN SHOULDN’T I USE THE PIPELINE?

When a command already gives you a way to parallelize.
Continue reading →

This entry was posted in Episodes and tagged arrays, ForEach-Object, hashes,
lists, Measure-Command, pipelining, Sort-Object on April 15, 2015 by mmwps.


PSREADLINE & PSGET

Leave a reply

This entry is a guide to a few PS Modules / Tools I use on a regular basis. It’s
filler, sure, but tasty filler!

PsGet, PSReadline, and Posh-Git

Continue reading →

This entry was posted in Uncategorized and tagged FYI on September 25, 2014 by
mmwps.


TEXT ENCODING WHEN WRITING TO FILES

Leave a reply


THE PROBLEM

Sometimes, PowerShell is both the problem AND the solution. This is one of those
times. Files default to Unicode encoding in PowerShell, which is awesome, but
when you aren’t expecting it can cause problems!


THE MAGIC

Out-File. That’s it.

1
PS> Get-Content “unicode_file_path” | Out-File –Encoding “ASCII”


THE BREAKDOWN

Out-File has many parameters. The interesting one is “Encoding” and help can
give us some insight into the ways we can use that parameter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
PS> Get-Help Out-File –Parameter Encoding
 
-Encoding <String>
    Specifies the type of character encoding used in the file. Valid values are
    "Unicode", "UTF7", "UTF8", "UTF32", "ASCII", "BigEndianUnicode", "Default",
    and "OEM". "Unicode" is the default.
 
    "Default" uses the encoding of the system's current ANSI code page.
 
    "OEM" uses the current original equipment manufacturer code page identifier
for
    the operating system.
 
    Required?                    false
    Position?                    2
    Default value                Unicode
    Accept pipeline input?       false
    Accept wildcard characters?  false

This entry was posted in Episodes and tagged Out-File on September 17, 2014 by
mmwps.


PS PROVIDERS

Leave a reply


THE PROBLEM

Recently a co-worker indicated that they were doing stuff in the registry, but
found going through .NET methods in PowerShell a little clunky.

A while back, when I was still working in Security, I needed a way to get a list
of applications that were allowed to launch with higher (medium) privilege from
low-rights IE.

Wouldn’t it be neat if there were a native way to grovel through the registry? A
quick way to get the full list of MIL-legal programs IE can launch? Turns out
‘gci’ can do more than just navigate your file system…
Continue reading →

This entry was posted in Episodes and tagged Get-ChildItem, Get-Item,
Get-Location, New-Item, Pop-Location, PSProviders, Push-Location, Remove-Item on
September 3, 2014 by mmwps.


SET THEORY, REDUX

2 Replies


THE PROBLEM

We covered the awesomeness of HashSets a few episodes back. However, there was
one really annoying aspect which can be summed up as follows:

1
2
PS> $hs = New-Object 'System.Collections.Generic.HashSet[string]' # comment
PS> <do something> |% { [void] $hs.Add($_.SomeValue) }

You had to use the above boilerplate… a lot. I don’t know about you, but I get
bored easily, and typing “System.Collections.Generic.HashS…” see? I’m bored
already. Let’s fix this.
Continue reading →

This entry was posted in Episodes and tagged New-HashSet, New-Object on August
20, 2014 by mmwps.


XML & DATA AGGREGATION

Leave a reply


THE PROBLEM

Let’s say we have an XML settings file whose format is very loose, and
components which consume it are free to define new properties, defined by key
(guid) name (string) pairs. Obviously, keeping a central repository can be
difficult. Further, due to legacy reasons, the only “identifying” piece of
information for a property is its guid, which must be lower cased. The name is
just there as window dressing.

Now, let’s say We have a sizeable body of settings files and need to accomplish
a couple of goals:
1. Get a list of all properties currently in use.
2. Ensure that all properties did what they claim to do (names and guids always
match each other)
Continue reading →

This entry was posted in Episodes and tagged Export-Csv, Get-ChildItem,
Get-Content, Group-Object, Import-Csv, Select-Object, Sort-Object, xml on August
11, 2014 by mmwps.


GETTING COMMANDLINES FOR ACTIVE PROCESSES

1 Reply


THE PROBLEM

A friend was pining for a way to get the command-line of active processes from
the… command-line. It took a couple iterations to get an answer, and I think it
is worth walking through the iterations here:

 1. Get-Process | fl * # Force display of all properties… hmmm, “StartInfo”?
 2. (Get-Process)[0].StartInfo # Start info has the ‘Arguments’ right? Nope, not
    populated…
 3. gwmi -list | ogv # Poke around via filter… “P-R-O-C-E” oooo, Win32_Process?
 4. gwmi Win32_Process # Lots of good info… what’s this ‘Properties’ thing?
 5. (gwmi Win32_Process).Properties | ft Name,Value # hmmm, ‘CommandLine’ you
    say?

Now I knew how to get the command-line, now to make a quick script so I don’t
have to remember the exact arcana each time:
Continue reading →

This entry was posted in Episodes and tagged Format-Table, Get-Process,
Get-WmiObject, Out-GridView, Select-Object, wmi on August 6, 2014 by mmwps.


POST NAVIGATION

← Older posts

Blog at WordPress.com.

Making Magic with PowerShell
Create a free website or blog at WordPress.com.
 * Subscribe Subscribed
    * Making Magic with PowerShell
      
      Sign me up
    * Already have a WordPress.com account? Log in now.

 * Privacy
 *  * Making Magic with PowerShell
    * Customize
    * Subscribe Subscribed
    * Sign up
    * Log in
    * Report this content
    * View site in Reader
    * Manage subscriptions
    * Collapse this bar

 

Loading Comments...

 

Write a Comment...
Email (Required) Name (Required) Website