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.
Thx
Powershell

Avatar of undefined
Last Comment
Roberto Madro R.

8/22/2022 - Mon
John Tsioumpris

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
Roberto Madro R.

ASKER
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.
John Tsioumpris

Maybe if you give the SQL script and where you want to put the user input would be most helpful....
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Roberto Madro R.

ASKER
A simple one;
UPDATE dbo.aspnet_Membership
SET
CreateDate = CURRENT_TIMESTAMP,
LastLoginDate = CURRENT_TIMESTAMP,
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)
John Tsioumpris

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....
Roberto Madro R.

ASKER
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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
John Tsioumpris

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Roberto Madro R.

ASKER
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)