<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>PowerShell on Andy M Mallon - AM²</title><link>https://am2.co/tag/powershell/</link><description>Recent content in PowerShell on Andy M Mallon - AM²</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Tue, 05 Oct 2021 15:54:03 -0400</lastBuildDate><atom:link href="https://am2.co/tag/powershell/index.xml" rel="self" type="application/rss+xml"/><item><title>What time is it in Oz?</title><link>https://am2.co/2021/10/05/what-time-is-it-in-oz/</link><pubDate>Tue, 05 Oct 2021 15:54:03 -0400</pubDate><guid>https://am2.co/2021/10/05/what-time-is-it-in-oz/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:300px"&gt;&lt;a href="https://www.youtube.com/watch?v=R4rpG-dipYA"&gt;&lt;img src="https://am2.co/wp-content/uploads/ElphiePup2-300x300.jpg" alt="Black dog wearing bandana standing on grass" width="300" height="300" class="size-medium wp-image-9493" /&gt;&lt;/a&gt; This is our puppy &lt;a href="https://en.wikipedia.org/wiki/Elphaba" rel="noopener" target="_blank"&gt;Elphaba&lt;/a&gt;. She's from &lt;a href="https://en.wikipedia.org/wiki/Name_of_Australia#Oz" rel="noopener" target="_blank"&gt;Oz&lt;/a&gt;...No, the &lt;a href="https://en.wikipedia.org/wiki/Land_of_Oz" rel="noopener" target="_blank"&gt;other Oz&lt;/a&gt;. She's &lt;a href="https://www.youtube.com/watch?v=R4rpG-dipYA" rel="noopener" target="_blank"&gt;popular&lt;/a&gt;.&lt;/figure&gt;&#10;&lt;p&gt;There was a &lt;a href="https://dba.stackexchange.com/q/300618/52344" rel="noopener" target="_blank"&gt;recent post on Database Administrators&lt;/a&gt;, where there was some confusion over Daylight Saving Time(DST) in Australian timezones. Let&amp;rsquo;s be honest though&amp;ndash;timezones are confusing, especially when DST comes into play. Arizona Time doesn&amp;rsquo;t observe Daylight Saving Time, so sometimes it&amp;rsquo;s the same as Mountain Time, and sometimes it&amp;rsquo;s Pacific Time.&lt;/p&gt;</description></item><item><title>Function to create SQL TABLE does not works well using Powershell</title><link>https://am2.co/2021/09/02/function-to-create-sql-table-does-not-works-well-using-powershell/</link><pubDate>Thu, 02 Sep 2021 11:41:40 -0400</pubDate><guid>https://am2.co/2021/09/02/function-to-create-sql-table-does-not-works-well-using-powershell/</guid><description>&lt;p&gt;&lt;a href="https://stackoverflow.com/q/69030492/1948808"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I need to get the values from a Excel Sheet (in a shared folder) to export it and then create a SQL Table in my instance. After of this I will execute a Stored Procedure (I already created) in order to create extended properties for a specific schema on tables,columns and rows.&lt;/p&gt;</description></item><item><title>Multi-subnet availability group, with mixed MultiSubnetFailover support (Part 2)</title><link>https://am2.co/2020/10/06/multi-subnet-registerallprovidersip-2/</link><pubDate>Tue, 06 Oct 2020 08:00:55 -0400</pubDate><guid>https://am2.co/2020/10/06/multi-subnet-registerallprovidersip-2/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=6U0C3LOwEP0"&gt;&lt;img src="https://am2.co/wp-content/uploads/AGListener01-b.jpg" alt="" width="512" height="315" class="alignright size-large wp-image-4885" /&gt;&lt;/a&gt;&#10;In &lt;a href="https://am2.co/2020/10/05/multi-subnet-registerallprovidersip-1/"&gt;yesterday&amp;rsquo;s post&lt;/a&gt;, I showed how to configure an availability group (AG) to use the &lt;code&gt;RegisterAllProvidersIP=0&lt;/code&gt; when you can&amp;rsquo;t get clients to connect using the &lt;code&gt;MultiSubnetFailover=true&lt;/code&gt; connection string attribute.&lt;/p&gt;&#10;&lt;p&gt;I mentioned that you have to make some trade-offs when you set &lt;code&gt;RegisterAllProvidersIP=0&lt;/code&gt;, and included this comparison:&lt;/p&gt;</description></item><item><title>Multi-subnet availability group, without MultiSubnetFailover support (Part 1)</title><link>https://am2.co/2020/10/05/multi-subnet-registerallprovidersip-1/</link><pubDate>Mon, 05 Oct 2020 09:00:48 -0400</pubDate><guid>https://am2.co/2020/10/05/multi-subnet-registerallprovidersip-1/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=jj8rmh8tna8"&gt;&lt;img src="https://am2.co/wp-content/uploads/AGListener01-a.jpg" alt="" width="512" height="315" class="alignright size-large wp-image-4885" /&gt;&lt;/a&gt;&#10;As a DBA, we have the opportunity &amp;amp; responsibility to build highly available database platforms for use by applications &amp;amp; users. Even if you are a DBA at a small company supporting databases for only internal applications, we are usually still responsible for providing databases as a service for application teams. Sometimes, in order for us to provide the best service, we need application teams to do some work to make use of the super awesome thing we built. And sometimes, getting application teams to make that change isn&amp;rsquo;t easy, or isn&amp;rsquo;t fast, or isn&amp;rsquo;t even possible.&lt;/p&gt;</description></item><item><title>Copying SQL Server settings to new server</title><link>https://am2.co/2019/10/17/copying-sql-server-settings-to-new-server/</link><pubDate>Thu, 17 Oct 2019 13:26:20 -0400</pubDate><guid>https://am2.co/2019/10/17/copying-sql-server-settings-to-new-server/</guid><description>&lt;p&gt;&lt;a href="https://serverfault.com/q/988391/299354"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;We are a small business using a single SQL Server 2014 instance as our main data platform.&lt;/p&gt;&#10;&lt;p&gt;We now need to set up a second instance (2017) to hold additional data - this is to be standalone, ie not replicated or actively linked to the main server.&lt;/p&gt;</description></item><item><title>Using PowerShell to tidy up CSV files</title><link>https://am2.co/2018/12/28/using-powershell-to-tidy-up-csv-files/</link><pubDate>Fri, 28 Dec 2018 13:31:18 -0500</pubDate><guid>https://am2.co/2018/12/28/using-powershell-to-tidy-up-csv-files/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=ptM7FzyjtRk"&gt;&lt;img src="https://am2.co/wp-content/uploads/CSV-150x150.png" alt="" width="150" height="150" class="alignright size-thumbnail wp-image-1623" /&gt;&lt;/a&gt;I was recently fussing with a CSV file that had an inconsistent number of columns. UGH. There was a bunch of historical data that had 4 columns, and then more recent data had a new attribute added with 5 columns. I spent a few minutes cursing whoever was responsible, then moved on.&lt;/p&gt;</description></item><item><title>Generating artificial CPU load 🔥</title><link>https://am2.co/2018/06/14/generating-artificial-cpu-load/</link><pubDate>Thu, 14 Jun 2018 11:43:10 -0400</pubDate><guid>https://am2.co/2018/06/14/generating-artificial-cpu-load/</guid><description>&lt;p&gt;I was recently asked:&lt;/p&gt;&#10;&lt;blockquote&gt;For testing, I need to generate artificial CPU load on the server, outside of SQL Server. Do you have any ideas? Maybe something with PowerShell? &lt;/blockquote&gt;&#10;&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=Q6bApDXbwGg" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/powershell-burn-300x195.png" alt="" width="300" height="195" class="alignright size-medium wp-image-1409" /&gt;&lt;/a&gt;&#10;I quickly replied:&lt;/p&gt;&#10;&lt;h2 id="heck-yea-powershell-can-do-that"&gt;Heck yea, PowerShell can do that.&lt;/h2&gt;&#10;&lt;p&gt;I mean, I knew PowerShell could do it. I just didn&amp;rsquo;t know how.&lt;/p&gt;</description></item><item><title>Is that share using SMBv1?</title><link>https://am2.co/2018/06/13/is-that-share-using-smb1/</link><pubDate>Wed, 13 Jun 2018 13:26:28 -0400</pubDate><guid>https://am2.co/2018/06/13/is-that-share-using-smb1/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:600px"&gt;&lt;a href="https://www.youtube.com/watch?v=-qTIGg3I5y8"&gt;&lt;img src="https://am2.co/wp-content/uploads/fancycrave-165874-unsplash.jpg" alt="" width="600" height="400" class="size-medium wp-image-1418" /&gt;&lt;/a&gt; Sharing is caring, unless the share is using SMBv1.&lt;/figure&gt;&#10;&lt;p&gt;In case you&amp;rsquo;ve missed it (though, if you&amp;rsquo;re a data professional or other IT pro, you must live under a rock if you&amp;rsquo;ve missed it), &lt;a href="https://en.wikipedia.org/wiki/Server_Message_Block#SMB_/_CIFS_/_SMB1" target="_blank" rel="noopener"&gt;SMBv1&lt;/a&gt; should never ever be used. Alas, some shares out there still exist &amp;amp; use it.&lt;/p&gt;</description></item><item><title>Using PowerShell to navigate SQL Server as a drive</title><link>https://am2.co/2018/02/15/ps-drive-sql/</link><pubDate>Thu, 15 Feb 2018 12:33:04 -0500</pubDate><guid>https://am2.co/2018/02/15/ps-drive-sql/</guid><description>&lt;p&gt;I might be a SQL Server pro, but I&amp;rsquo;m still a PowerShell novice. I learn best by doing, so I keep pushing myself to do more with PowerShell so that I can learn more.&lt;/p&gt;&#10;&lt;p&gt;If you don&amp;rsquo;t already know this about &lt;a href="https://docs.microsoft.com/en-us/sql/powershell/download-sql-server-ps-module" target="_blank" rel="noopener"&gt;the SqlServer PowerShell Module&lt;/a&gt;, you can access SQL Server via a path, as if it were a drive.&lt;/p&gt;</description></item><item><title>Troubleshooting Powershell errors from SQL Agent job</title><link>https://am2.co/2017/04/19/troubleshooting-powershell-errors-from-sql-agent-job/</link><pubDate>Wed, 19 Apr 2017 13:29:54 -0400</pubDate><guid>https://am2.co/2017/04/19/troubleshooting-powershell-errors-from-sql-agent-job/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/171395/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have a powershell script that I am trying to add in to a sql agent job, but the job step is failing with the following error&lt;/p&gt;&#10;&lt;div class="errorMsg"&gt;&#10;A job step received an error at line 1 in a PowerShell script. The corresponding line is 'import-module SQLPS -DisableNameChecking'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules\SQLPS\Microsoft.SqlServer.Management.PSSnapins.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.&#10;&lt;/div&gt;&#10;&lt;p&gt;I assumed that the error was being caused by differences in the module path, so I explicitly set the path via $env:PSModulePath to match the path of my powershell session where the code runs fine. I am pretty new to powershell, so any help you could provide would be appreciated&lt;/p&gt;</description></item><item><title>Building a Twitter-bot RSS Aggregator</title><link>https://am2.co/2017/01/11/building-twitter-bot-rss-aggregator/</link><pubDate>Wed, 11 Jan 2017 23:13:34 -0500</pubDate><guid>https://am2.co/2017/01/11/building-twitter-bot-rss-aggregator/</guid><description>&lt;h2 id="i-hate-rssreaders"&gt;I hate RSS readers&lt;/h2&gt;&#10;&lt;figure class="wp-caption alignright" style="max-width:512px"&gt;&lt;a href="https://www.youtube.com/watch?v=BxtKAvv1hLA"&gt;&lt;img class="wp-image-824" src="https://am2.co/wp-content/uploads/BotLove-1024x709.jpg" width="512" height="354" /&gt;&lt;/a&gt; I love my new bot&lt;/figure&gt;&#10;&lt;p&gt;For some reason, about once a year, I go hunting for a new RSS reader so I can keep track of blogs that I like to read.  It&amp;rsquo;s always the same process:&lt;/p&gt;&#10;&lt;ol&gt;&#10; &#9;&lt;li&gt;Dig through reviews to find an app that I think I will love.&lt;/li&gt;&#10; &#9;&lt;li&gt;Come up with a list of blogs that I like to read.&lt;/li&gt;&#10; &#9;&lt;li&gt;Install and configure RSS reader app.&lt;/li&gt;&#10; &#9;&lt;li&gt;Spend the night reading blog posts.&lt;/li&gt;&#10; &#9;&lt;li&gt;Use app for a week.&lt;/li&gt;&#10; &#9;&lt;li&gt;Never open RSS reader app again.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;Well, it's time to &lt;a href="https://www.youtube.com/watch?v=ZjfB4qDx3RM" target="_blank" rel="noopener noreferrer"&gt;stop the insanity&lt;/a&gt;. Its time to stop doing the same thing over and over again, hoping it will work this time. Its time to find a solution that really works.&#10;&lt;p&gt;Before I can find something that works, I need to think about&lt;/p&gt;</description></item><item><title>TSQL Tuesday #85: Backup + Recovery + ☁️</title><link>https://am2.co/2016/12/13/tsql-tuesday-85-backup-recovery/</link><pubDate>Tue, 13 Dec 2016 22:11:48 -0500</pubDate><guid>https://am2.co/2016/12/13/tsql-tuesday-85-backup-recovery/</guid><description>&lt;blockquote&gt;&lt;a href="https://sqlstudies.com/2016/12/06/4169/"&gt;&lt;img class="alignright wp-image-532 size-full" src="https://am2.co/wp-content/uploads/TSQL2SDAY-300x300.png" alt="TSQL2SDAY" width="300" height="300" /&gt;&lt;/a&gt;It’s T-SQL Tuesday,  the blog party that SQL Server expert &lt;strong&gt;Adam Machanic&lt;/strong&gt; (&lt;a href="http://dataeducation.com/blog/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;|t&lt;a href="http://twitter.com/adammachanic" target="_blank" rel="noopener"&gt;witter&lt;/a&gt;) started. This month’s episode is hosted by &lt;strong&gt;Kenneth Fisher&lt;/strong&gt; (&lt;a href="https://sqlstudies.com/" target="_blank" rel="noopener"&gt;blog&lt;/a&gt;| &lt;a href="https://twitter.com/sqlstudent144" target="_blank" rel="noopener"&gt;twitter&lt;/a&gt;). The topic: &lt;strong&gt;&lt;a href="https://sqlstudies.com/2016/12/06/4169/" target="_blank" rel="noopener"&gt;Backup &amp;amp; Recovery&lt;/a&gt;&lt;/strong&gt;&lt;/blockquote&gt;&#10;## Your backups are my bread &amp;amp; butter&#10;Backup &amp;amp; recovery are a DBA's &lt;a href="https://en.wikipedia.org/wiki/Glossary_of_baseball_(B)#bread_and_butter" target="_blank" rel="noopener"&gt;bread &amp;amp; butter&lt;/a&gt;. I always tell people that if you can't restore from backup in an emergency, you should at least make sure your resume is up to date--you'll need it. Part of my approach to making sure I have foolproof backups is making sure my setup is scripted and fool-proof to configure. Traditionally, this has been as simple as some T-SQL scripts that create the &lt;a href="https://ola.hallengren.com/sql-server-backup.html"&gt;backup stored procedure&lt;/a&gt;, and create a few SQL Agent jobs.&#10;&lt;p&gt;The SQL Agent jobs would write to the NAS, use the company standard retention, and everything was set. No muss, no fuss.&lt;/p&gt;</description></item><item><title>PowerShell can't see network locations after SQLPS module is loaded</title><link>https://am2.co/2016/08/15/powershell-cant-see-network-locations-after-sqlps-module-is-loaded/</link><pubDate>Mon, 15 Aug 2016 11:38:16 -0400</pubDate><guid>https://am2.co/2016/08/15/powershell-cant-see-network-locations-after-sqlps-module-is-loaded/</guid><description>&lt;p&gt;&lt;a href="https://superuser.com/q/1113679/630094"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I&amp;rsquo;m trying to automate a script that backups a database in one environment, copies it to the other, then restores it there. But there&amp;rsquo;s some strange behavior going on.&lt;/p&gt;&#10;&lt;p&gt;First, I try to access a network location. Works like a bliss:&lt;/p&gt;</description></item><item><title>Moving SSRS Reports between servers</title><link>https://am2.co/2016/06/29/moving-ssrs-reports-servers/</link><pubDate>Wed, 29 Jun 2016 12:30:42 -0400</pubDate><guid>https://am2.co/2016/06/29/moving-ssrs-reports-servers/</guid><description>&lt;p&gt;Today, my friend Derik Hammer (&lt;a href="http://www.sqlhammer.com" target="_blank"&gt;blog&lt;/a&gt;|&lt;a href="https://twitter.com/SQLHammer/" target="_blank"&gt;twitter&lt;/a&gt;) asked about moving SSRS reports between (versions and) instances of SSRS:&lt;/p&gt;&#10;&lt;div class="tweet-card" role="group" aria-label="Archived tweet by Derik Hammer"&gt;&#10; &lt;div class="tweet-card__header"&gt;&lt;img class="tweet-card__avatar" src="https://am2.co/images/tweet-profiles/derik-hammer.png" alt="" aria-hidden="true" loading="lazy"&gt;&#10; &lt;div class="tweet-card__identity"&gt;&lt;strong&gt;Derik Hammer&lt;/strong&gt;&lt;span&gt;@SQLHammer&lt;/span&gt;&lt;/div&gt;&#10; &lt;div class="tweet-card__brand" aria-label="Twitter"&gt;&#10; &lt;svg class="tweet-card__bird" width="18" height="18" viewBox="0 0 24 24" aria-hidden="true"&gt;&lt;path d="M23.95 4.57a9.8 9.8 0 0 1-2.82.77 4.93 4.93 0 0 0 2.16-2.72 9.86 9.86 0 0 1-3.12 1.19 4.92 4.92 0 0 0-8.39 4.48A13.98 13.98 0 0 1 1.64 3.16a4.92 4.92 0 0 0 1.52 6.57 4.9 4.9 0 0 1-2.23-.62v.06a4.93 4.93 0 0 0 3.95 4.83 4.93 4.93 0 0 1-2.22.08 4.93 4.93 0 0 0 4.6 3.42A9.88 9.88 0 0 1 0 19.54a13.94 13.94 0 0 0 7.55 2.21c9.05 0 14-7.5 14-14v-.64a10 10 0 0 0 2.46-2.54z"/&gt;&lt;/svg&gt;&#10; &lt;span&gt;twitter&lt;/span&gt;&#10; &lt;/div&gt;&#10; &lt;/div&gt;&#10; &lt;div class="tweet-card__text"&gt;What is the best way to move 2008 R2 SSRS reports into an existing 2012 SSRS instance? Catalog move is insufficient here. #sqlhelp&lt;/div&gt;&#10; &#10; &lt;div class="tweet-card__footer"&gt;&lt;time datetime="2016-06-29T14:47:59Z"&gt;2:47 PM · Jun 29, 2016&lt;/time&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&#10;&lt;p&gt;This reminded me of a PowerShell script I wrote a few years back, so I&amp;rsquo;m dusting it off for this blog post. I&amp;rsquo;m far from a PowerShell Pro, but I think this will be helpful to other people&lt;/p&gt;</description></item></channel></rss>