Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Necrobama
Aug 4, 2006

by the sex ghost
Forgive me, this is probably pretty basic stuff, but my experience with PS mostly boils down to "someone made this script to grab a bunch of database tables and throw them in a series of CSV files" which has served me well under the conditions that I'm using a trusted connection and not directly supplying credentials to the database server (ex loading a .bak into my local instance of SSMS and spitting out all 700 tables into CSV files).

In working on something I came across a bit of SQL script that was generating PS commands and...they included plaintext storage of the username and password of the user who was going to run the SQL and PS code because for whatever reason, these servers aren't using trusted auth.

code:
bcp "Select [##SOME_COLUMN_NAMES##] from [##DB##].[dbo].##TableName## order by k1" queryout "C:\Path\To\File.csv" -U ##Username## -P ##Password##  -S ##ServerName## -c -t','
This works fine. It works exactly as expected - but I have a problem with it because the comments of course say NOT to save your credentials when you push the to the repo but I don't like leaving it up to chance.

I've messed around a bit with what I can find through google searches, and come up with an almost ideal solution:

code:
[string]$pwd = read-host -Prompt "Password"
and

code:
bcp "Select [##SOME_COLUMN_NAMES##] from [##DB##].[dbo].##TableName## order by k1" queryout "C:\Path\To\File.csv" -U ##Username## -P $pwd  -S ##ServerName## -c -t','
work fine. It's ok - but what's making me absolutely bonkers is that I can't use -AsSecureString for $pwd because when I feed the variable into the -P argument, I get the message back that authentication has failed.

I'll admit I might be suffering from google exhaustion and this may be an incredibly easy thing to figure out for you all but...I'm at my wit's end!

Adbot
ADBOT LOVES YOU

Necrobama
Aug 4, 2006

by the sex ghost
Our product version 7 databases use Windows authentication. Our product version 8 databases use credential authentication.

:shrug:

Thanks for the tips!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply