<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Powershell on Mark Allison</title>
    <link>https://markallison.co.uk/tags/powershell/</link>
    <description>Recent content in Powershell on Mark Allison</description>
    <image>
      <title>Mark Allison</title>
      <url>https://markallison.co.uk/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E</url>
      <link>https://markallison.co.uk/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E</link>
    </image>
    <generator>Hugo -- 0.151.2</generator>
    <language>en</language>
    <lastBuildDate>Fri, 06 Sep 2024 13:25:32 +0100</lastBuildDate>
    <atom:link href="https://markallison.co.uk/tags/powershell/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Script to Remove NOLOCK Hints</title>
      <link>https://markallison.co.uk/blog/remove-nolock-hints/</link>
      <pubDate>Fri, 06 Sep 2024 13:25:32 +0100</pubDate>
      <guid>https://markallison.co.uk/blog/remove-nolock-hints/</guid>
      <description>&lt;h1 id=&#34;the-problem&#34;&gt;The problem&lt;/h1&gt;
&lt;p&gt;Recently, I was performance tuning and enhancing the reliability of several SQL Server 2019 and 2022 databases for a client and discovered &lt;code&gt;NOLOCK&lt;/code&gt; hints everywhere. Why are these bad, they seem to improve performance and remove blocking for most queries?&lt;/p&gt;
&lt;h2 id=&#34;1-dirty-reads&#34;&gt;1. Dirty reads&lt;/h2&gt;
&lt;p&gt;This allows data to be read that is currently being modified by another query leading to inconsistent results. If a row that has been read gets rolled back because of an error like a deadlock, or network issue, the data never existed!&lt;/p&gt;</description>
    </item>
    <item>
      <title>Troubleshooting Get-AzVirtualNetwork</title>
      <link>https://markallison.co.uk/blog/get-azvirtualnetwork-error/</link>
      <pubDate>Mon, 16 Jan 2023 12:15:23 +0000</pubDate>
      <guid>https://markallison.co.uk/blog/get-azvirtualnetwork-error/</guid>
      <description>&lt;p&gt;Are you encountering the following error message when working with Azure in PowerShell and running the command Get-AzVirtualNetwork?&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-Get-AzVirtualNetwork:&#34; data-lang=&#34;Get-AzVirtualNetwork:&#34;&gt;&amp;#39;Microsoft.Azure.Management.Network.Models.SecurityRule&amp;#39;, 
on &amp;#39;T MaxInteger[T](System.Collections.Generic.IEnumerable`1[T])&amp;#39; 
violates the constraint of type &amp;#39;T&amp;#39;.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This error can be caused by an incompatibility between PowerShell 7 and the &lt;code&gt;Az&lt;/code&gt; Module and &lt;a href=&#34;https://github.com/Azure/azure-powershell/issues/18721&#34;&gt;incompatibilty with .NET 7&lt;/a&gt;. To fix this issue, try the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Upgrade to the latest versions of PowerShell 7 and the Az module.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the issue persists, remove all versions of the Az Module on your system by using the command &lt;code&gt;Uninstall-Module Az -AllVersions&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>What-If In Production</title>
      <link>https://markallison.co.uk/blog/powershell-what-if/</link>
      <pubDate>Wed, 26 Jan 2022 09:59:06 +0000</pubDate>
      <guid>https://markallison.co.uk/blog/powershell-what-if/</guid>
      <description>&lt;p&gt;What if you could do a dry run of your PowerShell script when making a change to your production environment?&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve read my other posts, you will know I am a big advocate of &lt;em&gt;infrastructure-as-code&lt;/em&gt;. Most of my work is done in the Microsoft Azure cloud, and although I encourage source controlling all assets within Azure, sometimes developers create things manually through the portal.&lt;/p&gt;
&lt;p&gt;Yes, I know! 🙄&lt;/p&gt;
&lt;h2 id=&#34;removing-azure-resources-safely&#34;&gt;Removing Azure Resources safely&lt;/h2&gt;
&lt;p&gt;A scheduled drift report should alert developers or DevOps engineers that the production state is out-of-sync with the source controlled code. If this happens, and some resources need removing, then the &lt;code&gt;-WhatIf&lt;/code&gt; switch comes in handy and provides confidence to remove items in production that shouldn&amp;rsquo;t be there.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Az.Sql Module won&#39;t load</title>
      <link>https://markallison.co.uk/blog/az-sql-module/</link>
      <pubDate>Tue, 16 Mar 2021 18:17:22 +0000</pubDate>
      <guid>https://markallison.co.uk/blog/az-sql-module/</guid>
      <description>&lt;p&gt;Today, the &lt;code&gt;Az.Sql&lt;/code&gt; module would not load on my machine when attempting to manually fail over a SQL Managed Instance with this error:&lt;/p&gt;
&lt;figure&gt;
    &lt;img src=&#34;2021-03-16_18-19-15.png&#34; alt=&#34;&#34; /&gt;
    
      &lt;figcaption&gt;module could not be loaded&lt;/figcaption&gt;
    
