Your browser does not support our blog javascript

how to make a pipe out

search for more blogs here

 
Home - Take this blog! - Get your Author's Pass Here - Submit Comments Below

Exporting VSTS load test results to a new database with PowerShell

Posted by ~Ray @ 2007-12-09 14:14:37


express emotion readers of theJoyOfCode com ordain have seen that I'm having a bit of fun getting friendly with PowerShell of late and Colin has kindly provided me with the inspiration I needed to show the use of powershell for something a little bit more complicated than my previous and admittedely very simple examples. The label sample colin provides basically traverses a directory looking for trx files (created by VSTS load evaluate) and swaps the connection arrange value with a the encrypted version taken from the local registry. Fair game for a tiny powershell script.. and here it is:$dir = "c:\temp"$key = get-itemproperty HKCU:Software\Microsoft\VisualStudio\8.0\EnterpriseTools\QualityTools\Controller$connectionstring = $key. LoadTestResultsConnectString$re = [regex] "(<m_resultsRepositoryConnectString.*?>).*?(</m_resultsRepositoryConnectString>)"dir $dir * trx -recurse | foreach { $in = [System. IO. register]::ReadAllText($_. FullName) $out = $re. regenerate($in. "`$1" + $connectionstring + "`$2") [System. IO. File]::WriteAllText($_. FullName. $out)}And that's it. You can just C+P this whole thing into PowerShell and you're away. Let's act a look at it line-by-line to see how it works: First we just setup the name of the directory we want to scan and store it in a variable called $dir$dir = "c:\temp"Next we get the determine of the connection arrange out of the registry and store it in a variable called $connectionstring for use later$key = get-itemproperty HKCU:Software\Microsoft\VisualStudio\8.0\EnterpriseTools\QualityTools\Controller$connectionstring = $key. LoadTestResultsConnectStringNow we create a regular expression that will scan the trx files and find the appropriate area to replace. say that our regex differs from Colin's slightly because we're using regex groups (represented by parantheses).$re = [regex] "(<m_resultsRepositoryConnectString.*?>).*?(</m_resultsRepositoryConnectString>)"The next four lie of the program are effectively one lie of script but we've spread it across multiple lines to keep things more readable. The first line is a standard dir command to examine a folder ($dir) for files matching "* trx". Note that we specify -recurse here which means it will acutally examine sub-folders too. Simply remove this switch if you don't be to do this. Finally we pipe the results of our dir dominate into a foreach; I described how to use this in my previous post: dir $dir * trx -recurse | foreach {Next we construe the contents of the file into a $in variable$in = [System. IO. File]::ReadAllText($_. FullName)And then we use the regex to replace the connection string. Note how I re-match the groups using the $1 and $2 tokens in the regex strings. It took me a while to get this working because the $ symbol is a special syntax to powershell and must be escaped using the ` symbol (very top left key on most UK keyboards).$out = $re. Replace($in. "`$1" + $connectionstring + "`$2")Finally we have to write the results of our replace back into the original file. [System. IO. File]::WriteAllText($_. FullName. $out)All that remains is to close the foreach and we're done.}Sweeet. [ADVERTHERE]Related article:
http://www.thejoyofcode.com/Exporting_VSTS_load_test_results_to_a_new_database_with_PowerShell.aspx


0 Comments:


No comments have been posted yet!

From:   Website:
Subject:   Code:
Message:


   

 


 

 

 





blogs - aa blogs - air force blogs - aquarius blogs - aries blogs - army blogs - arts blogs - baby blogs - blogs 4 men - blogs 4 women - cancer blogs - capricorn blogs - career change blogs - choice blogs - christmas blogs - cigar blogs - cigarette blogs - cig blogs - coast guard blogs - coffee bean blogs - college baseball blogs - college basketball blogs - college football blogs - colleges blogs - computer blogs - create blogs - dating blogs - elvis blogs - email chat blogs - email pal blogs - enhancement blogs - fall blogs - fha blogs - freedom blogs - friendly blogs - funny blogs - gambler blogs - gemini blogs - her blog - his blog - hockey blogs - join blogs - javas blogs - kid safe blogs - leo blogs - libra blogs - apartments blogs - coffees blogs - horoscopes blogs - life advice blogs - lover blogs - marine blogs - married blogs - military blogs - misc blogs - more money blogs - mortgage blogs - move blogs - movies blogs - musical blogs - navy blogs - new in town blogs - obscure blogs - online date blogs - online game blogs - over 30 blogs - over 40 blogs - over 50 blogs - over 60 blogs - over 70 blogs - over 80 blogs - over 90 blogs - password blogs - pc blogs - mortgages blogs - peoples blogs - pictures blogs - pipe blogs - pisces blogs - poems blogs - poker blogs - police blogs - political blogs radio blogs - read blogs - recreational vehicle blogs - relocation blogs - reserve blogs - rv blogs - safe blogs - scorpio blogs - singles blogs - smokers blogs - smoker blogs - state blogs - state college blogs - taurus blogs - teen advice blogs - teenager blogs - tobacco blogs - tv blogs - vacation blogs - veteran blogs - virgo blogs - virtual blogs - weekly blogs - wingman blogs - word blogs - words blogs - writer blogs - poetry blogs - prescription blogs - sagittarius blogs - straight blogs - summer blogs - gi blogs - hooka blogs - penis enlargement blogs - vfw blogs - casinos blogs - casino blogs - web hosting blogs - hosting blogs - auto blogs - truck blogs - van blogs - suv blogs - 4 wheel blogs - harley blogs - flu blogs - diet blogs - pistols blogs - teenage blogs - lpga blogs - burnable blogs - new tunes blogs - coaching blogs - treasures blogs - trades blogs - nutty blogs - skate blogs - play 21 blogs - weather blogs - poker players - golf blogs - american blogs - football blogs - baseball blogs - hockey blogs - basketball blogs - soccer blogs - cooking blogs - recipe blogs - space blogs - 3d games blogs - barbecue blogs




blogs home