Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
17 views

How to change SharedDatasets in SSRS on several reports at the same time

I moved the report server from one server to another. Now I need to change the Shared Dataset url in the 300 report definition, from server_1 to server_2. Below is a bit of problematic source in XML: ...
0
votes
0answers
20 views

SQL Agent Powershell step not using specified proxy

I'm trying to execute a powershell script, and use a proxy to do. The job runs correctly, but using whoami within the script to log the executing user indicates that the script is not being run by the ...
1
vote
2answers
26 views

Get-SqlAgentJobHistory Invoked By

I want to report on failed Sql Agent jobs using Get-SqlAgentJobHistory but excluded jobs that were not invoked by the service account. I'm running this cmd: Get-SqlAgentJobHistory -ServerInstance $...
1
vote
0answers
19 views

Extracting AD subgroups information [duplicate]

I need to extract AD groups and all of it's subgroup into an excel sheet.Basically the script should loop though each of the AD group and get their subgroup. AD_Group Subgroup ---------- -----...
0
votes
0answers
12 views

Recursively enumerate Active Directory forest AND dynamically pivot results [migrated]

I'm trying to get a list of all the AD groups along with their sub groups. It should be recursively populated and then displayed with the following column style Parent_Group, Child_Group_Level1, ...
3
votes
1answer
52 views

SQL Visual Studio Find and Replace in Publish Profile

We have source control in Visual Studio Database Projects (SSDT). To make cross database references, we utilize something like this below in Project References. We need Project references, since ...
0
votes
0answers
39 views

Powershell Invoke-Sqlcmd2 Timeout

I'm creating a PowerShell job step to perform index stats in parallel. The job is designed to perform index maintenance on alternating databases based on database ID & the day of week. Originally, ...
0
votes
0answers
10 views

Heroku postgres database encoding issue

When i try insert statement on heroku postgres console the arabic character appear "????" On linux every thing work fine, but on Win 10 Powershell is seems that there is problem with encoding ...
2
votes
3answers
70 views

How to speed up rebuilding a database from scratch/scripts

Our Database exists in many different scripts within our source control. i.E. every table has it's own scripts for creating the table, the indexes and so on. When needed, we can rebuild the entire ...
0
votes
0answers
38 views

PowerShell DBAChecks Module - Unable to use

I'm unable to get the DBAChecks Powershell module to work. I'm new to Powershell, I've been able to use DBATools, but getting errors when I'm attempting to use DBAchecks. I've attempted to use the ...
2
votes
2answers
54 views

DBATools - pass through flat file configs to Agent Job Commands

I'm experimenting with source controlling my SQL Agent Jobs & Schedules as .json files and deploying them with the dbatools SQL Agent command suite. Given $sa = Get-Credential and foo.config of ...
1
vote
1answer
81 views

DBATools offline install - export-dbainstance was not found

I followed the instruction at https://dbatools.io/offline/: download zip & unzip run $env:PSModulePath to find all the paths. copy to C:\Program Files\WindowsPowerShell\Modules. run Get-ChildItem ...
1
vote
1answer
32 views

how to script out all the permissions in a folder using powershell?

Using the script below I find out where are the data and log folders: declare @rc int, @dir nvarchar(4000) declare @data nvarchar(4000) declare @log nvarchar(4000) ...
1
vote
0answers
34 views

Switch-SQLAvailability error during DB Restore in AlwaysON Group

Can anyone share your inputs on below and how to fix the issue and possible causes of failure? I am trying to restore a DB using PS script and at one step it is failing during the role change test ...
0
votes
1answer
40 views

CmdExec Powershell Job Step Escape Double Quotes

I have a PowerShell job step I'm trying to execute and it's failing with a syntax error I believe is because I'm trying to escape double-quotes in my code. Can anyone take a look and help me with ...
0
votes
1answer
73 views

How do I compare Schemas for Multiple Databases to a True Copy?

We have a database for each customer, over 700 databases. All the schemas are supposed to be exact same. We have Source Control database, and want to schema compare to the 700. Sometimes schema in ...
0
votes
1answer
18 views

