Skip to content
Advertisement

Tag: powershell

sql distinct statement not working in powershel script

I am trying to run the following sql command on a powershell script: I set the following as a variable: after some other commands, i have the following: The above command works perfectly in SQL, but when I run on my powershell I get the error: Please can anyone advise? Thank you. Answer Thank you to Luuk and Astentx for

Save list of txt files through referencing array [Powershell]

I have a file that has some names (table_names.txt) whose contents are: and another file that has some entries (test.txt) whose contents include the above names, like: I need to write a for loop in powershell that creates, within my current directory three separate files: ALL_Dog.txt whose contents are “INSERT INTO ALL_Dog VALUES (1,2,3)”, ALL_Cat.txt whose contents are “INSERT INTO

SQL extract data to Excel using Powershell

I want to extract data from SQL server to a new excel file using powershell . For small data set my code works but some tables has more than 100.000 rows and this will take ages. The reason why I don’t use the utility in SQl server is because I want to extract mutilple tables. Is there a way to

How to get datasource from Connectionstring using PowerShell?

In .Net we can get the datasource from a connectionstring using below mechanism: I was trying to do that in PowerShell but getting the following exception: New-Object : Exception calling “.ctor” with “1” argument(s): “Keyword not supported: ‘metadata’.” At line:1 char:17 + $ConstringObj = New-Object System.Data.SqlClient.SqlConnectionStringBuilder($con … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

Advertisement