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
Tag: powershell
How to parameterize logins when executing SQL from PowerShell command
How do we run CREATE LOGIN … against a variable string? I’m executing the following command: MasterDBSetup.sql: How do we run CREATE LOGIN … against $(SvcRRRComparisonUser) ? Answer In the $SqlVariables: Then in the SQL file:
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
Powershell how to use SQL syntax on system.data.datatable foreach variable lookup?
I am using a data table in Powershell ISE on 2 large csv files. The second file is used to lookup various facilities by ID number found in File1. So, File2 has either 1 or many facilities depending on where they go. I’m trying to do a standard foreach loop, but not sure how to populate where the number variable
SQL `SELECT ‘some string value’ AS fieldname` equivalent in Powershell?
In SQL I can go SELECT actualField, “repeat” AS bs_repeated_value FROM Table1 And I can repeat the bs_repeated_value field as many times as there are rows no matter what I name the field! Now in a …
Change Windows Firewall Settings With PowerShell But Do Not Show Output
I have a PowerShell script I am using to install SQL Express, then SQL Server Management Studio, and finally, to edit the Windows Firewall settings to allow remote connections to the database. For …
INSERT into table wherever update_time is latest
I have a table that has data about session. I want to insert hardcoded values for every new session row added at the latest time. for example, given this table with 3 session rows information added …
Read the sql files by Exclude the list of files from sql table and Execute all the files in a single Transaction using PowerShell
I have not an Expert in power shell. I Need a script/Approch which handles the below requirement. I have list of files in a folder and the file Names like below. 001_File.sql 002_File.sql 003_File….
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