Parse env:Path with PowerShell | Quisitive

The environment variable PATH (combined SYSTEM PATH and USER PATH) can be tricky to parse if you want to check for each folder it contains.  This is due to the support of various formatting styles.  For example, this is a valid PATH statement:

C:WINDOWS;”C:Path with semicolon; in the middle”;”E:Path with semicolon at the end;”;;C:Program Files;

Notice the differences

A few references can be found…

But I could find no fully working method to parse this complexity, so I wrote a PowerShell Function to handle it.

Function Get-ENVPathFolders { #.Synopsis Split $env:Path into an array #.Notes # - Handle 1) folders ending in a backslash 2) double-quoted folders 3) folders with semicolons 4) folders with spaces 5) double-semicolons I.e. blanks # - Example path: 'C:WINDOWS;"C:Path with semicolon; in the middle";"E:Path with semicolon at the end;";;C:Program Files;' # - 2018/01/30 by [email protected] - Created $PathArray = @() $env:Path.ToString().TrimEnd(';') -split '(?=["])' | ForEach-Object { #remove a trailing semicolon from the path then split it into an array using a double-quote as the delimiter keeping the delimiter If ($_ -eq '";') { # throw away a blank line } ElseIf ($_.ToString().StartsWith('";')) { # if line starts with "; remove the "; and any trailing backslash $PathArray += ($_.ToString().TrimStart('";')).TrimEnd('') } ElseIf ($_.ToString().StartsWith('"')) { # if line starts with " remove the " and any trailing backslash $PathArray += ($_.ToString().TrimStart('"')).TrimEnd('') #$_ + '"' } Else { # split by semicolon and remove any trailing backslash $_.ToString().Split(';') | ForEach-Object { If ($_.Length -gt 0) { $PathArray += $_.TrimEnd('') } } } } Return $PathArray }

To prove it out:

#output the array of PATH folders Get-ENVPathFolders #create a test file in half of the folders $i=0 Get-ENVPathFolders | ForEach-Object { $i++ If ($i%2 -eq 0) { New-Item -Path "$_" -Name $myFile -ItemType File } } #output the PATH folders with the test file Get-ENVPathFolders | ForEach-Object { If (Test-Path -Path $_$myFile) { Write-Output "Found [$_$myFile]" } }

Happy coding!

The Azure portal provides an easy to use dashboard experience which allows you to easily pin items from Azure and other sources into your own custom dashboards. This blog post will showcase the following:

Creating your own dashboard:

To create your own dashboard, log into the Azure portal and choose the option to create new dashboard.

Provide a name for the dashboard and then you can temporarily call this done by choosing the “Done customizing” option.

The Tile Gallery on the right provides a large number of items which can be easily added to your dashboard so if you haven’t already finished customizing your dashboard you can try some of these out before you save off the dashboard.

The Video option is an interesitng one as you can enter a title, a subtitle and a link to a video and it will embed on the dashboard. The other one that I reguarly use is the “Markdown” option.

For now we’ll just complete customizing so that we have a dashboard where we can pin a variety of items.

Adding content to your dashboard from the Azure portal

Within the Azure portal you can pin any view that you see to the custom dashboard which you created. As an example for some of the views in the portal there is a pin directly on a portion of the screen such as the one shown below.

Or you can pin a link to the same view in the top right corner of the page.

Adding content to your dashboard from Log Analytics

If you open your Log Analytics workspace in the Azure portal you can open the overview pane to see the top level of view of your OMS workspace.

From this view you can see the various solutions you have added to the workspace. Any of these top level views can be added to your custom dashboard by right-clicking on them and choosing the option “Pin to Dashboard’ shown below. In the example below we are pinning the top level view of the Server and Client Performance solution which was shown in a previous blog post.

Unfortunately you cannot currently pin dashboard views which appear in further drill-downs within the Log Analytics portal. A workaround for this will be discussed in the “Adding content to your dashboard from Application Insights” section of this blog post.

Sharing your custom dashboard

To share your custom dashboard click on the Share option shown below.

You will need to choose the name, subscription name, and location as well as checking the option to publish this into a resource group called ‘dashboards’ (Note: this will be important when providing access to the dashboard later, note where you add this for later).

Choose the publish option at the bottom to make this available. Please note, the order of these steps is important as you need to perform this step before adding any content from Application Insights to the dashboard.

Adding content to your dashboard from Application Insights

Within Application Insights you can pin any queries that you run or any graphs that you create directly to your dashboard. For example, let’s say that I wanted to display data like what I have in the drill-down for the server monitoring dashboard related to disk space. The graphic below is the drill down within the Log Analytics top level view of the Server and Client performance solution.

Unfortunately, as we have already seen it’s not possible to pin these dashboards. We can however drill down into this view and open the query in advanced analytics.

From Advanced Analytics we can visualize the data as text or with a variety of charts such as the sample below. Once you have the data visualized the way that you want you can pin it to a dashboard with the pin icon shown below.

When you pin the view it will let you choose from your shared dashboards (see the “Sharing your custom dashboard” section of this blog post).

Note: This same approach to pinning views to the dashboards works throughout Application Insights regardless of whether you go there directly from Application Insights or from a view within Log Analytics.

Customizing your dashboards

Now that we have added content to our dashboard and published any changes that we made we can see what it looks like.

That’s not bad but it could use a little clarification as to what is actually on the screen. That’s where the “Markdown” option comes in handy. We can edit the dashboard to move things around and to add some additional content.

You can drag over a Markdown and then make some customizations.

On the right side I change the title and then remove the subtitle and content.

Then I resize the markdown to match the size that I need. An example is shown below with markdowns added for clarification on what is on the dashboard. Once the changes are done, publish them to make the updated dashboard available.

And there you go! A sample shared dashboard with content from Azure, Application Insights and Log Analytics all together.

Note: One of the challenges with the Azure dashboard is the time range it displays. Based on my testing this appears to be a 24 hour time range for Log Analytics dashboard items and Application Insights appears to be a 14 day time range. I have not found an option which allows you to specify what the time range is for the dashboard, but you can drill into dashboard items and use the Filter option with the view that you drilled down into.

Summary: The Azure portal’s dashboard capability makes it easy to add content from within Azure, Log Analytics or Application Insights to provide your own sharable customized dashboards. There are a couple of challenges that I have run into (inability to pin lower level views from Log Analytics, and inability to set the time range for your dashboard) but overall I would recommend trying this out.