Questions tagged [powershell]

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.

Filter by
Sorted by
Tagged with
0
votes
0answers
16 views

Using SQL Agent Job to execute a script from a UNC path

I need to execute a script located on an UNC share. I've setup my SQL job to use CMDExec and to execute the following command: PowerShell -NOPROFILE -ExecutionPolicy Bypass -File \\Server\...
1
vote
1answer
23 views

Deleting expired SQL server database backup file on data domain using PowerShell

I am backing up the database on data domain however I'll have to delete an expired backup using following command. It's an emc databoost agent app for Microsoft sql server. I am trying to convert the ...
0
votes
1answer
54 views

Determine the source of user permissions in a database

I have a developer that just accidentally ran an UPDATE and ALTER TABLE script he was working on in a production database instead of the development environment. How can I track down what security ...
0
votes
0answers
39 views

Powershell script hangs with psql command, continues only after hitting enter

I have a simple powershell script that is supposed to drop an existing schema and restore it from a backup, the script is basically those lines: echo "Dropping Schema MySchema" & $PG_SQL -d "host=...
0
votes
1answer
33 views

PowerShell script to send an email with SQL results in HTML format

Does anyone have a PowerShell script to query results from a SQL Server database and send it out as an email in HTML format?
1
vote
3answers
49 views

Report of permissions in SQL server

I want to write a report that gets all the permissions for every Login in our SQL server farm. For now I can get the logins but get stuck there trying to connect the logins to roles. Haven't even ...
0
votes
0answers
49 views

Error while executing PowerShell script using SQL Server Agent Job

I am executing a PowerShell script using SQL Server Agent job, script code is given below(it is added as is in the Job step 1) : $OriginFile = "\\vmpr-file1\share3\RT-BI_Shared\ABC.xlsx" $SourceFile =...
7
votes
2answers
745 views

How can I install the SQL Server PowerShell module on an offline machine?

I have some SQL Server machines that cannot connect to any external sites. I have been using PowerShell more and more when managing databases, so I definitely need this module to be installed so ...
0
votes
0answers
19 views

how to handle $ inside parameters in powershell

How to handle a $ sign inside a parameter used for SQL code. If I am going with code all My $Some_text (Prefix with $) with Null (Noting Just a space) POSH command used : $attachSQLCMD1 = @" .......
1
vote
1answer
34 views

how can I get only the SQL server logins, when we use Export-dbalogin

when we run the export-dbalogin, it will will generate a script(.sql) file, which we will run the in the destination server, then the logins will be migrated, but this command will give both windows ...
1
vote
1answer
33 views

How do I pass a variable into -job on Copy-DbaAgentJob?

I'm trying to query one the source instance and copy across any missing jobs into the destination instance. Everything seems to work except passing the name into -job. Can anyone suggest a fix or ...
0
votes
1answer
34 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
1answer
36 views

What permissions does the SQL Agent's user need to execute Powershell scripts?

I'm trying to create a job with a Powershell step. To recreate this: create new job, give it a name add a new job step, name it, type powershell, run as the SQL Agent, script: $test="test" set the ...
0
votes
1answer
51 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 ...
1
vote
1answer
95 views

SQL Server Encrypted Connections - Configuration Manager does not see Certificate

My goal is to implement encrypted connections on Test SQL Server instance First, tried to create self-signed certificate in the Certificates snap in (certlm.msc), Personal > All Tasks > Request New ...
4
votes
2answers
681 views

Query Multiple SQL Server Instances using Powershell referencing the list of instances in a text file

Rather than issuing a query per instance via SQL Server Management Studio, we are trying to create a powershell script to query multiple instances by going through a loop referencing a text file where ...
1
vote
1answer
249 views

how to list the SSRS permissions in each folder in the reporting services server?

I have the following powershell script that downloads all the RDL from a reporting services server. I am not the author to whom I am very thankful. It has been very useful for downloading the RDLs. ...
-2
votes
1answer
330 views

PowerShell script to output SQL query results [closed]

