I am creating a new job which has powershell job steps.
I know that in TSQL you can make use of tokens:
PRINT N'Current instance name is $(ESCAPE_SQUOTE(INST))' ;
PRINT N'Current server name is $(ESCAPE_SQUOTE(MACH))' ;
Is there a way to embed it into Powershell without running TSQL queries?
I need to be able to do something like this:
$InstanceName = $(ESCAPE_SQUOTE(INST))' ;
$ServerName = $(ESCAPE_SQUOTE(MACH))' ;
Yes, you can use SMO.
If you just type $server, you will see a list of all the properties that you can use. Note that while this specific operation takes a few seconds, it's only because it's enumerating so much info, not because SMO is slow (SMO is awesome and fast).
Some properties you may find useful:
To use SQL Authentication with SMO, you would use the following:
Please let me know if this does not answer your question. I know this is a little late, but it will be a good reference for others, even if you've already solved your problem.
Powered by IDERA