Skip to main content

Questions tagged [powershell]

Windows PowerShell™ is a task-based command-line shell and scripting language designed especially for automation of Windows tasks. Questions using this tag should restrict themselves to interactions directly with the database tier. General PowerShell scripting questions should be directed to [StackOverflow](https://stackoverflow.com/questions/tagged/powershell).

Filter by
Sorted by
Tagged with
0 votes
1 answer
352 views

Exporting multiple TSQL result sets into one spreadsheet using Powershell

I have to load a lot of CSV files into a DB (3 at a time, resulting in one table per CSV, named as the file name and headers are). I then run about 12 different stored procedures using those table ...
1 vote
1 answer
350 views

how to update SSRS execution account automatically through powershell?

I need to update the password for the SSRS Execution account for every 15 days. How can I automate this process using powershell or some other scripting?
0 votes
1 answer
47 views

SQL Agent Job failing after uninstall of SQLPS and install of the new module

Uninstalled the old PS module and replaced it with the new SQLServer but now third step of system job syspolicy_purge_history, which is a Powershell step, fails with the following message: The error ...
0 votes
1 answer
5k views

How to List all roles and their members (users/groups) of an Azure Analysis Services tabular model/database

I have a tabular model/database in an Azure Analysis Server instance. Model/database has roles and users/groups were added on each role. I can see the list by right click on the role and then go to ...
0 votes
1 answer
339 views

Powershell script while executing mysqldump script

I'm having an error 1045: Access denied for user 'mysqlsuperuser'@'test.internal.cloudapp.net' (using password: YES) when trying to connect Here is the mysqldump command on my ps1 file. $command = [...
0 votes
1 answer
29 views

Invoke-PolicyEvaluation with the new SqlServer module generates security error

Started getting error messages after uninstall of PS and install of the new module SqlServer when evaluating policies on remote servers using Registered Servers and Invoke-PolicyEvaluation cmdlet. It ...
2 votes
1 answer
973 views

DBATools :: how to query Azure SQL Databases with MFA

I'm following the official DBATools guide regarding how to query Azure SQL Databases. This code is working: $azureCredential = Get-Credential -Message 'Azure Credential' $azureAccount = Connect-...
0 votes
1 answer
4k views

Read and Get Data from ExcelFile using powershell

I'm starting with powershell and this time. I have to read all the values from a excel file In this case from a specific sheet. The ultimate goal of this task is to get the values from two columns and ...
0 votes
1 answer
689 views

Invoke-AzVMRunCommand on Azure VM using domain user

I am working on ARM template to setup SQL server VM on Azure with Always on High availibility setup using Win server 2019 and SQL Server 2019 Enterprise image. I am trying to automate everything using ...
0 votes
1 answer
697 views

Generate script for all stored procedures in Azure SQL database

I'm trying to create a SQL script that will create all the stored procedures that were exported from another database. Basically navigating in SSMS to the database > Generate Scripts > select ...
0 votes
1 answer
448 views

Error with dbatools

Trying to export SQL Objects via DBAtools in Powershell. Get-DbaAgentJob -SqlInstance 'TestServer01' -Job 'mydatabase-daily-backup' | Export-DbaScript -FilePath C:\temp\mydatabase-daily-backup.sql ...
2 votes
2 answers
3k 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
0 answers
16 views

Write-DbaDbTableData - "Exception occurred while trying to enumerate the collection" error

I have the following code that I use to retrieve some TempDB space details on an AG: $DataDriveTable = Invoke-DbaQuery -SqlInstance $SQLInstance -Database TempDB -Query $SelectDriveQuery -...
0 votes
1 answer
723 views

Restoring a managed SQL instance in Azure using PowerShell

I am trying to figure out how to restore a database from one managed SQL instance to another. I'm following the tutorials, but I keep running into inscrutable error messages. Here's my command: ...
0 votes
1 answer
3k views

How to get currently used SSL certificate thumbprint from MSSQL

So, how to get currently running SSL certificate (especially thumbprint) from MSSQL using Powershell? It could include SQL commands... I know that it is in Windows Registry, but if you change it then ...
1 vote
2 answers
4k views

Unable to create a self signed Certificate for SQL Server 2017(14.x.xxxx)

Using SQL Server 2017 Developer Edition The command I'm using is: New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName host.doman.com -KeySpec KeyExchange -FriendlyName ...
0 votes
1 answer
534 views

PowerShell Subsystem max_worker_threads reverts back to default after applying cumulative update for SQL Server 2016

We change the PowerShell subsystem max_worker threads to 10, but after we install the latest cumulative update, it reverts back to 2. Is there a way to keep that from happening? SELECT s....
2 votes
3 answers
751 views

Trouble automating the install/execution of Ola Hallengren 'SQL Server Maintenance Solution'

I'll do my best to explain this as best I can, but kindly bear with me as I'm not a DBA and hacking my way through this. I'm tasked with ongoing deployment of SQL Server for end user clients on new ...
1 vote
1 answer
172 views

Insert values in PowerShell Variable into Oracle Database Table

I have created a script in PowerShell (utilising the PowerShell dbaTools) which collect information about SQ Server Estate in our environment. I need to insert the result from the PowerShell directly ...
1 vote
1 answer
368 views

Postgres psql command intermittently 'stalls' in powershell

I'm in the process of moving a postgres database to a new server. I have number of large tables, partitioned by month, each contains several 10's of millions of rows. I have a powershell script to do ...
0 votes
2 answers
99 views

Error when scripting SQL View dbo.spt_values

I am using a Powershell script to generate scripts of my SQL database objects (Tables, Views, StoredProcedures etc.). It was working fine in testing and still works on 2 out of the 3 servers being ...
0 votes
0 answers
98 views

Uninstalling a SQL Server instance using dbatools

I don't know if this is the right forum for this question, please let me know if it isn't and kindly point me in the right direction. I have just started learning powershell and dbatools. I am trying ...
0 votes
0 answers
25 views

Problems with minutes in timestamps when inserting data into InfluxDB via PowerShell

I am working with InfluxDB and trying to insert time series data via PowerShell. My goal is to insert data points with specific timestamps containing hours, minutes and seconds into InfluxDB. I am ...
0 votes
2 answers
805 views

Powershell dbatools combining result of multiple Get-dbaxxx commands to generate a report

I'm new to powershell and dbatools. It is a great tool but when I try to combine the result of few different commands into an array to be exported to csv, it is not providing the intended result. It ...
16 votes
5 answers
91k views

Get Job id OR Job name from within executing job

I have a central DB that I write job outcomes on all my servers back to. I pass 3 parameters via powershell in a SQL job back to a sp on the central server that verifies the job should be running at ...
4 votes
5 answers
14k views

Restore SQL Server database using Windows Powershell 3.0

I'm trying to restore a SQL Server database with a PowerShell script, but I'm having problems. Here is the error I'm getting: Exception calling "SqlRestore" with "1" argument(s): "Restore failed ...
-1 votes
1 answer
35 views

Backup and Restore Disaster Recovery

I am using PowerShell to write a script for DR, assuming that we only have backup files of all the databases. If i have a latest sql server version and i want to restore some database from backup ...
0 votes
1 answer
254 views

How to export as a pipe-delimited file using PowerShell?

This code creates a comma-separated file, I need to convert that to the pipe-delimited format. How to do that? $DataSet.Tables[0] | Export-csv "G:\Text.txt" -NoTypeInformation
0 votes
0 answers
39 views

Unix Powershell script stops after running SQLPlus command within the script

We are trying to create a Unix Powershell (not shell script) script which first runs a SQL to update a couple of tables, psprcsque and psprcsrqst. The function which runs the SQL update gets variables ...
1 vote
1 answer
160 views

Download certificate from Key Vault w/ private key for use in SQL Server (TDE) via powershell

I need to download an x509 Certificate from Azure Key Vault and import it in SQL Server to use for TDE. Note: I'm not referring to EKM providers/ASYMMETRIC KEYs, where SQL accesses key vault to pull ...
5 votes
2 answers
3k views

"the maximum number of '1' dedicated administrator connections already exists" message in error log when connecting to DAC from Powershell

I'm connecting to SQL Server (2016 and 2017 latest builds) via the Dedicated Administrator Connection (DAC) from PowerShell. The following error message is recorded in the SQL Server Error Log: Date ...
3 votes
1 answer
2k 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 ...
0 votes
0 answers
181 views

Use PowerShell script to backup SQL Server 2019 Express database to a network destination

I've got a SQL database server (SQL Server 2019 Express) and a application server connected by a simple switch. Now I'd like to back up a SQL database to the application server. Since its an SQL ...
0 votes
1 answer
3k views

Get-ClusterParameter Not Returning Expected Results

I have been trying to get the parameter value for RegisterAllProvidersIP in my AG environment. However, the command is not fetching me all results. The resultset has just 4 parameters, and I'm ...
0 votes
0 answers
33 views

"consise" SQL table scripting via Powershell SQLServer module

When I script a database using Visual Studio, I get a more "consise" script like the one below, where constraints are included in the create table statement. I'm wondering if there is an ...
1 vote
1 answer
414 views

Call SQL Stored Procedure from Powershell to insert XML into a table

I have a working stored procedure: USE [DB_NAME] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[INSERT_XML] -- Add the parameters for the stored procedure here @...
0 votes
1 answer
271 views

How can I get the SQL Server instance names running based on a hostname (COMPUTERNAME)?

I have only a hostname (what Microsoft calls a COMPUTERNAME). How can I get the names of SQL Server instances running on the host? It appears from other answers that I could look through the services ...
0 votes
1 answer
38 views

Run Policy Based Management On Central Management Server with Code

I have a jump\terminal server to administer 100 SQL Servers and want to evaluate my locally created policies across all the servers by using the Central Management Server but WITHOUT: creating the ...
1 vote
1 answer
509 views

Powershell script SQL Server AvailabilityGroups

I am really new to Powershell and hopefully someone can help me with this error. I have been given the below script that is supposed to take a list of SQL servers from a text file and lists out the ...
0 votes
1 answer
273 views

Why does `Get-ChildItem` require a call to `invoke-sqlcmd` to see `SQL SERVER:\SQL\...`?

PowerShell has a cool module for interacting with SQL Server. One of the features is the ability to navigate database objects like file system objects. For example: get-childitem -Path "SQLSERVER:...
0 votes
1 answer
1k views

Can we change the parameter of Find-DbaAgentJob?

Can we change the parameter of Find-DbaAgentJob? Hi there, I got "[Find-DbaAgentJob] Failure | Error connecting to [xxx.yyy.zzz]: The certificate chain was issued by an authori ty that is not ...
1 vote
1 answer
2k views

Can't Connect to WMI Provider on New SQL 2022 Install

I have a fresh installation of Microsoft SQL Server 2022 on Windows Server 2022 Standard. I'm attempting to enable Always On Availability Groups with the Enable-SqlAlwaysOn PowerShell commandlet but ...
2 votes
1 answer
3k views

ODP Connect String with Oracle Wallet

I'm trying to use ODP.NET in PowerShell to access an Oracle DB. I want to use my existing Oracle Wallet for the connection credentials but I find no hints about how to specify the connect string with ...
14 votes
6 answers
47k 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 ...
1 vote
3 answers
1k views

How can I export all of the Tables from a given Database in SQL Server to tab separated files?

I tried using SSMS but it only lets me export one file at a time and I'd prefer not to create an SSIS package. Is it possible to do this in PowerShell? I need the headers of each table in the file as ...
1 vote
0 answers
252 views

How to direct psql errors to powershell log file?

I'm running a powershell script on a windows system. The script includes psql commands to run SQL on a postgres database. Most stuff gets correctly recorded in the powershell log file, EXCEPT for psql ...
0 votes
0 answers
74 views

Rollback a write-dbadatatable with the truncate flag?

I'm using the dbatools for our SQL Server 2019 server. When I try to import an Excel sheet, I would like to truncate the table before importing the new rows. This is possible if I add the -Truncate ...
0 votes
1 answer
262 views

How to check AutoProtect setting for Azure Backup using PowerShell?

We have about 30 SQL instances being backed up by Azure Backup. I have the needed PowerShell commands to set the AutoProtect policy, but there doesn't seem to be a command to get the AutoProtect ...
0 votes
1 answer
411 views

Unable to connect to MariaDB using Invoke-SQLcmd

I have tried this a ton of different ways and I can't figure out why the syntax isn't working : I have mariaDB running on localhost 127.0.0.1:3306 and I'm able to connect successfully in MySQL ...
0 votes
1 answer
186 views

Reading from .sql file located in Visual Studio repository

A user.sql file which contains USE [database] GO -- Legacy users cleanup DROP USER IF EXISTS [dw]; etc... is located at the repository: https://company.visualstudio.com/Database/_git/Azure?path=etc... ...

1
2 3 4 5
8