Windows PowerShell™ is a task-based command-line shell and scripting language designed especially for automation of Windows tasks. It has become the defacto CLI for Microsoft products since the its release, and can fully leverage .NET frameworks.

learn more… | top users | synonyms

0
votes
0answers
8 views

where-object in powershell [migrated]

How can I club these two ? Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*|` Where-Object {$_.displayname -like "*Database Engine Services*" } | Select-Object ...
0
votes
1answer
17 views

In SQL Server and using only client side encryption requests, can I use a different certificate for each client?

Based upon the UI dialogue box in SQL Server Configuration Manager, if I right click 'Protocols for server_name', it appears that I can only select one certificate to use. My experience so far tells ...
0
votes
1answer
13 views

Connecting Remote Shares via Powershell

I had a big problem which I just happened to solve, but it's a permissions issue I don't quite understand. Unfortunately I'm in a tight bind and no amount of googling in the past week has really ...
0
votes
1answer
23 views

Trying to get password has for a login through PowerShell

I've trying to get the password hash for a SQL authentication login via powershell. The code I'm executing is something like this Invoke-Sqlcmd -Query "SELECT LOGINPROPERTY('$LoginName', '...
1
vote
1answer
25 views

AOAGs State Report

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”) | Out-Null $query = "select node_name, group_name, role_desc,operational_state_desc, synchronization_health_desc from ...
3
votes
1answer
73 views

Changing SQL account password in specific database

I am trying to change the password for userId in a specific database called LionsDB. If I am changing the password manually, I would login into SQL Management Studio using that user account and update ...
0
votes
0answers
14 views

Windows Powershell - multiline indirect for psql connection

I have a script that goes like psql << EOF sql 1 sql 2 EOF I want to do the same in Windows powershell. I learned about the script block, but tried passing it in Invoke-command, but hitting a ...
2
votes
1answer
35 views

PowerShell Pipeline Binding examples on SQL server?

I am learning PowerShell, my training machine (VM) is a Windows Server 2012 R2, with SQL 2014 and PS 4.0. I am try get a handle on the two Pipeline Binding methods ByValue & ByPropertyName. I am ...
0
votes
1answer
28 views

Powershell: Does System.Data.SqlClient.SqlDataAdapter usange in powershell need some ADO.Net installation?

In PowerShell, goal is to query some data from Sql Server and put that into a preformatted Excel file. Towards that, the following PowerShell script snippet, throws an error saying "assemblies are ...
1
vote
0answers
46 views

SQL Agent job step fails after upgrading to Powershell 5

I've not seen this issue discussed on the web, and have searched far and wide. I have a brand new HP DL380 running SQL Server 2008R2 standard. It's not yet in production, and I'm testing SQL Agent ...
0
votes
0answers
24 views

How to return a user defined error code through SQL based on the error

I would like to return a user defined error code in my SQL Server stored procedures based on the outcome. For example, if no error takes place, RETURN 0. If a validation error takes place, return 20....
1
vote
1answer
33 views

How to find the 'Instance ID' for PowerShell Invoke-TroubleshootingPack?

I was doing a PowerShell training, that said use the PowerShell help to run a "Networking troubleshooting pack" I found, ran and read Get-Help Get-TroubleshootingPack -full Get-Help Invoke-...
2
votes
1answer
50 views

How can I detect the use of SQL Server replication on a server (all versions) preferably using PS or CMD

I am trying to find a way to detect if a customer has SQL Server replication on. This helps decide whether they can use Express (as they frequently request) and this is one of the blocking factors. ...
0
votes
0answers
31 views

Error connecting from other SQL instance using powershell script

I have a job to run a powershell script that will rebuid fragmented index through source SQL instance to target SQL instance. The poweshell script didn't run due to the following error: Sqlcmd: ...
6
votes
2answers
321 views

Are cursors/While loops the only way to make administrative changes to multiple databases?

I specifically want a programmable way to change the recovery model of all the databases on a server, and i know this solution can be applied to all 'Alter Database' commands. While I know SMO in ...
1
vote
0answers
68 views

Powershell Invoke-Sqlcmd Implicit Transaction

Does Powershell, through invoke-sqlcmd or through running a query directly through a cmdlet, wrap a query in an implicit transaction? And if so, is there a way to work around this should my query ...
0
votes
1answer
71 views

Powershell invoke sqlcmd

How is it possible to execute a query as a applicationintent=readonly using powershell? I have an cluster alwayson environment. I want to call a procedure with invoke sqlcmd to the readonly database ...
1
vote
1answer
51 views

How is powershell commonly used in SQL server? [closed]

I am wondering how is powershell used in SQL Server? I heard people saying that powershell makes a DBA's life easier. But I dont know how is powershell commonly used in SQL server. Can anyone provide ...
1
vote
1answer
34 views

Modifying the Contents of SQL Server Agent Alerts

As is generally recommended to do, I have Alerts configured for errors of severity 19 and greater that occur on my SQL Servers. However, as part of an email notification standardization process, I'm ...
2
votes
2answers
175 views

Using Powershell Variables in a File-Stored Query with SQL Server

I'm attempting to run some SQL through Powershell, using a wrapper function in PS to run the SQL command. As well, my SQL is in its own independent file and not hard-coded inline to the Powershell ...
0
votes
1answer
28 views

Create a file with variable name in power shell Power shell

I am trying to execute the below power shell script to script out the db in sql server. [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null $s = new-object ('...
1
vote
1answer
76 views

TSQL Script Execution Through Power shell, Special Characters Rendering Problem

We have a simple T-SQL script file (.sql), which we execute through Powershell. Everything works fine, except the script portion, where we are using some special characters as string (example: 'ô' ). ...
0
votes
0answers
6 views

Need help on permission on AdvanceSharing

i have create a remove share using powershell and i want to enable everyone to have a "change" permission on the share i have create. I have used the below script to do so. But it is creating ...
3
votes
3answers
117 views

Improve Restore Speed

I have a ~3GB backup file from our QA database, and a daily diff (~500MB). For data complexity reasons, some of our developers like to use regular backups from this database, and so we have a process ...
1
vote
1answer
171 views

unable to run step 3 of syspolicy_purge_history job on SQL Server 2012

After installing an instance of SQL Server 2012 (SP3) on a server that had previously had SQL Server 2008R2 on it, I began encountering the following error while attempting to run step 3 of ...
4
votes
1answer
278 views

How do I enable both PowerShell Remoting and SPN for SQL Server Reporting?

I'm struggling with remoting servers with SQL Server Reporting Services running. My Reporting Services are running with individual domain-accounts, and I have set up SPNs for them (HTTP/<Machine>...
6
votes
2answers
196 views

Can't get databases or its objects with powershell

I have Powershell installed both in my server and development pc. In my dev machine apparently have a most recent version of PowerShell installed or some its components of SQL Server 'sqlps'. My ...
2
votes
1answer
62 views

How do I generate the ENCRYPTED_VALUE for CREATE COLUMN ENCRYPTION KEY?

I can make a certificate in the windows certificate store for the master column key easily enough with: $cert = New-SelfSignedCertificate ` -Subject "Always Encrypted Sample Cert" ` -...
1
vote
2answers
49 views

How do I view operators in a Notify Operator task in a Maintenance Plan?

In the past, we have added each DBA to a Notify Operator task on failure in Maintenance Plans ranging from scheduled backups to indexing and occasionally one-off operations. One of our DBAs recently ...
4
votes
1answer
59 views

How long does it take for powershell to restore a SQL Backup?

I executed this Powershell script to backup a Database, Drop that database and then restore it with a different name: $srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)") $...
-2
votes
1answer
117 views

Script to check CPU, memory, server type

Can someone please help me with the script to get CPU, total physical memory, server type(i.e. physical/VM), maxdop and max server memory details? I need it to run for 50 servers. All the servers are ...
4
votes
1answer
108 views

SQL Server Job Powershell is failing

I have a SQL Server 2014 instance job that runs nightly that moves backups from the local drive to a network drive. I wrote it using PowerShell. $mypath = $('F:\Backup\CRMDB01$CRMDB012014\Prod\Full\'...
6
votes
2answers
170 views

How to collect NTFS file properties and insert into SQL Server table

I have to provide reports on file system usage. I'm collecting statistics on file server usage down to individual file level so we can see who is using what files/folders, how much storage they're ...
3
votes
1answer
340 views

Using a Different Windows Account for Invoke-Sqlcmd

I'm attempting to make a Powershell script that needs to interact with SQL Server, so part of the script will involve invoke-sqlcmd. However, the script can't be scheduled as a job in SQL Server and ...
7
votes
1answer
888 views

Connect to LocalDB via SQLCMD in PowerShell

I'm trying to access the "localdb\MSSQLLocalDB" server on my computer through PowerShell with the SQLCMD utility. I'm using PowerShell v5, .NET v5.0, and the server name is (localdb)\MSSQLLocalDB when ...
2
votes
1answer
113 views

Script file execution through Power shell

We are trying to automate few things, one of them is to deploy patch in one go on selected DBs of SQL Server, as per my knowledge Powershell is an option. But I have zero taste buds of Power shell. ...
0
votes
2answers
36 views

SQL Service Account creation in AD using PowerShell [closed]

I'm wondering if it's possible to create a service account remotely from the SQL box using PowerShell, and put the service accounts created in the OU (folder) they belong in AD as part of a unattended ...
1
vote
0answers
85 views

Powershell To Run SQL Case Update [closed]

This is my syntax which throws an error of incorrect syntax near abcdefg. Can someone who is more experienced in the world of powershell take a gander and let me know how to remedy my issue? ...
6
votes
2answers
477 views

Running sp_AskBrent with @ExpertMode = 1 in PowerShell

I am trying to run sp_AskBrent from PowerShell using Invoke-SQLCmd and capture its output in a variable: $query = "EXEC SAIDBA.monitoring.sp_AskBrent @Seconds=10;" $check = Invoke-Sqlcmd -...
1
vote
1answer
502 views

Trying to use SMO Transfer Object to transfer a database from one instance to another

The schema tables are owned by dbo and another schema name. The code below is not moving over any tables. Is there something else that I need to add to make it transfer the tables? There are no stored ...
1
vote
1answer
2k views

Call Powershell script from another Powershell script

I have a problem. I develop some powershell scripts to perform actions on my Databases. In theory this PS should execute when them are called by the main powershell like the calls in .bat files. My ...
0
votes
0answers
43 views

Modify Script to not include *_snapshot_* databases

We use the script on the website below to script out replication. I would like to add a exclusion of databases that have a name _snapshot_ in the name of the database. http://www.sqlservercentral....
0
votes
0answers
40 views

Error scripting data using SQLPSX Powershell?

I'm trying to script the data using some of our Lookup tables. We've used SQLPSX in the past for other scripting just fine but can't get scripting data to work. Other ScriptiongOptions work just fine. ...
4
votes
3answers
1k views

Correct way to stop SQL Server (through automation)

Question Is it safe to start & stop SQL's services using PowerShell's Start-Service and Stop-Service commands? If not, is there a recommended way to start & stop SQL's services through ...
1
vote
1answer
109 views

Run PS-Script after job is done on 3 instances - SQL Server

I have backup jobs running on a server with 3 instances. Link to script: https://ola.hallengren.com/sql-server-backup.html The solution I found for the other 2 servers with only once instance was ...
0
votes
2answers
123 views

How to connect to a named SQL Server instance without specifying its name? [closed]

Is there anyway I can connect to a SQL server that has no default instance, using just the server name? I've tried using SQL CMD, but it seems that the named instance name is required to login, ...
1
vote
1answer
550 views

Cannot run Sql Server Agent jobs with PowerShell script

The problem: I have a customer that cannot run Sql Server Agent jobs with PowerShell script. It fails with this message: Message Executed as user: xxNC\SQLService. Unhandled Exception: System....
1
vote
1answer
55 views

Failed scheduled job [closed]

I have created 3 jobs in my MS SQL Server The job returns an error on 2. Remove top 4 lines Message Executed as user: myDomain\administrator. The process could not be created for step 2 of ...
2
votes
1answer
226 views

SQL Agent doesn't have perms to run a PowerShell script

I recently upgraded SQL Server from Windows 2008 R2 & SQL Server 2008 R2 to Windows 2012 R2 & SQL Server 2014 SP1. One of the sql agent jobs fails to run. The job runs a PowerShell script to ...
2
votes
1answer
96 views

powershell problem when running on a remote server - access is denied

as a follow up from this question below: Run a PowerShell script on a different server - from inside a SQL Server job there you can see that for me tu run a powershell script from inside a sql ...