How to Remove Scripts Date Comments from Powershell Generate Database Script?

I am generating Database Generate scripts with Powershell. What is the option in Powershell to remove Script dates comment lines? Automated Script-generation with Powershell and SMO Object: Table ...
1
vote
2answers
95 views

SSIS package deployed to SQL Server hangs when running a Powershell script

We have a SSIS package that tidies up a few files and folders, and want to automate it to run every night via the SQL Server Agent. When running the package via Visual Studio (2015 and 2017) the ...
0
votes
0answers
30 views

Powershell Script in SQL Server Failing Due to Missing Method in System.__ComObject

I have a powershell script I'm executing as part of a SQL job and it is failing to write to the table. Running as CmdExec, here is my script. powershell.exe "Get-SQLServerUpdates -Version 'SQL ...
0
votes
1answer
44 views

Instead of C:\SQLDBA\ServerName\Instance rather C:\SQLDBA\ServerName_Instance

I am trying to create a folder based on the servername\instance to backup up to, i want the folder to create as servername_instance. Could you please point out where i am going wrong as it creates as ...
1
vote
2answers
246 views

How to find the list of SQL Server jobs using PowerShell?

I need to create Windows PowerShell Scripts that will check and list down all SQL Jobs scheduled on a given database server. Is it possible to find out the list using PowerShell Scripts? If yes, how ...
1
vote
0answers
95 views

How to create encryption certificate using PowerShell in Windows Server 2012 R2?

I'm implementing the Always Encrypted feature in SQL Server 2016. I have tried to create the certificate using PowerShell in Windows 10 environment as per the below article. https://docs.microsoft....
0
votes
1answer
21 views

How to remove an installed AE certificate from server using PowerShell Scripts?

I have created the encryption certificate using below PowerShell script in dev. environment. Now, I need to create deployment document to configure the encryption on staging environment. $cert = New-...
1
vote
1answer
120 views

How to avoid warning with file system cache in mongodb?

OS Windows 10 x64. Version of MongoDB 3.6.5 When I'm starting mongo process, I'm always getting: MongoDB shell version v3.6.5 connecting to: mongodb://127.0.0.1:27017/ MongoDB server version: 3.6.5 ...
0
votes
1answer
121 views

How to connect via config file in mongodb

In config file I have: systemLog: destination: file logAppend: true path: c:\data\log\mongod.log storage: dbPath: c:\data\db journal: ...
0
votes
1answer
46 views

Archive backups with a PowerShell script launched by SQL Server Agent

I would like to run a Powershell script via the SQL Server Agent. This script works fine if I run it manually through the command prompt, but the job history in SQL Server Management Studio tells me a ...
0
votes
0answers
44 views

Not able to run my SQL script from my local machine using power shell INVOKESQL command

I am not able run the below stored procedure on SQL server from my command line using powershell invoke sql command(but able to run the below script directly going on to the SQL server) .please help ...
1
vote
3answers
487 views

How can I use Invoke-SqlCmd with variables to output the SQL command only or some similar method?

I have a big *.sql file that I run with Invoke-Sqlcmd and variables to do some tasks, and when I have an issue, it's a pain to debug because of the variables and I want to do logging of the SQL script ...
2
votes
1answer
354 views

I want Powershell's invoke-sqlcmd to ignore SQL execution errors

I've written a Powershell script that scripts out the appropriate SQL scripts for all databases on a server as well as creating BCP files for the contents of each. This is to allow the restoration of ...
0
votes
1answer
51 views

Copy contents of network drive to local folder [closed]

I have an automated third party backup places files on a network drive. I've mapped this drive to a local folder on the DB server using the following PowerShell script $pass ="xxxx"|ConvertTo-...
0
votes
0answers
37 views

Reinitialize transactional replication using powershell

Recently I was asked to develop a solution by management to reinitialize a transactional replication whenever it fails using powershell. The request was made because our 3rd party vendor restores our ...
5
votes
3answers
474 views

Invoke SQLCMD doesn't work when used with xp_cmdshell

