Stack Exchange Network

Stack Exchange network consists of 175 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

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.

0
votes
1answer
22 views

powershell Write-Output format [closed]

I am finding what seems to be an inconsistency to the way a Write-Output line (which prints out a variable) should be formatted. I can't find any information on this, which makes me guess that I am ...
0
votes
0answers
10 views

Compress-Archive showing exception in Windows Server 2008 R2

Can any one help to solve this issue. Compress-Archive in PowerShell showing below exception in Windows Server 2008 R2. c:\datafolder\powershell Compress-Archive . A.zip
1
vote
1answer
44 views

Convert SQL Server results to a text file that PowerShell can access and use

The query below is used to create a text file with a list of server names. The problem I have is that the text file gets created like Server, Server, Server etc. but I need it as follows Server ...
0
votes
2answers
44 views

Looking for recommendation [closed]

I am a non IT background, my recent projects uses PowerShell for a lot of SQL Server administration. I would like to start from absolute zero, and learn to use and code the Windows PowerShell as it ...
0
votes
0answers
21 views

Test connection between application and DB using Oracle instant-client

Good morning I have on one side an 12.1.0.2 Oracle database server and on the other side an application server which is running Windows Server 2012 R2 Standard. Client connection to the database are ...
1
vote
1answer
27 views

Fail SSIS “Execute Process Task” if false is returned

I have an "Execute Process Task" that calls Powershell and checks if a folder is empty. I'm wanting the SSIS job to fail if $false is returned. Here is the code param ([string] $FolderLocation) $...
0
votes
1answer
33 views

Set service startup using DSC

Windows PowerShell Desired State Configuration (DSC) newbie here. The MOF file generation fails with: PSDesiredStateConfiguration\Node : The argument is null or empty. Provide an argument that is not ...
1
vote
0answers
20 views

Add signature to stored procedure using PowerShell SMO

I want to add a signature to a stored procedure using PowerShell SMO. The equivalent command in TSQL is: ADD SIGNATURE TO [myprocedure] BY CERTIFICATE [mycertificate] with password = 'CertificatePW' ...
0
votes
0answers
42 views

Silent install of Oracle XE 11g fails with error -3

I'm trying to install silently Oracle 11g XE in the default location (C:\oraclexe). PS D:\Profiles\xxx\Downloads\x.x\oraclexe\oraclexe-11.2.0> .\setup.exe /S /v/qn However, the command generates ...
0
votes
2answers
73 views

Create SQL login to multiple instances at once

I have a AD group that needs to be added to multiple SQL instances, I am wondering is there a quicker way of adding this group at once rather than having to login to each server and creating a login ...
1
vote
1answer
44 views

How to copy all firewall rules and apply them on a new server?

I often install new SQL Server Servers. Be them production, test or development. There is one thing I still have not automated and it is time consuming: the firewall settings. I know how to ...
0
votes
1answer
24 views

Missing data when trying to import large columns using powershell [closed]

Powershell command (whitespace added for readability): Invoke-Sqlcmd -ServerInstance "$db" -Database "$dbname" -Username "xxxx" -Password "xxx" -Query "select logmessages from log ...
2
votes
1answer
165 views

how to Enable these Windows Firewall rules using powershell?

I have a few servers where I see a blue question mark on the sql server service, as per the picture below. This is the solution: Enabling these Windows Firewall rules did the trick for me ...
0
votes
2answers
28 views

How to have SQL Server's SQL Agent pick up a new Powershell module

I have a Powershell module that I've written and uploaded to my SQL Server at C:\Program Files\WindowsPowerShell\Modules.I have a SQL Agent job with a powershell step that calls the module. This all ...
1
vote
2answers
97 views

Running Powershell Code embedded in SSIS or TSQL, not in external file

Is there a method to embed powershell code in SSIS or T-SQL, without saving the code in an external file *.ps1? We know SSIS/Tsql can run powershell, however the code always seems to be saved ...
0
votes
1answer
297 views

Powershell Run Stored Procedures in Parallel in Database

We want to run all stored procedures in parallel. The powershell script finds a list of stored procedures in the database (only have 5 right now), and runs them simultaneously. This code seems to be ...
0
votes
0answers
32 views

Deploy one object in database without Whole Publish Profile

We are using SSDT Visual Studio Database projects. I modified single table (eg added column, etc), and want to deploy new table in two Dev/QA instances. I do Not want to publish other changes in the ...
1
vote
0answers
79 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
35 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
20 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 ---------- -----...
3
votes
1answer
79 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 ...
3
votes
3answers
86 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 ...
2
votes
2answers
70 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
261 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
61 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
48 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
136 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
255 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
19 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
302 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
1answer
45 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
602 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
199 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
31 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
182 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
180 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
51 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
65 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
1k 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
497 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
62 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
45 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
709 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
15 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
69 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
443 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
2k 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
246 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
342 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
737 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 ...