I have the SQL cmdlets loaded in PowerShell, need a script to execute a SQL statements and save results in pipe delimited file
3
votes
1answer
90 views

where can I find the DNS name associated to the listener of an Availability Group?

I have an availability group that has a listener. The listener is called SQLPROD as you can see on the picture below. It uses port 1433 When I run the following script: ALTER AVAILABILITY GROUP [...
0
votes
1answer
65 views

How to capture data from a PowerShell script that runs as part of a SQL Agent Job?

I have a PowerShell script called from an Agent job which opens an Excel file, converts it to .CSV and saves the .CSV file in a particular location, ready for me to import it with BULK INSERT. What I ...
0
votes
2answers
79 views

How to automate creating credentials in a secure way

We have created an automated process to stand up a new SQL Server using TFS and powershell. As part of a new server build, we deploy a database and a set of jobs for dba use. As part of the install ...
2
votes
2answers
164 views

PowerShell command 'New-Item' fails when invoked through SQL Server Agent job

I have the following PowerShell script to create a folder at a share location. The share has full control permissions for everyone. I have granted all permissions for testing. The problem is the ...
0
votes
1answer
37 views

How to find port using Get-DbaTcpPort

How to find whether the port used by SQL Server is static or dynamic using Get-DbaTcpPort dbatools command? Below command doesn't show whether it's static/dynamic: Get-DbaTcpPort -sqlinstance TEST ...
0
votes
1answer
94 views

How to create multiple azure sql database in an elastic pool using powershell script?

I want to create a sql server and deploy the elastic pool on that server. Then create multiple azure sql database in that elastic pool using powershell script.
0
votes
0answers
41 views

Get-Counter not accepting array created from SQL

When I try and generate an array from a SQL output, although it's the same data type and content, perfmon doesn't accept these values, whereas it does for a manually created a list. So the first call ...
0
votes
0answers
35 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....
1
vote
1answer
132 views

How to list Extended Properties for all databases

I am currently working on task where we use Central Management Server and Server Group for easy access to our SQL server boxes. I am trying to query the extended properties for all databases on ...
0
votes
1answer
179 views

How to pass parameter value for ExecuteReader() - powershell

I am trying to run following powershell script. How Can I pass parameter value for @P0= '2019-11-22' and @P1 = '123456789' during runtime? $sqlconnection = New-Object System.Data.SqlClient....
1
vote
1answer
56 views

Union from Multiple Tables in many databases and group results in batches of n

First post in dba, so please be gentle. I have a project I am working through and have 4+ SQL Server databases to work with. These DBs contain 2 (or more tables) I wish to UNION the results from. ...
0
votes
0answers
34 views

SQL/Powershell job failing

Need more help from you brilliant folks. I am trying to import a CSV file to a SQL table with this code: $SQLServer = "MYSQLINSTANCE" $SQLDatabase = "DBATools" $SQLString = "Server=$SQLServer;...
1
vote
2answers
754 views

Invoke-SQLCMD with special characters

I'm currently working on a project integrating AD with SQL Server data, which I am handling mainly via powershell (Invoke-SQLCMD in particular). The issue I'm running into is if someone has a special ...
0
votes
1answer
29 views

Why does a fresh SQL Server instance with the same details as the original think that my DB backup is in the original location?

So I'm working on a server application for a large government body and need to setup a development environment to test on. For this I'm using a Vagrant-controlled VM with Windows Server 2019 installed ...
0
votes
1answer
21 views

Where does [reflection.assembly] reside?

In a disconnected DEV box, I attempt to load the reflection assembly, "Microsoft.SqlServer.SMO". Then I try to call for a SMO.Server object, like this [Reflection.assembly]::("Microsoft.SqlServer....
0
votes
1answer
127 views

SQL Job PowerShell task fails same command succeeds as user

Simple requirement: delete files on remote path older than 20 days. PS C:\Users\Administrator> Get-ChildItem ` -Path \\FileServer\SQLBackups\SQLServer\ ` -File -Recurse -Force | Where-...
1
vote
1answer
46 views

How to create a job that uses Powershell script? [duplicate]

I have a powershell script which deletes old backups from NAS storage. I have already tested it using Windows Powershell and it works but I couldn't perform the same thing in SQL Server. I have ...
1
vote
1answer
88 views

Index Fragmentation Monitoring: Can I make this query faster?

I have a query that is run against each database on two of my servers using a PowerShell script to initiate the script and throw the results into a CSV thus the need to have temp tables. Is there a ...
0
votes
0answers
325 views

Postgres using powershell scripts - where do trigger messages go?

I have a windows (10 pro) powershell script that reads messages from an external server and INSERTS them into a postges (v10.5) database table. The table has an AFTER INSERT trigger defined on on it ...
2
votes
2answers
85 views

SMO, Powershell, & Failed Logins

Background At my current organization, we've got a SQL Agent Job running a Powershell script, originally based on Script All Server Level Objects to Recreate SQL Server. This job writes a bunch of ...
0
votes
1answer
55 views

How to Configure Always Encrypted using PowerShell

I just want to ask if there is a way to configure always encrypted columns using power shell? like for example i want to encrypt a column in a table with deterministic using powershell codes?
0
votes
3answers
512 views

Check if a SQL Login exists without SA

How can I check if a SQL Login exists for an arbitrary domain user if the account I'm running doesn't have SA rights to the instance (but will be dbo on at least one DB) Ideally I'd like the solution ...
1
vote
2answers
107 views

Import table data into a text file

I'm new to powershell. I need to write a script which will import data for each table into separate text file.For sample table, I tried with below script: bcp -u sa por.dbo.audit out D:\tbackup\...
1
vote
1answer
557 views

Use Powershell to query SSAS connection string

I want to retrieve the existing connection string from SSAS for each OLAP Cube or Database. The data will be used in a control/audit report. I've found that Powershell allows me to drill into SSAS ...
1
vote
0answers
65 views

SQL Vulnerability Assessment Error in PowerShell

I am running Vulnerability Assessments against my SQL Servers and databases using the PowerShell cmdlets Invoke-SqlVulnerabilityAssessmentScan and Export-SqlVulnerabilityAssessmentScan, however, I am ...
1
vote
1answer
93 views

Does MySQLDump Verify the backup as restorable

I have written a PowerShell script to use MySQL dump to perform full backups of a specific database at a specific time. I am wondering if I need to confirm the backup is restorable via my script or ...
5
votes
1answer
1k views

How to Natively Return Output when using Invoke-Sqlcmd?

How do I natively log output from the PowerShell Invoke-Sqlcmd? I am using Invoke-Sqlcmd to loop through a large (50,000-90,000 SQL files w/ 1-10 inserts in each) set of small SQL insert statements. ...
0
votes
1answer
478 views

SQL Server unattended / Silent installation override Configuration.ini file in command line parameter

I am creating a PowerShell script to install SQL Server 2012 silent installation. It is not hard to find a tutorial or instructions online on how to do so. I want to my script be a bit more flexible ...
0
votes
0answers
130 views

SQL Agent PowerShell job runs in ISE but not in SQL Servere

My PowerShell script uses WinSCP to download files. It writes a message to a sql server table containing the number of files downloaded. When run within ISE it's fine. When run as a sql agent job ...
2
votes
1answer
64 views

Call Powershell command string from Sql Query Publish profile script

Is there a way to call powershell in SSMS Sql query window? I know Command prompt can be invoked with xp_cmdshell. Does similar method for powershell exist ? (Note, I know about powershell window , ...
2
votes
1answer
43 views

SQL Server Audit File Metrics Information

I'm currently working in an environment that requires we enable SQL Server Audit, enterprise-wide. We generate .sqlaudit files as we have retention and access guidelines, and I'm finding that we need ...
1
vote
1answer
118 views

Powershell runs locally but fails when put in a job - login failed, login is from an untrusted domain

I have a powershell script that queries from the local server for a list of servers and then iterates through that list of servers, connects to them, queries some data, and then connects and inserts ...

1
2 3 4 5
7