&lt;/figure&gt;
  
&lt;p&gt;I followed the advice of the error message and tried to import the module to get further information.&lt;/p&gt;
&lt;figure&gt;
    &lt;img src=&#34;2021-03-16_18-19-54.png&#34; alt=&#34;&#34; /&gt;
    
      &lt;figcaption&gt;module is already loaded&lt;/figcaption&gt;
    
&lt;/figure&gt;
  
&lt;p&gt;Hmmm :thinking:&lt;/p&gt;
&lt;p&gt;I decided to uninstall the Azure PowerShell from my machine using the Windows 10 Settings App. Looks like an old version.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Running a Sql Server Workload Using Powershell</title>
      <link>https://markallison.co.uk/blog/running-a-sql-server-workload-using-powershell/</link>
      <pubDate>Thu, 15 Feb 2018 14:41:18 +0000</pubDate>
      <guid>https://markallison.co.uk/blog/running-a-sql-server-workload-using-powershell/</guid>
      <description>&lt;p&gt;In February 2018, myself and Paul Anderton gave a presentation on how to correlate database deployments with performance issues within the context of a DevOps pipeline. We used Sentry One as our monitoring tool in a Performance Test environment so that we could catch badly performing deployments before they got to production and caused havoc. If you would like to see the recorded video, then you can download it from here: &lt;a href=&#34;http://info.sentryone.com/partner-webinar-performance-problems&#34;&gt;http://info.sentryone.com/partner-webinar-performance-problems&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Automating Adding Servers to Sentry One</title>
      <link>https://markallison.co.uk/blog/automating-adding-servers-to-sentry-one/</link>
      <pubDate>Mon, 20 Nov 2017 15:20:19 +0000</pubDate>
      <guid>https://markallison.co.uk/blog/automating-adding-servers-to-sentry-one/</guid>
      <description>&lt;h2 id=&#34;overview&#34;&gt;Overview&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Sentry One&lt;/strong&gt; is a great tool for monitoring many servers. For new installations, it can be a bit of a bind to add your existing servers into the tool to be monitored. I have written a PowerShell module to make this much easier and to validate that servers that you thought were being monitored, are in fact monitored.&lt;/p&gt;
&lt;p&gt;There is full documentation for the module in the Sentry One user guide which explains how to use the functions within it, but a brief explanation is shown below. it is worth mentioning that all the PowerShell cmdlets are doing is calling the SentryOne compiled PowerShell module provided when you install SentryOne.&lt;/p&gt;</description>
    </item>
    <item>
      <title>How to Check Sentry One Requirements</title>
      <link>https://markallison.co.uk/blog/how-to-check-sentry-one-requirements/</link>
      <pubDate>Sun, 12 Nov 2017 15:37:18 +0000</pubDate>
      <guid>https://markallison.co.uk/blog/how-to-check-sentry-one-requirements/</guid>
      <description>&lt;p&gt;I was at a client site recently and implemented Sentry One for them, a great monitoring system for SQL Server. It proved challenging because some servers were in a DMZ on a separate network and domain and some servers were in the same domain. All servers connected via a router and were firewalled off from each other with only the minimum ports open required for them to fully function and communicate.&lt;/p&gt;</description>
    </item>
    <item>
      <title>When to Use Cmdletbinding in Powershell</title>
      <link>https://markallison.co.uk/blog/when-to-use-cmdletbinding-in-powershell/</link>
      <pubDate>Sun, 11 Jun 2017 17:23:02 +0000</pubDate>
      <guid>https://markallison.co.uk/blog/when-to-use-cmdletbinding-in-powershell/</guid>
      <description>&lt;h2 id=&#34;clean-code&#34;&gt;Clean Code&lt;/h2&gt;
&lt;p&gt;I am a big proponent of clean code. I use PowerShell a lot for automation, and want code to be clean. You are automating everything, right? If not, please see a slide from a recent meetup:&lt;/p&gt;
&lt;figure&gt;
    &lt;img src=&#34;IMG_20170606_191942.jpg&#34; alt=&#34;&#34; /&gt;
    
      &lt;figcaption&gt;Disturbing&lt;/figcaption&gt;
    
&lt;/figure&gt;
  
&lt;p&gt;For me, clean code in PowerShell means (and not limited to):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Small self-contained functions that have a single responsibility&lt;/li&gt;
&lt;li&gt;Number of arguments to a function kept as small as possible&lt;/li&gt;
&lt;li&gt;Consistent formatting&lt;/li&gt;
&lt;li&gt;No duplication of code&lt;/li&gt;
&lt;li&gt;Modules that hide internal functions, and only expose what’s needed&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;common-parameters&#34;&gt;Common Parameters&lt;/h2&gt;
&lt;p&gt;One way to make code a bit cleaner is to make use of PowerShell’s common parameters. If you would like a refresher as to what these are, there is extensive documentation in PowerShell itself which you can access with&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
