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
31 views

SMO Not Scripting DB Objects

I have a PowerShell function included in the allusersallhost profile. It is basically scripting linked servers. When I execute the function from a PowerShell session, it scripts the linked server ...
4
votes
1answer
42 views

Passing current server name from SQL Server Agent job to PowerShell

I have a SQL Server Agent job that calls a PowerShell script in one step. And I want to pass the SQL server name and the current job-id to my script. With the job-id I have no problems. But with the ...
1
vote
0answers
57 views

how to pass the “file path” as a parameter in powershell?

I have recently added a SQL Server JOB on SERVER-A that goes to SERVER-B and backups all the SSAS databases. This seems to be fine. However when I want to delete backups older than 3 days, using ...
0
votes
2answers
52 views

PSQL not executing SQL command - Powershell

I have a simple script that should execute a select statement and output it to a CSV. My problem is that the script connects to the database and hangs waiting for my sql instructions (which are on the ...
0
votes
2answers
46 views

PowerShell script to access oracle system views

I am using PowerShell script to access oracle 11g's system views as SELECT COUNT (*) AS COUNT FROM v$session but I keep getting "ORA-00942: table or view does not exist" I have created a user with ...
2
votes
1answer
46 views

Powershell - SQL Server - connectionstring in loop for multiple Instances

Thisis part of a bigger script which finds DatabaseFiles on a SQL Server machine (multiple instances). Following should just return all files for 3 instances. The server is called V3000801 and ...
1
vote
1answer
43 views

SQL Server AS: Set ImpersonationMode via PS

Try to create a database in SQL Server Analysis Server (SQLAS, SSAS) version 2012 SP2 if that matters and set Impersonation Mode via Powershell. (try to avoid XMLA script). Here are my attempts. Does ...
1
vote
1answer
108 views

Powershell function to drop table(s) from SQL Server database [closed]

### List of tables that require full sanitizing $requiredTables = 'table1','table2','table3' foreach ($table in $requiredTables){ function Delete-FromTable{ $SqlConnection = New-Object ...
3
votes
1answer
76 views

Backup-SqlDatabase: Cannot bind parameter 'InputObject' Error Being Thrown

I have a PowerShell script that is used in a fairly complex automated process. One thing it does is creates a database backup, and for that we are using the Backup-SqlDatabase cmdlet. I am also using ...
0
votes
2answers
56 views

Executing a script via Powershell possibility

Let's say I don't happen to have the ability to create a Stored Procedure, but I have to run the same query on a regular basis. Would I be able to put my query in a .txt document and be able to run it ...
2
votes
1answer
30 views

Can't create an Availability Group with Powershell when instance uses non-standard port

I am trying to create an Always On Availability Group with PowerShell, something I have done many times before but am hitting an issue now that I am using non-standard ports for the SQL Instance I ...
0
votes
1answer
55 views

SA login history in sql

Is there any PowerShell script to get the SA log in history? I need to do an audit on SA login.
1
vote
1answer
122 views

Backup SSRS Encryption Keys Using Powershell

I have made the following script from google for backing up the SSRS Encryption keys: cls $pwd = "sa@123@123" $SSRSClass = Get-Wmiobject -namespace ...
0
votes
0answers
139 views

Problem running SSIS package remotely using PoSH

For various reasons I'm trying to run an SSIS package remotely using Powershell. I've enabled remote scripts on my server using the following command. Set-PSSessionConfiguration -Name ...
2
votes
0answers
74 views

SQL Server 2008 R2 : Unexpected timeout with SQL Agent Job/powershell

I have a SQL agent job set to execute a SQL query against a single database and then save each row into a different file with powershell before zipping the files up and emailing me. In one of my SQL ...
1
vote
4answers
201 views

Script to merge-replicate two MDF database files?

I have a program on a computer and on a tablet. The program uses SQL Server Express to interact with a local database (the same information on both) from a .MDF file. So if I plug the tablet into the ...
0
votes
0answers
47 views

Powershell error: “Cannot convert the ”[DBADEV\SQL2008r2]“ value of type ”Microsoft.SqlServer.Management.Smo.Server“ to type… ”

Error I'm getting from Powershell: Cannot convert argument "srv", with value: "[DBADEV\SQL2008r2]", for "SqlBackup" to type "Microsoft.SqlServer.Management.Smo.Server": "Cannot convert the ...
2
votes
0answers
125 views

How can I speed SQLPS connection when I don't have WMI permissions at the server

When connecting SQLPS to a SQL Server, it will try to run some WMI service status queries. In an environment where one does not have permissions for those, PowerShell issues a bunch of warnings, and ...
2
votes
0answers
120 views

Sql Powershell Script not working [closed]

I am performing a job from SQL server agent with a powershell command. It was running fine a couple of days back.. there is no change in the script. The script is also working fine if i run it via ...
1
vote
1answer
276 views

Comparing two different ODBC system-DNS entries. Which is faster? PS script

i want to find out which ODBC Connection is faster on my VM with Windows Server 2008 R2. I have two different ODBC providers. The first is "Oracle Instant Client ODBC" in v11. The other "Microsoft ...
1
vote
0answers
164 views

SqlPS and PowerShell with Import-Module SQLPS different behaviors

I'm trying to write an automated installation script in powershell for SQL Server Express 2014. I'm stuck with a stupid issue when trying to enable the TCP protocol in the SQL instance. What I'm ...
2
votes
1answer
123 views

Powershell Output Help

I have wriiten the following SQL script to execute using powershell. cls foreach ($svr in get-content "demo.txt") { $con = ...
5
votes
1answer
863 views

Execution-Policy Error running Powershell Script in SQL Server Agent

Running a powershell script from SQL Server Agent in 2014 using my AD account via a credential. I am getting the following error. A job step received an error at line 1 in a PowerShell script. The ...
0
votes
0answers
212 views

Powershell Restore Azure SQL Database to local with Restore-Database

I have written a powershell script that uses Start-AzureSqlDatabaseExport & Get-AzureStorageBlob to export my azure DB to a bacpac and download it locally, the next step is to restore the bacpac ...
0
votes
1answer
93 views

delete WSFC 2012 cluster role/group fails

PS C:\Windows\system32> get-cluster Name ---- sql2012poc_cl1 PS C:\Windows\system32> get-clustergroup Name OwnerNode State ...
1
vote
1answer
82 views

Wait for an AlwaysOn replica to be synchronized in Powershell

I am working on a disaster recovery script. One part of it is not being consistent. This is the code: ... ## Switch replica to Synchronous Set-SqlAvailabilityReplica -AvailabilityMode ...
2
votes
2answers
2k views

Execute Remote Powershell script from SQL Agent

A test SQL Server job hangs when it executes a Powershell script. It does work using my login and a Powershell window, but not using the Agent account and a job. The SQL Agent user has ...
4
votes
1answer
976 views

Dropping a table with powershell

Trying to delete an existing table using powershell $srv = new-Object Microsoft.SqlServer.Management.Smo.Server(".\CEF_2014_1") $db = New-Object Microsoft.SqlServer.Management.Smo.Database $db = ...
0
votes
1answer
120 views

How to verify a SSAS Backup and how to perform Integrity Checks in SSAS?

I have a procedure to backup SSAS Databases that is working successfully. I also delete the SSAS backup files that are older than 2 days. What I am looking forward to implement is: 1) How to verify ...
0
votes
1answer
86 views

SQL Server job - powershell Where does “log to table” save logs

After selecting the "log to table" option and running the job, when I come back to this screen and select View, I can see the output of the powershell script in a text file. The only job step is a ...
0
votes
1answer
416 views

Job showing the running sign but not currently running

I have a script to get the currently running jobs: -- get the running jobs --marcelo miorelli -- 10-dec-2013 SELECT sj.name ,DATEDIFF(SECOND,aj.start_execution_date,GetDate()) AS Seconds FROM ...
4
votes
2answers
961 views

Run a PowerShell script on a different server - from inside a SQL Server job

I have a procedure to backup SSAS Databases. That is working as a charm. Now my server is filling up with SSAS backups and I would like to delete the backup files that are older than 2 days. to ...
2
votes
1answer
255 views

Script Table Definition in Powershell

I'm writing a powershell to create a duplicate table(in another schema) for the purposes of partition switching*. I'm having problems adding the columns and the clustered column store index. Here's ...
3
votes
1answer
553 views

How Do I Use PowerShell to Get a SQL Server Backup Status?

I need a power-shell script to obtain the following information Name of the database , LastBackupDate of the database and this information should be sent via an email converting the results to HTML ...
0
votes
0answers
191 views

SQLCMD.exe in SQL Server 2012 does not give real-time output logging [closed]

I'm running a long-running stored procedure using sqlcmd.exe for automation purposes. However, I observed that in SQL Server 2012, sqlcmd.exe does not produce real-time logging. It displays only when ...
4
votes
4answers
5k views

What is the most effective way to discover all running instances of SQL Server using PowerShell?

I've been tasked with discovering all the instances of SQL Server that are running within our domain. In several cases there are multiple instances per server. I've seen two different PowerShell ...
3
votes
2answers
1k views

How does the PowerShell SQLPS SQLSERVER provider detect central management servers in SQLRegistration\Central Management Server Group

I'm experiencing odd behavior with the PowerShell SQLSERVER provider and the SQLRegistration\Central Management Server Group directory. Below are the behaviors. I would like to know how the SQLSERVER ...
3
votes
0answers
131 views

PowerShell Move-Item command made SQL and Windows entirely unresponsive [closed]

A LUN expansion completed overnight on our 15k FibreChannel VMAX SAN from 4 to 13 terabytes. This morning I attempted to move a 4.5 terabyte file from a temporary SATA LUN to the newly expanded LUN ...
2
votes
2answers
455 views

Detached database file permissions

I have a script that detaches databases for archival when they meet certain criteria. The script is executed by SSIS under the local Administrator account by the Ghost of DBA Past. Per design it (by ...
2
votes
1answer
97 views

SQL Server 2008 R2 - remove line below heading (which has ----,----) - dont have SSIS

I have found this line of code online sqlcmd -S localhost -d master -E -W -w 999 -s "," -Q "SELECT D.* FROM sys.databases D" -o "C:\sqlcmd.csv" This is used in a SQL job, to export to a CSV file. ...
2
votes
1answer
321 views

Iterating over the output of a SQL query with PowerShell

I have about 300 databases, (most) with a table, [File], and a column [Location] that holds a UNC path to a file. While migrating SANs, some needed files may not have been copied. This issue ...
3
votes
2answers
3k views

PowerShell Script To Identify Databases

I have enough PowerShell skills to get off the ground, but have none with SQL server. Can someone please point me in the right direction of how to use PowerShell to get information on remote SQL ...
0
votes
1answer
68 views

Why do my backup policies fail when a database's guest user is disabled?

I'm attempting to implement Policy Based Management on a SQL Server 2012 instance also acting as a Central Management Server using the Enterprise Policy Management Framework. The job running the ...
1
vote
1answer
57 views

PowerShell 'get-ClusterQuorum' output is not showing 'QuorumType' column

PowerShell cmdlet 'get-ClusterQuorum' output is not showing "QuorumType" column. Has anybody seen this before? Thanks
2
votes
1answer
295 views

SQL Server xp_cmdshell: account's access changed - how to avoid restarting the service?

A T-SQL script is running an xp_cmdshell call to stop a local service through Powershell's Stop-Service, say, like this: exec xp_cmdshell 'powershell Stop-Service -InputObject (get-Service -Include ...
3
votes
1answer
1k views

How to get server cpu, memory, network usage from SQL Server

For reporting purposes, I want to get SQL Server box CPU, memory, network (not SQL Server process alone) and show it in report. Do you have any idea how to pull this? My initial thoughts are run wmi ...
0
votes
1answer
47 views

Remove Cluster Nodes after Cluster Object was deleted

While building new 2012 servers to move to we had some change in requirements. We are using Availability Groups on the new servers. Here's where we started. Servers: Serv1a Serv1b Serv2a Serv2b ...
2
votes
1answer
464 views

Powershell Get-Counter not returning values for SQL counters

I am attempting to use PowerShell to get some SQL counters but it doesn't seem to return the SQL specific counters anymore. I am not sure what could have changed on my server that would have caused ...
3
votes
1answer
382 views

Why can't I script out CLR assemblies with SMO in Powershell?

I am creating a Powershell script to read all objects in a source database, script them and then re-create them in an empty destination DB (may be across different SQL Server versions). For the most ...
0
votes
0answers
283 views

Powershell Error Handling W/ SQL Restore Jobs

I would like to rebuild many of our SQL scripts into Powershell to further integrate my department with the Windows Operations team and to open up a lot of other options. Questions: 1-preference ...