Link to home
Start Free TrialLog in
Avatar of Roberto Madro R.
Roberto Madro R.Flag for United States of America

asked on

SQL Script to run from a powershell script

I have a sql script that updates a table, I need to run it via a powershell script, but I need to capture a user input first, then use that user input in the sql script.

Your thoughts please.
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

It seems that Powershell can use .NET namespaces and libraries so you can use them to construct a powershell script with advanced functonality...for detailed example take a look here
For user input check the script from the Scripting Guy here
Avatar of Roberto Madro R.


John; I'm familiar with the scripting guy and the that function you pointed out, I'm more interested in seeing a place holder (or whatever it's) that can hold the input of the user while the SQL script at the backend runs and grab that value, I'm interested in seeing how those two (SQL & PS1) can work together.
Maybe if you give the SQL script and where you want to put the user input would be most helpful....
A simple one;
UPDATE dbo.aspnet_Membership
LastPasswordChangedDate = CURRENT_TIMESTAMP
WHERE UserId= '13CBD9F0-6CA9-4512-96F4-8CA4AAA538C8'

See, but to get the UserID, you have to query another table based on username, and I'm trying not to expose any of this to level 1 support guy (if you know what I mean)
So you want to query a table that retrieves the username and makes the assosiation of the username <--> userID and then insert this info on the SQL script....
Yes, so the only value the user is inputting is the "username", and if I can get that and pass it onto the sql script, I can easily do the rest.
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The UserID comes from another table in the database (not AD by any chance, this is application specific), it's looked up via UserName, and all we're doing here is prompting the jr. admin to ask the user for their Username and voila, we'll take it the rest of the way.
(users know their UserName not their UserID, that's a database thing)