SQL Script to run from a powershell script

Roberto Madro R.
Roberto Madro R. used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer

Commented:
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.Programmer Analyst

Author

Commented:
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 TsioumprisSoftware & Systems Engineer

Commented:
Maybe if you give the SQL script and where you want to put the user input would be most helpful....
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Roberto Madro R.Programmer Analyst

Author

Commented:
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 TsioumprisSoftware & Systems Engineer

Commented:
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.Programmer Analyst

Author

Commented:
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.
Software & Systems Engineer
Commented:
Unless you mean the SID of the user where in this case you need
[wmi] "win32_userAccount.Domain=’DomainName’,Name=’TheUsersName’"

Open in new window

Roberto Madro R.Programmer Analyst

Author

Commented:
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)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial