Tag: SQLNewBlogger

  • Arrays in PowerShell–#SQLNewBlogger

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    This isn’t necessarily an expert post, but more a recognition that I learned something. I knew about objects in PowerShell, but I’d never actually used an array. Never had a need.

    However, while writing my article about striped backups, I ended up using arrays. This was mainly from the example shown by Anthony Notencino in his Restoring Backups from Azure Blob with dbatools.

    Here’s a way to initialize an array:

    $a = @()

    If I look at this, I get nothing back, which makes sense. There’s nothing in there.

    2019-10-10 14_41_05-cmd - powershell

    I can “add” values to this array with +, as in:

    $a += 1
    $a += 2

    If I now look at the variable, I see this:

    2019-10-10 14_44_41-cmd - powershell

    One interesting thing here is that += is different than Add(). Look at this:

    2019-10-10 14_52_15-cmd - powershell

    So why does += work? In the array doc, there’s this quote:

    When you use the += operator, PowerShell actually creates a new array with the values of the original array and the added value. This might cause performance issues if the operation is repeated several times or the size of the array is too big.

    Worth knowing this. I think for most scripts this isn’t a big issue, but be aware that you are allocating a new array.

    Working with arrays is a topic for another day, but this is a short look at how you might store something like a list of files in a single place.

    SQLNewBlogger

    While working on solving the problem for a customer, I realized this was a little thing I learned. A quick post to show that here, just about 10 minutes or writing and structuring code.

    A good chance to give an interviewer something to ask you. Write your own post on arrays.

  • Setting Permissions for a SQL Server backup folder–#SQLNewBlogger

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    While testing a script recently, I needed to set a few backup folders for my instance. This was a striped backup, and using one folder wouldn’t make sense. In modern OSes, we can’t just create a folder and expect that our processes can read it. We need to explicitly set permissions.

    It’s fairly easy for SQL Server, but since it wasn’t obvious, I decided to take a minute and document this.

    If I create a folder, say c:\sqlbackup, I see this kind of thing in properties on my Window 10 machine.

    2019-10-08 14_53_19-SQLBackup Properties

    If I click “Edit”, I get a similar view.

    2019-10-08 14_53_27-Permissions for SQLBackup

    Now, my SQL Server process can’t access this. If I try to restore a backup from here, I’ll get a permissions error.

    That’s fine. In the Permissions, I can click Add and I’ll get this dialog.

    2019-10-08 14_53_35-Select Users or Groups

    From here, I can enter “NT Service\MSSQLServer” or “NT ServiceMSSQL$SQL2017” for a named instance. My named instance is SQL2017.  Note the space in “NT Service”

    2019-10-08 15_00_49-Select Users or Groups

    If I click the “Check Names”, this will resolve for the built in service account.

    2019-10-08 15_00_53-Select Users or Groups

    Then I can click OK and set the appropriate permissions.

    If your service account is something not built in, it’s usually easy to find and add, but for build in accounts, you need the “NT Service”.

    SQLNewBlogger

    You can take a simple thing here that you needed to solve and write about it. This took my about 5 minutes to solve, playing with different names, and then about 5 minutes to write.

    Showcase your knowledge today.

  • Just Getting Specific Files in PoSh–#SQLNewBlogger

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    Just a quick one today, but a tip I hope I remember. While working on a script, I wanted to just get backup files in PoSh. I tried this:

    Get-ChildItem -Path $BackupPath -File -Include *.bak

    That got me this:

    2019-09-23 10_06_19-cmd - powershell

    Nothing.

    Why not? Apparently, you need the –Recurse parameter, even though there are no subdirectories in this folder. A bug, IMHO, but who knows. In any case, adding the parameter makes things work. Thanks, SO.

    2019-09-23 10_11_59-cmd - powershell

    SQLNewBlogger

    This was a quick 5 minute thing. After researching and testing for 10 minutes, and finding the solution, I wrote this up.

    You could do that with anything you get working.

  • Shutting Off PowerShell Warnings–#SQLNewBlogger

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

    Not really a SQL Server post, but I ran into this minor issue. While running a script, I saw this:

    2019-09-19 16_47_13-● RestoreUnknownStripedBackup.ps1 - SitC 2018 - CreateProtectManageDB - Visual S

    The warnings aren’t a big deal, and in fact, have no bearing on my script. At least, not on this script. Since I needed to give this to a customer as a PoC item, I didn’t want any weird warnings. As a result, I needed to suppress these. A little intellisense in VS Code gave me a hint, but what value to use for the parameter?

    2019-09-19 16_47_46-● RestoreUnknownStripedBackup.ps1 - SitC 2018 - CreateProtectManageDB - Visual S

    A quick search brought me to Server Fault, where I saw the value. I added the SilentlyContinue to my script and messages suppressed.

    2019-09-19 16_48_11-● RestoreUnknownStripedBackup.ps1 - SitC 2018 - CreateProtectManageDB - Visual S

    SQLNewBlogger

    This is a helpful tip for me, and I think I showed you how I found an issue, researched, and solved it. It’s good to give a potential employer some confidence that you can work through issues and find answers.

    This took me less than 10 minutes. I bet you could do the same thing in the same time. Write about how you solve a small issue and drop it on your blog.