Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Help with replace parameter


Help with replace parameter

Author
Message
Judy Scheinuk
Judy Scheinuk
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 461
Hi. I have a script that looks at the sysjobsteps table to find SSIS script locations and then copies them out to disk for disaster recovery. It works fine but I am making an assumption in the script that all scripts will be found on drive C. This is currently true but it could change without notice. My current script lines are like this:

$Server = 'server1'
$job ='FILE "C:\Projects\Scripting Restart.dtsx" /CHECKPOINTING OFF /REPORTING E'
$URL = $job -replace 'FILE "C:',"\\$Server\C`$" -replace 'dtsx"','dtsx'
$URL

The only method I can think of is to use a subscript like this. I haven't made it work yet but I'm sure it's possible.

$Drive = $job.Substring(6,1)
$Drive

It's getting pretty convoluted. Does anybody have a better way to handle this? I should be able to pass a masking character but I can't figure out how. Thanks in advance for any ideas you can offer.

Judy S.
Gary Varga
Gary Varga
SSCrazy Eights
SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)SSCrazy Eights (8.2K reputation)

Group: General Forum Members
Points: 8179 Visits: 6110
I would say that until the requirement to change the directory comes you cannot fully understand that requirement i.e. if you cater for all files to be located in the same but single directory albeit on a different single drive this might not hold true when the change in requirements comes (if it ever does).

I would leave the working script as is until you know what is needed.

Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
Judy Scheinuk
Judy Scheinuk
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 461
I don't think I explained my problem very well - plus I have now answered it myself. To clarify, my problem was that I have the name of a SSIS package which I have found by looking at the sysjobsteps table. I need to use Powershell copy-item to copy that package file to a remote server for disaster recovery. I was trying to use the drive letter as a variable but it turns out that is not necessary.

In other words, I need to tranform this:
FILE "C:\Projects\FakeJob.dtsx" /CHECKPOINTING OFF /REPORTING E
To this:
\\server1\C$\Projects\FakeJob.dtsx /CHECKPOINTING OFF /REPORTING E

After further research, I found that most people do these complicated replace functions in increments. Although it is probably possible to do the transformation in one giant statement, I got the results I needed with this routine:

$Server = 'server1'
$job ='FILE "C:\Projects\FakeJob.dtsx" /CHECKPOINTING OFF /REPORTING E'

$UNCPath =$job -replace (":", "$") # replace the ":" with a "$"
$UNCPath =$UNCPath -replace "File","" # get rid of the word 'File'
$UNCPath =$UNCPath -replace ' "','' # get rid of extra quotation marks and space before the file letter
$UNCPath= $UNCPath -replace 'dtsx"','dtsx' # get rid of the extra quotation marks around 'dtsx'
$UNCPath =$UNCPath.Insert(0, "\\"+ $Server + "\") # adds \\$server
$UNCPath

The script is working now and I don't have to worry that somebody will put an SSIS script in an unusual location. As long as it's set up as a job, I should now be able to find it and copy the file.
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44774 Visits: 39845
We store the SSIS stuff on the SSIS box and the entire box gets replicated to the DR site through SAN replication. Makes life real easy and the DR box is always up to date. If you have a SAN, then get the infrastructure/SAN folks involved. This could be a much simpler task than you might guess.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
     Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is usually not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search