Category Archives: Powershell

Powershell sending wrong exit code to SQL Agent

I went to the edge of the Internet, and could not find the answer to my Powershell question.  Say I returned exit code from Powershell. SQL Agent, running the command from CmdExec, would always receive an exit code of 0. … Continue reading

Posted in Powershell | Tagged | Leave a comment

Powershell SMO Job Object

I am trying to kick off a job using SMO objects. And encountered the following error: Cannot find an overload for “Job” and the argument count: “1”. This simply means that the parameters weren’t used correctly. There should be two … Continue reading

Posted in Powershell | Tagged | Leave a comment

Running remote Powershell script in SQL job

A job was not able to complete when running a remote Powershell script. It would not really start either, but was just running indefinitely. I asked the question on StackExchange, and eventually found the answer. http://dba.stackexchange.com/questions/84126/execute-remote-powershell-script-from-sql-agent This article was helpful … Continue reading

Posted in Powershell | Leave a comment

Move Hallengren Backups to instance folder

The Ola Hallengren backup solution creates folder names of the concatenation of SERVER + $ + INSTANCE. I wanted to move these folders into a parent directory of INSTANCE. That is because I have several servers with the same instance … Continue reading

Posted in Powershell | Leave a comment

Move Ola Hallengren SQL Server backups

The Ola Hallengren backup solution is good.  If you need to redo security on the folders, and carefully move files to a new folder, here is a Powershell script to assist. Set your paths at the top, and it will … Continue reading

Posted in Powershell | Leave a comment

Powershell Get all backups before a certain date

Get-ChildItem -Path \\FileShare\SQLBackups\Product -Filter *.BAK -Recurse | ? { $_.LastWriteTime -le [DateTime] “10/1/2014” } | Out-File OldBackups.txt

Posted in Powershell | Leave a comment

Powershell SMO Restore issue

Hey, I started a new job.  And just as I had hoped, I had the opportunity to learn new things.  One of the things I’m learning is Powershell. I wanted to restore a database using SMO (SQL Server Management Objects), … Continue reading

Posted in Powershell | Tagged | Leave a comment