I am trying to get disk space report from bunch of servers and insert them into sql table.. below is sample of what i am trying to do,Server names will be populated from a table and passed as a ...
3
votes
0answers
14 views

Invoke SQLCMD doesn't work when used with xp_cmdshell [duplicate]

I am trying to get disk space report from bunch of servers and insert them into sql table.. below is sample of what i am trying to do set @ps = 'powershell.exe -noexit -c " $computers=Get-...
2
votes
1answer
58 views

Invoke-SqlCmd - does casting as integer prevent injection

I am lazy and would rather parameterize once (to get an object_id for a name) and use Invoke-SqlCmd for the rest of the work. Given a series of functions meant to work with an arbitrary server ...
1
vote
3answers
231 views

How can the System databases in SQL Server 2016 be moved using Powershell?

I'm trying to move the system databases using Powershell ie. without using any T-SQL. Using SMO : Install-Module SQL-SMO $smo = New-SMO -ServerName localhost $smo.databases["TempDB"]....
0
votes
1answer
887 views

What causes SQL error 41106?

I get an error when I try to join the secondary replica to the Availability group thru Powershell while following the below Microsoft Documentation. Join-SqlAvailabilityGroup -Path "SQLSERVER:\SQL\&...
1
vote
1answer
148 views

Restore Latest Copy of Full and Differential database From Azure Blob Container

I'm trying to work out how to Restore the Latest Backup of a Database that is held on Azure Storage Blobs. This container contains other backups from different databases on a server but I'm only ...
0
votes
1answer
174 views

powershell command enable-alwayson not work for SQL Server Named instance

Hi all, I installed a SQL server 2016 default instance and a SQL Server 2017 named instance (instance name is SQL17) on my Windows 2012 Server. I opened a powershell windows with administrator mode, ...
2
votes
2answers
407 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
1answer
145 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 ...
2
votes
2answers
212 views

SQL Server Reporting Services: Generate Scripts Programmatically

I'm looking to export SSRS reports from SSRS 2005 into SSRS 2017. I have around 100 reports to move but in total there are around 500 subscriptions across all of these reports. The Script to file ...
-1
votes
1answer
65 views

Creating Excel Spreadsheet with Database Table information

My Goal: I'm wanting an excel document showing basic information for each table. I'd be happy with the same information shown when you Alt+F1 on the table but ideally I want a separate sheet per table....
-1
votes
2answers
41 views

What's the standard way to update a large number of arbitrary rows in MSSQL?

I have a SQL database table containing configuration for a large number of devices. I need to update the value of one of the properties (TemplateID) for about 1000 of these devices, based on a ...
0
votes
1answer
701 views

Check progress of database restore running asynchronously

I have a Powershell script that restores a database using the SqlRestoreAsync method. I have a decent size database which I'm restoring (~55Gb) and I'm trying to find the progress of the restore ...
0
votes
1answer
111 views

Postgres using powershell - how to tell how many transactions have been COMMITed

I'm adding records to a postgres database using a powershell script. How can I tell how many records are in a transaction - or to put it another way how can I tell how many INSERT statements were ...
0
votes
0answers
860 views

Powershell and Postgres – improving INSERT performance

I have a postgres database which I populate via a powershell script. I’m having trouble with the time it takes to for the script to perform an INSERT The powershell script is very simple, it reads ...
1
vote
0answers
20 views

how to update SSRS execution account automatically through power-shell?

I need to update the password for the SSRS Execution account for every 15 days. How can I automate this process using power shell or some other scripting?
2
votes
1answer
108 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 ...
2
votes
2answers
263 views

Using Powershell can you insert a macro into Access?

I am using PowerShell to automate an export of an access databse (.accdb) to postgresql. As a step of that I am using a VBA script to convert all the table and column names to lowercase so they play ...
2
votes
1answer
53 views

How to trust trust a document in access via PowerShell so I can trigger my database export marcos

Long story short I'm working on using PowerShell to automate a nightly DB conversion from access to PostgreSQL. In it's more basic form the script does the following. Copies the .accdb file to a ...