tag:blogger.com,1999:blog-100745652024-02-19T10:07:01.339+00:00cornasdf's fieldpersonal and technical musings. published as often as my real life allows.cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.comBlogger97125tag:blogger.com,1999:blog-10074565.post-43624957745686144292016-11-22T20:50:00.000+00:002016-11-22T20:50:10.919+00:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1gAvlcYAa5ucFhu8giWC-DmuW0wJts3THBzhDfUIjk43CNfrZuusVnOca3ntnA-S0mECet8Hd8ZCOsZXjg-SWlRGTl0oWlQLFhIUiNIxG7Bvf7jiIW_eTtlsrbwBLSZZ-6Um5rg/s1600/20161119_082956.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1gAvlcYAa5ucFhu8giWC-DmuW0wJts3THBzhDfUIjk43CNfrZuusVnOca3ntnA-S0mECet8Hd8ZCOsZXjg-SWlRGTl0oWlQLFhIUiNIxG7Bvf7jiIW_eTtlsrbwBLSZZ-6Um5rg/s320/20161119_082956.jpg" width="240" /></a></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Up around 8am, excited to explore Delhi but a little trepidation was settling in as well. Went to the breakfast at the
buffet. Still not sure how careful I
need to be here in India nor here in the Taj.
I skipped the exotic cut up fruit.
I also skipped the continental and English breakfast options. Had another plate of tasty things. Idli sambar and several other items. An Aloo (potato) paratha was made to
order. I also got my first taste of
local chai. It was fine, not sweetened
though, which I did expect. I had heard
that this was for the westerners but my driver later told me there is a problem
with diabetes developing in the population and there is a movement to remove
sweets where possible.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Explored the hotel a bit, there is a pool but it looks
unused. Some nice grounds, beautiful
lobby, store with various gorgeous arts and crafts. The ATM was working this morning though it would only dispense a single 2000 rupee bill. I changed some money at the front desk, they
would only change one 2000 into 100s. </span></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Back up stairs to get ready to go. I packed my squared westerner travel kit of
antiseptic wipes, wound care, pepto and immodium into an old travel bag. My neighbor had recommended some mosquito spray
that was 95% deet. It didn’t smell
nearly as bad as I thought as I dosed myself.
Grabbed a bottle of water and headed out to explore.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Still unsure where to go and feeling a little daunted by
exploring on my own this morning. My
original plan was to walk from the Taj to the India gate (about a mile). I had heard stories of being mobbed by beggars the
second you stepped out of your hotel though and wasn’t sure how I would cope so
I am having second thoughts on that idea.
I was originally going to skip Connaught place as I thought it would be
that same metropolitan square that you can find from Seattle to New York to
London to Amsterdam to St. Petersburg.
This morning, that seems like a good way to dip my toe into Delhi. All the locals seemed shocked that I wasn’t
hiring a taxi to take me around for the day.
I didn’t want to do that as I thought I would want to walk and wander
and wasn’t sure how I would get the guy to pick me up at the end of my wanders. Uber seemed like a better idea, I could call
them from wherever I was. Also, all
payment is done on the card so I didn’t have to worry about currency. That said, I did have to wonder if the locals knew something i didn't.</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Uber was only a few minutes away. I got into the very basic, Tata car and we
were on our way. Taking the car out from
the Taj, we drove through the park that runs from the India Gate to the
parliament buildings. I was glad I
didn’t walk. 10am on a Saturday, there
were only (what seemed like) indigent or homeless people on the street and in
the parks. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Connaught Place is not what I expected. It was not nearly as metropolitan as I had in
my head. It is still very much
India. Crowded and dirty and
chaotic. There were a few recognizable
stores, I did see a Starbucks but it wasn’t the shopping mall I had
expected. Still not entirely
comfortable, I wandered one way and stumbled into a bit of a homeless camp so
turned back. Heading the other way, I
saw several hundred people queuing for the bank. Behind them was the metro line so I decided tackling the public transport would be my next step.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Heading down into the metro, I still wasn’t travelling well. Having gone through 90s style airport
security to get into the metro, I wanted to buy a 24 hour travel card. The guy at the first window said something
harsh and gesticulated toward the other side of the hall. I headed over there and tried the other
window. The card cost 150 rupees. I tried to pay with my 2000 rupee note and he
was having none of it. I tried to pay
with my card but couldn’t get the machine to work. First it was not taking the numbers and then
I mistook which card I was using and gave the wrong pin. He got mad at me as a queue started to build
up, ‘Why so fast on the numbers!?’. As
the machine noted ‘last chance pin’ I decided to cut my losses and dug 200
rupees out of my pocket. Hehe, that
didn’t go very well.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Subway was fine. I
was on the yellow line so decided to head down to Dilli Haat. I came down the escalator just as the train
pulled up. I got into the queue behind
some lady and waited as people poured out of the train. It was crowded but not overwhelmingly
so. I was filing into the car when I
heard an, ‘Excuse me’. When I turned a
young women noted, ‘Sir, this is the ladies carriage’. Doh!, ‘Sorry, thank you’ and barely stopped
myself from reaching out to touch her arm in thanks. Dammit Beavis, pay attention.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">The next train was just a few minutes later, got onto the
correct carriage this time. It was more
crowded here but still not terrible. I
realized I hadn’t seen anybody I could distinguish as being non-Indian since I
left the Taj. No white, far eastern or
black people as far as the eye could see.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">One nice thing about travelling by metro, especially one
with armed guards at the entrance, is that I could explore out from there and
know a way back to a safe place. I came
out at Dilli Haat station. Well, that
wasn’t so simple either. After holding
my card to the reader, it wouldn’t let me out.
I tried another reader, still no dice.
I was about to go looking for help when I realized I was trying to get
out w/ my hotel card. FFS dude, get your
sh*t together.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhk6jzK3bu_5mdAmyhJdU6bEN7r54M4zXqiElIwoJ0g3AwVODTwI_qqCmAMdxDq7f8YNmQWKphB4PVGfaWl4t_5UT3Fuqp74rn0m_8Z9_yY4PMNGGl7B57ZpIVUBgBJzWoXnwJfVw/s1600/20161119_110847.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhk6jzK3bu_5mdAmyhJdU6bEN7r54M4zXqiElIwoJ0g3AwVODTwI_qqCmAMdxDq7f8YNmQWKphB4PVGfaWl4t_5UT3Fuqp74rn0m_8Z9_yY4PMNGGl7B57ZpIVUBgBJzWoXnwJfVw/s320/20161119_110847.jpg" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">After a quick wander, I found my way to the market. Sign on the wall says 100rupees for
foreigners. I paid up and got a ticket
that says it cost 60 rupees, more of that loose relationship with numbers. As I wandered inside, it was still mostly
closed. Several shops were open or
opening but no shoppers yet. I wandered
through, easily ignoring several of merchant’s calls. I understand Dilli Haat is an artist’s market
where most of the stalls rotate every 15 days.
There were some beautiful scarves, probably 75% of the market was
selling pashmina scarves. Not sure of
the value and know that they know that I wouldn’t know the value. I heard there is a state
shop w/ no haggling, I will probably hit that later.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">The pollution is omnipresent. There is a haze over everything and I can
taste it on my lips. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">At the back of the market were a few food sellers. I thought to stop for a drink. Looking behind the boy at the counter, the thing in bottles was Coke. So, like an American
commercial, I settled down in to watch the market open w/ a Coke in hand. It was actually a nice chance to gather myself and turned out to be turning point in the day.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Now, I realize that my trepidation and missteps above
probably sound pretty negative. I don’t
really mean it to. Somehow, most of the
things I can articulate about India sound negative. But as I went through the rest of the day, I
started to find how they come together to something wonderful.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">After a quick rest to gather myself, I started back out of
the market. I saw more evidence of the
lack of theft here. Several of the
stalls were still closed. It looked to
me, like their wares were still in the shops, protected only by a plastic
tarp. It would seem it was that way all
night. I also saw the first of many
public water fountains. There seems to
be a lot of free, public water. Now, I
am not ready to drink it, but I am impressed at how available it is.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Heading out of the market, I saw my first white guy! Some obvious tourist, I would guess German,
taking photos w/ a telephoto lens. I
ended up not making contact but it made me wonder if I should stop by a hostel
and pick up some travel companions.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaGmLkxQvc-tCDKMLAnOZYk5uUpH6buG69ZYTV_7f-_648gJpV1NOBo4wN_Hllc8nGd2ibDuvelyo7TBuHDfKyHye_i1ppqx0VI9G5XoJgvFu9wZP3DLyfmncRPu7VVrvDaBwozA/s1600/20161119_122822.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaGmLkxQvc-tCDKMLAnOZYk5uUpH6buG69ZYTV_7f-_648gJpV1NOBo4wN_Hllc8nGd2ibDuvelyo7TBuHDfKyHye_i1ppqx0VI9G5XoJgvFu9wZP3DLyfmncRPu7VVrvDaBwozA/s320/20161119_122822.jpg" width="240" /></a></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Feeling a bit more comfortable, I decided that the refuge of
the metro gave me the courage to try Chandni Chowk. This was supposed to be a super chaotic
market near the Red Fort and a spice market.
I thought both or either may be worth seeing. There were two ways out of the metro, one
down a covered corridor, where most people were going, and one through a
park. I took the path less travelled (a
relative thing, here) and headed out towards the park. It was nearly noon by now and I saw a curious
mix of homeless sleeping in the park and families with children picnicking and
playing. There were huge piles of
garbage around garbage bins and some guy jumping up and down on top of an
already very full wagon of garbage, try to compact it further. When the park and the corridor diverged, I
decide to jump back in with the people, presuming we were all going to more or
less the same place. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Stopping to try to get a picture of some impressive temple,
I saw two women trying to look something up on a map. They were accosted by people trying to help
them find something and quickly packed it up.
When they passed, I asked them if they were looking up the Red
Fort. Turns out they were so we hooked
up and I found my travel companions for the day. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbBJDLWDUkyFO0uaIiG-Qte-KGWtCJfklkgOl6JMvpoxYzNWMPHs3ZqAj3B_8qJcmzf5Y0TJL6J3KvqcB1R08j_Nk7kFPyEYROKwCukS4Xxj25g9a_pz8wM_XjFZ2ZJZUMxrfCwg/s1600/20161119_122249.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbBJDLWDUkyFO0uaIiG-Qte-KGWtCJfklkgOl6JMvpoxYzNWMPHs3ZqAj3B_8qJcmzf5Y0TJL6J3KvqcB1R08j_Nk7kFPyEYROKwCukS4Xxj25g9a_pz8wM_XjFZ2ZJZUMxrfCwg/s320/20161119_122249.jpg" width="240" /></a><span style="font-family: Arial, Helvetica, sans-serif;">Sheena, an international school teacher from Ireland,
teaching in Kuala Lumpur and (… gawd, I am bad with names, we’ll go with)
Carol, an international school teacher from Minnesota, teaching in Thailand,
had met teaching in Korea and were in town for a friend’s wedding. They were happy to have a guy w/ them and I
was happy to have a second (and third) pair of eyes with me. We had more or less the same goal of
wandering and looking at interesting things.
We thought we were wandering towards the Red Fort as we made our way
through the traffic and crowds. The bike
taxis were very insistent here. After
one guy followed us for some time offering a ride for 10 rupees each, I finally
told him that “the last guy offered a better deal and we didn’t take that one
either”. That seemed really effective
and he disappeared. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Looking to my right at an impressive statue of Gandi and
large building which turns out to be Town Hall. I didn’t realize I was approaching some sort of event. There was a table on the sidewalk with
several people sitting on one side facing the street. On the street maybe 100 people had gathered
to listen to what these guys and ladies were saying. They had loud speakers set up and a big
banner behind them with the </span><span style="font-family: Arial, Helvetica, sans-serif;">Town Hall </span><span style="font-family: Arial, Helvetica, sans-serif;">as their back drop. That was all fine. The strange thing was that, as it was on the
street, some set of sidewalk traffic just walked right behind them while they
yelled into the microphone. I think it
was a political demonstration or debate as the speaker seemed angry and
animated. I hope they aren’t saying, ‘Let’s
lynch the next white guy that walks by”.
B)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">We realized we weren’t on the path towards Red Fort, that
seemed to be a train station that we were heading to. So, change of plan, from here we started to head
towards </span><span style="font-family: Arial, Helvetica, sans-serif;">Gadodia </span><span style="font-family: Arial, Helvetica, sans-serif;">markets. This was a fascinating area and
all I thought Delhi would be. It was a
chaotic warren of sights, smells and sounds.
A wonderful assault on the senses.
Writing my notes later, I realized I wasn’t sure of the order of several
of these impressions, it was all a jumble of sensation.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoW_4n5WljU7sdG8Z4ouQjlc3crLqeCl4QLzFnisFbiWhIlekAeCZok60aLafo7CCDnDNFexMSx1qs2TmRnaLJ9jYC1VrnW9R3ar6Xiyb0QuMi83_o2qS_JhHmTVmBEqVQjmcHmw/s1600/20161119_122841.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoW_4n5WljU7sdG8Z4ouQjlc3crLqeCl4QLzFnisFbiWhIlekAeCZok60aLafo7CCDnDNFexMSx1qs2TmRnaLJ9jYC1VrnW9R3ar6Xiyb0QuMi83_o2qS_JhHmTVmBEqVQjmcHmw/s320/20161119_122841.jpg" width="240" /></a></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">The spice market itself was the most intense as the spices
permeated the air. Everybody, not just the
tourists, was coughing their way through the alleys full of spices, nuts and
pulses. Colorful bags of Tumeric, chili,
coriander, mango, pepper and others lined the streets. I almost bought a bag of spice for about $2
when I realized that 500g of turmeric would last more than a lifetime.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">I should have bought when I first saw things. I regret not purchasing black and pink salt
crystals that were bigger than golf balls.
I assumed I would see them again later in the market but never did. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">There were several cows around the streets and market,
including some that were decorated in what I took to be ceremonial markings. Ducking down one particularly grimy side
warren, we found, as Sheena put it, “a very handsome goat” and a fresh grocer
market with piles and piles of potatoes and various greens.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4J5ro9QqIHhIENj0sQxjY8ki0nTUB-qZz7iqw_xNZ-Zm_9Xu1eiZ4lZYi7j2KmYSrF6bNY2NhyphenhyphenpsOQzew5ZijMRZxtz5mNRIskl2KbDwRhN8CPQTYgzgmmZUHe_3aDT8k4RFFQw/s1600/20161119_123907.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4J5ro9QqIHhIENj0sQxjY8ki0nTUB-qZz7iqw_xNZ-Zm_9Xu1eiZ4lZYi7j2KmYSrF6bNY2NhyphenhyphenpsOQzew5ZijMRZxtz5mNRIskl2KbDwRhN8CPQTYgzgmmZUHe_3aDT8k4RFFQw/s320/20161119_123907.jpg" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">There were several of these warrens, narrow alleys that led
away from the road into mazes of varied goods.
We wandered through a couple fabric warrens. Down the narrow paths were dogs and scooters
and workers carrying lumber on their shoulders and huge bundles of fabric on heads,
all capped by a tangle of spliced and respliced electric lines overhead. Down one of these alleys, I saw a male kurta. This is the male dress for formal occasions. Since I am going to a wedding later in the
trip, I decided to reach out to one of my coworkers here to see if I should get
one. She came back a bit later with an
affirmative but I had wandered on by this point. I kept my eye out for the next couple days
but nobody else seemed to sell male ones.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoIMtii6iPMl1WFws_-MkVG9mCo3s6KEBOqkVRJlkJ-vwy4fX91QhZpwBKt4oL6unT4aGmwndX0rbS1Tq8pZHwqxSc9KNo5voJ2MshicAlaFkIoNen0LAxgXS8VuMNC6PXHH5tgw/s1600/20161119_125402.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoIMtii6iPMl1WFws_-MkVG9mCo3s6KEBOqkVRJlkJ-vwy4fX91QhZpwBKt4oL6unT4aGmwndX0rbS1Tq8pZHwqxSc9KNo5voJ2MshicAlaFkIoNen0LAxgXS8VuMNC6PXHH5tgw/s320/20161119_125402.jpg" width="240" /></a></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Through all of this, there were small doorways. Looking through you could see various temples
that stood as <span style="background-color: white;"><span style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;">oases</span> </span>of calm, set apart from the chaos. To
enter you had to remove your shoes. I
was in hiking boots and that seemed like too much of a fee for me. The girls tried to go in but one was wearing
shorts so she was denied as a floozy.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">We got to an intersection in Gadodia market and decided to head down Lalkuan Bazar Road, heading towards the metro. This road is
a bizarre road in that they are selling every manner of thing. It also seems to be a busy road as dogs, bikes,
scooters, cars trucks, tuktuks, children and ourselves all wove our way
together and in opposite directions to form a strangely effective pattern in
the cacophony of varied purpose. </span></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">We
passed more spice, food and fabric shops but also a district of shops that were
kitchen supply, espresso makers and mixers and other industrial kitchen goods. Then we came into the home depot section where
there were latches and tools and lumber.
Interspersed were mini factories doing some sort of water cooled metal
cutting or shaping. Striking was the small
children one pair couldn’t have been more than 5 and 3 years old. Weaving through the bikes and cars with the
rest of us. This was a hugely stimulating
area and exactly what I wanted from Delhi.
<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIgrpyuZrohEEBr1SDTZNZEhdzK4jnCVfSlscr0W9hw9MQv0qdqd8mDGxXDPxtD9EU5XDhee-CU89QUXxtL1jJu1VKevMTbct0mZC_Pph8iHITgdOHUJax_YieeCn_NoUuvGwkCQ/s1600/20161119_131030.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIgrpyuZrohEEBr1SDTZNZEhdzK4jnCVfSlscr0W9hw9MQv0qdqd8mDGxXDPxtD9EU5XDhee-CU89QUXxtL1jJu1VKevMTbct0mZC_Pph8iHITgdOHUJax_YieeCn_NoUuvGwkCQ/s320/20161119_131030.jpg" style="cursor: move;" width="320" /></a><span style="font-family: Arial, Helvetica, sans-serif;">We finally made it to the metro station and decided to try
to find the state market I had heard of. We picked a stop a few blocks away and decided
we would walk towards it. As we headed
down the street we saw another huge queue in front of a bank. These are common enough now not to
mention. This one though, started to
look like a riot was going to form. They
were chanting and started waving their fists.
We decided it was probably best to wander on rather than watch this
develop.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Our path towards the markets took us by a beautiful mosque Gurudwara Bangla Sahib. Not on our radar but so impressive we had to wander around it for a while. Lots of marble and great inlay work. This was also a no shoes area, complete with
a ‘shoe check’ area where you could leave your shoes.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9fxG1R5bub8YEPHXVfzrTGKuOqwNaQAt6lA3sd7N85asDtfIKneM_oNghZS-CMmo71bfLbI_9CtVAANpNy9St09sMbIPJ5Jo1VpVoqp4ZsNLsF2vuZwxeeX-VIu5xZrb5YjWaKw/s1600/20161119_141033.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9fxG1R5bub8YEPHXVfzrTGKuOqwNaQAt6lA3sd7N85asDtfIKneM_oNghZS-CMmo71bfLbI_9CtVAANpNy9St09sMbIPJ5Jo1VpVoqp4ZsNLsF2vuZwxeeX-VIu5xZrb5YjWaKw/s320/20161119_141033.jpg" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">We couldn’t find the shops but a quick consultation with
google later found that they were a bit further down the direction we were
going and we quickly found them. The
idea here was each state in India had a government run store in a mall/market that
had fixed prices. Since I had no idea
what something was worth, that seemed like a fair deal to me. And overall it was. I am sure we overpaid but probably not much
more than I would have trying to bargain w/ no idea of guideline costs. If I had more time, I would suggest going to
the market to get an idea and then trying your luck in the more varied markets.
After some shopping and a cafeteria
lunch (that was still excellent) it was time to say goodbye to my travel
companions as we went our separate ways.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">As I wandered a bit past the market, looking for a
reasonable place to call an uber, I realized that I was in Connaught Place, at exactly
the area I had turned back from earlier in the day as I thought I was entering
a homeless encampment. Now I am
wandering through the same area, laden with shopping bags, an obvious
mark. But I wasn’t really concerned. I
guess I learned a bit more about the city and where I could fit and how to
manage the city. I juggled my bags as I
dodged traffic looking around for my uber.
It took a while as the guy had gotten out of his car and was wandering
around looking for me, while I wandered looking for his car. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRzvXSsFyOM-UPcmK0jsK4cTKg5VPiskGj4QCE_KhyRR8N_GVlpfjATIA_aUNjMIdEd2yr4cuSmJolLKLUFpvJIjW4_soEDoD3Ps3bVaCnqWFMSN4XgPwA0HGlz0GoaMG6KtbT8g/s1600/20161119_210523.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRzvXSsFyOM-UPcmK0jsK4cTKg5VPiskGj4QCE_KhyRR8N_GVlpfjATIA_aUNjMIdEd2yr4cuSmJolLKLUFpvJIjW4_soEDoD3Ps3bVaCnqWFMSN4XgPwA0HGlz0GoaMG6KtbT8g/s320/20161119_210523.jpg" width="320" /></a><span style="font-family: Arial, Helvetica, sans-serif;">I arrived back at my hotel room and realized I was still
just buzzing with excitement. What a
day! It took several hours to calm down.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">I wandered the hotel a bit to see what they had for offer
and was suggested, by the nice lady who kicked me out of an upstairs members
lounge, that Varq was a good place to eat.
This is an upscale modern Indian restaurant. The dishes were beautifully presented and
absolutely delicious. Another great
treat on an excellent travel day.<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com2tag:blogger.com,1999:blog-10074565.post-74167757724747445832016-11-21T09:12:00.000+00:002016-11-21T09:12:19.823+00:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx40p79s_Ma70ihL6Eoy6v6NFq2143XVp2wyJyDgtb-vRzTn6W8MiNgpkmD2wjRAlxFL5srSgOQ8ezUSexOJpgdph9iUnaDlUx-jy-F4HAFYhvJMR6MIK_bJDDX8R9hGAU7j1_xw/s1600/20161118_075521.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx40p79s_Ma70ihL6Eoy6v6NFq2143XVp2wyJyDgtb-vRzTn6W8MiNgpkmD2wjRAlxFL5srSgOQ8ezUSexOJpgdph9iUnaDlUx-jy-F4HAFYhvJMR6MIK_bJDDX8R9hGAU7j1_xw/s320/20161118_075521.jpg" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">It has been a long time since I wrote a blog post but an
adventure to India seems like a good reason to start again.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">I flew direct from London Heathrow to New Delhi. This left from Heathrow Terminal 4 which was a
bit light on food options at 7am on a Friday. </span><span style="font-family: Arial, Helvetica, sans-serif;">I checked in at the Air India lounge.</span><span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">I don’t often fly business class and was
thinking there may be a nice, premium lounge but it was actually quite
basic.</span><span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">Just a counter with some small
bits of food, 4 or 5 bottles of booze as a bar and a few types of juice sitting on a second counter.</span><span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">The BA and even the United/Delta basic lounges
are much nicer.</span><span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">That said, there as a
good ball of something Indian that I ate there. </span><span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">My knowledge of Indian food names is terrible.</span><span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">Spoiler alert: This entire trip is me eating
tasty Indian things that I don’t know what they are called.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">I headed out of the Air India lounge in search of a
reasonable breakfast. I walked the
length of the terminal and found a Lebanese place. A strange start to my Indian adventure but a nice
breakfast. Sadly, health isn't great at
home. Now my elder boy is also sick. Tough week for me to be away.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Air India Business class was also not as luxurious as I
hoped. I settled in on the stained,
spotted seats as the stewardess walked around spraying what I took to be Indian
Febreeze on the unoccupied seats. A chemically
‘fresh’ sent permeated the air for a few minutes. It either faded or I started filtering it out. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">The entertainment options were disappointing. The screen was nice and large but there was a
strange collection of movies. It would
have seemed fine 10 years ago but given the options on other carriers, it was
very sparse. Maybe a dozen ‘recentish’
releases and another two-dozen random ‘classic’ movies (from Breakfast at
Tiffany’s to Rebel Without a Cause to A-Team to Avatar).<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">The food was actually excellent. No idea what it was, but very tasty Indian
food. I have been going vegetarian for
this trip. It is easy in India as the
veg options are plentiful and filling.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">The flight was otherwise uneventful. Landed at Delhi a bit late around 22:45. It looked like the airport was mostly
shutting down. There were more staff
than passengers as I walked through the terminal. It seems like they had at least two people to
do every job that needed doing, and sometimes 5 or 6. I guess this is an oversupply of labor? Maybe they need more management
oversight. I assume they were being paid
but far more were sitting and hanging out than actually working.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">As I came to the baggage area, I saw a currency exchange
spot with (what looked to my naïve eyes like) a huge queue. There were two lines, probably 20 people ahead
of me in my line. I decided to jump in one of them before the rest of my
plane got here. I wasn’t sure how long
my bags would take but I was guessing it wouldn’t be too quick.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr3jperN1XGdg4q8IH6AGb7ThwoFce400l1HusyUTeVl24wYm2Ptb1nG3TVzMfjxzvhhOvaCm24iVgOJgKtHppikjH7oi1XskulZlQEkmuWSyF-np4zYMdJb4LXyJQr2n7KaLRaA/s1600/20161118_232116.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr3jperN1XGdg4q8IH6AGb7ThwoFce400l1HusyUTeVl24wYm2Ptb1nG3TVzMfjxzvhhOvaCm24iVgOJgKtHppikjH7oi1XskulZlQEkmuWSyF-np4zYMdJb4LXyJQr2n7KaLRaA/s320/20161118_232116.jpg" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">There is a major currency crisis going on in India. At the beginning of November, the government
announced that as of the end of the year, they would no longer accept 500 or
1000 rupee notes. According to one of
the guys in the currency line, 86% of the money in circulation was in these
notes. Not sure whether that is in value
or volume. The stated (and possible
real) reason for this is to get the ‘dark money’ into circulation. Several people have noted that there is a
largely cash economy with people living outside of the tax system. People would also stock money ‘in the
mattress’ in these bills. I would guess
getting the money out of people’s mattresses and into the banking system (for
the banks to leverage) must be at least as important as the taxes. The move makes sense but it is causing a lot
of pain right now. Apparently, you can
only exchange 4000INR per day (you can deposit the rest in your bank account,
if you have or create one). From the
ATMs, you can only withdraw 2000 INR / day (or possibly per week, I heard conflicting
reports). One problem there is that the
new 2000 INR notes are a different size and not all ATMs can manage them. A second problem is that the ATMs that can
manage the notes only spits out a single 2000 rupee note. If you try to buy something less than about
1500 rupee, most sellers will refuse because they don’t have the change. Even at the Taj Mahal Hotel, the ATM would
only give 2000 rupees and it was empty when I got there. They had refilled it the next day. The front desk was willing to break it but
only a single 2000 note into 100s, they weren’t able to get enough change
either.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">It is driving a move away from cash, to either plastic or
other payment styles. I saw PayTM
accepted in some unlikely looking spots which seems to be a point to point payment system on your smartphone.
It is also driving the adoption of Uber and a local version Ola, which
allows you to pay electronically. This
is fine for some section of the population but I understand that a large group
of the people are operating by cash. So
if you are a small business, you aren’t able to pay your employees. They aren’t able to buy food, etc. It looks to be mass chaos. While wandering around over the next few
days, every time I saw a huge queue, it was for a bank or ATM. I saw riot chants start at one bank and a
physical fight with policemen at another bank.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Anyway, back to my line at the airport. The line was moving really slowly. As 5 mins became 30, I started to worry about
my bag on the carousel, but I was too far in to abandon my spot in line. It became apparent that they were only
exchanging 100$ per passport and that they had to take all the passport details
down for each transaction. It was also slow as each person in
line had a bit of an argument about how much would be accepted and how long the
wait was or something else. Eventually,
when I was about 3 people back, they announced a 30 minute break. I had assumed the break would be a bathroom
break or similar but instead, they went into their drawer, dumped all the
exchanged currency onto a chair and started sorting and counting it. Myself and one guy in line, who turned out to
be a banking consultant had several suggestions for improvements on this
process, we should write Thomas Cook.
Counting took a long time, so we started to get to know each other in
line. The lady behind me was in India on
a buying trip for her small clothing business.
She was from Australia, heading to Jaipur. The trip was as much for the business of
buying items and keeping relationships with distributors as it was content for
her social media presence! She has to
constantly feed the social media stream to keep her brand presence. She kindly agreed to watch my bags while I
sprinted over to the carousel and got it just as they started loading the
abandoned bags onto a cart.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">The 30 minute break became 60 mins as the pile of counted
and sorted money grew. There was
seriously a lot of cash there. They
piled it up on the counter. Casually
within reach of the public. There seems
to be very little theft here. The
clothing lady had a friend in one of the other queues and she noted there were
35 people in front of her so we thought it best to wait it out. Eventually, we got going again. I had GBP so I could only exchange 60 GBP
which was around 4780INR. I would think
the 100 dollars is much closer to 80GBP right now but there was little point in
arguing. That got ‘service charged’ to 4500,
mostly because I think it was simpler to count. I am starting to see a loose connection to
numbers here. 30 becomes 60, 100 become
60, 4700 becomes 4500. Later I would see
that, although some registers calculate the cents on the rupee, they are
rounded up, nobody bothers with anything less than a rupee. It is often rounded to 10, 50 or 100 as well.<o:p></o:p></span></div>
<div class="MsoNormal">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEge1UuACSCozCy-VaMbjXmDXP_IExylJweRfyrs7jcWeKfp3dYHO1BKlzf1JcRXEYG3ohEKAZ1Gad43F3EHDaprwWKt6B-Mq_G0WFACVWJi7iMwCqvufRNu6I53Q-TlB5gDUNQtKQ/s1600/20161119_095808.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEge1UuACSCozCy-VaMbjXmDXP_IExylJweRfyrs7jcWeKfp3dYHO1BKlzf1JcRXEYG3ohEKAZ1Gad43F3EHDaprwWKt6B-Mq_G0WFACVWJi7iMwCqvufRNu6I53Q-TlB5gDUNQtKQ/s320/20161119_095808.jpg" width="240" /></a><o:p><span style="font-family: Arial, Helvetica, sans-serif;"> </span></o:p></div>
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">Finally found my poor driver. I don’t think his English is strong. I noted it was the currency issue and he
seemed to get that. As we got going I
could smell and see the haze of pollution in and around the city. Exploring the next day, I could taste it on my
lips.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<span style="font-family: Arial, Helvetica, sans-serif;">The Taj was beautiful, of course. Service was impeccable as I settled in. Definitely not India prices. They wanted 20GBP for a nightcap. I’ll find another way to wind down,
thanks. Managed to get to sleep around
3am, off to explore tomorrow!</span><o:p></o:p></div>
</div>
cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0New Delhi, Delhi, India28.6139391 77.20902120000005228.3907261 76.886297700000057 28.8371521 77.531744700000047tag:blogger.com,1999:blog-10074565.post-24617618536252840462015-01-29T11:20:00.002+00:002015-01-29T11:22:03.817+00:00Powershell to gather ILO Version and Firmware details<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
Here is a quick, useful snippet around using powershell to
query ILO version and firmware.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Create a list of ilo names or IPs, one server per
line. Below notated as iloservers.txt<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This powershell will interrogate version for each ilo
instance. An interesting sidenote here is that you can get some
interesting information from ILO w/ no authentication (really? In 2015
this is still the case? wtf.)<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$ilo</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">New-Object</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">System.Xml.XmlDocument</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">foreach</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$server</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">in</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">Get-Content</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> .\</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">iloservers.txt</span><span style="font-family: 'Courier New'; font-size: 10pt;">) ){<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$ilo</span><span style="font-family: 'Courier New'; font-size: 10pt;">.Load(</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"<a href="http://%24server/xmldata?item=All">http://$Server/xmldata?item=All</a>"</span><span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"$server :
$($ilo.RIMP.MP.PN) - $($ilo.RIMP.MP.FWRI)"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com2tag:blogger.com,1999:blog-10074565.post-39789810527081749832012-10-15T14:04:00.000+00:002012-10-16T02:31:24.949+00:00DD-wrt, openvpn and selectively routing for multiple tunnels<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">So, as an
expat living abroad, I have times when I want to have my traffic appearing as
though I am from the US. Most recently, <a href="http://www.newegg.com/">Newegg</a>
rejected some purchases I made b/c I am coming from an IP abroad. <a href="http://www.dd-wrt.com/site/index">Dd-wrt</a> has the facility to use an <a href="http://openvpn.net/index.php/open-source.html">openvpn</a> client but I
don’t really want to send all my traffic overseas just for the few instances I
need to redirect my traffic. <o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">As an
American living in the UK, most things are pretty similar but one thing that
grates on me is the ‘big brother’ government. Recently, the gov’t tried to push
through a <a href="http://www.bbc.co.uk/news/uk-politics-19354126">snooping
bill</a> that would track all internet use. Australia has a similar one <a href="http://www.news.com.au/technology/govt-defends-need-to-keep-internet-data/story-e6frfro0-1226424390925">in
the works</a>. <o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">Now, I am
pretty boring but, in principle, I completely disagree with this. So in order
to add more encrypted static to the world, I am also planning to route all of
my non time critical internet traffic out a local UK vpn. <o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">In some
things, like RDP, latency really matters, so I will route those out my local
ISP. <o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">Mostly
though, this is a just b/c I wanted to see if I could do it. B) <o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">Below are
some proof of concept steps that I hope will help someone else get up and
running. This should work w/ any number of VPNs (or other interfaces) and w/
any linux w/ the right routing in the kernel. (it was there in dd-wrt so I
didn't go too much into it, I saw some mention on several of the pages I used
that you need certain kernel options). <o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">I got some
help on the <a href="http://www.dd-wrt.com/phpBB2/viewtopic.php?p=715419#715419">forums</a>,
and <a href="http://lartc.org/howto/lartc.rpdb.html">these</a> <a href="http://lartc.org/howto/lartc.netfilter.html">three</a> <a href="http://www.linuxhorizon.ro/iproute2.html">pages</a> really brought it all
together for me. <o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">To start,
I have a Netgear WNR3500v2/U/L. Based on the <a href="http://www.dd-wrt.com/phpBB2/viewtopic.php?t=51486">peacock thread</a>, I
put in DD-WRT v24-sp2 (08/12/10) mega - build 14929. This has the necessary
routing options compiled into the linux kernel to do what I need. <o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">The basic
idea is this: <o:p></o:p></span><br />
<ol start="1" type="1">
<li class="MsoNormal">Bring up two VPN tunnels, one to the UK and one to US<o:p></o:p></li>
<li class="MsoNormal">Create routing tables to send traffic in that table out
the specific gateway<o:p></o:p></li>
<li class="MsoNormal">Us iptables to mark packets for specific tables/routing<o:p></o:p></li>
</ol>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">I am going
to do this through a start up script. Getting all of this set up required me to
get the ssh daemon running and I recommend the same if you try to do this. You
can do this in DD-WRT under Services –> Services –> Secure Shell. <o:p></o:p></span><br />
<br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">Once that
is set you can ssh to your dd-wrt box. Login with root and your password you
use to get into the web console.<o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">For a vpn
provider, I am using <a href="https://www.privateinternetaccess.com/">Private
Internet Access</a>. Anybody that gives you an OpenVPN client and allows
multiple connections should be fine but you may need to tweak your openVPN.conf
files.<o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">The script
(in several parts):<o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">First,
since we are not configuring the openvpn client through the GUI (I leave
Services –> VPN –> OpenVPN client disabled), we need to create our own config
files. <o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">Begin by
creating the directory to hold your configuration:<o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">
</span><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">mkdir</span><span style="font-family: 'Courier New'; font-size: 10pt;"> /tmp/openvpncl</span><span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><o:p></o:p></span><br />
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">Create a
file w/ the cert for your vpn provider:<o:p></o:p></span><br />
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"-----BEGIN
CERTIFICATE-----<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">--snip--<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">-----END
CERTIFICATE-----<o:p></o:p></span></div>
<div style="margin-left: .5in;">
<span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >> /tmp/openvpncl/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">ca.crt<o:p></o:p></span></div>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;"><br /></span>
<span style="font-family: "Calibri","sans-serif"; font-size: 11.0pt;">Next, we
want to create our configuration files. We do this by echoing a bunch of lines
to create a config file. We do this twice, once for each VPN. <o:p></o:p></span><br />
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Setup US Tunnel
Config<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">client</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">dev</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">proto</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">udp</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">remote</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">_YourVpnServer_</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 1194 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">resolv-retry</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">infinite</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nobind</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">persist-key</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">persist-tun</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">ca</span><span style="font-family: 'Courier New'; font-size: 10pt;"> /tmp/openvpncl/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">ca.crt</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tls-client</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> remote-cert-tls
</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">server</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >> /tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> auth-user-pass
/tmp/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">password.txt</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">comp-lzo</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">verb</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 1 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">reneg-sec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 0 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Setup UK Tunnel
Config<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">client</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">dev</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">proto</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">udp</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">remote</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">_YourOtherVpnServer_</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 1194 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">resolv-retry</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">infinite</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nobind</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">persist-key</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">persist-tun</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">ca</span><span style="font-family: 'Courier New'; font-size: 10pt;"> /tmp/openvpncl/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">ca.crt</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tls-client</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> remote-cert-tls
</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">server</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> auth-user-pass
/tmp/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">password.txt</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">comp-lzo</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">verb</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 1 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">reneg-sec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 0 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Note that you will need to replace YourVpnServer and
YourOtherVpnServer w/ the details appropriate to your service. There may
be other options to change as well, though, the above is
fairly basic and should work w/ most services.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
When we bring our tunnels up and down, we will need to tell
iptables to MASQUERADE for this connection. These will be run as scripts
so we need to set the execute bit for them. We create our up and down
scripts here:<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Tun0 route up
script<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">iptables</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -A </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">POSTROUTING</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -t </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nat</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -o </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun0</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -j </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">MASQUERADE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/route-up-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.sh</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">chmod 700
/tmp/openvpncl/route-up-UK.sh<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Tun0 route down
script<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">iptables</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">-D</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">POSTROUTING</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -t </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nat</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -o </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun0</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -j </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">MASQUERADE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/route-down-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.sh</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">chmod 700
/tmp/openvpncl/route-down-UK.sh<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Tun1 route up
script<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">iptables</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -A </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">POSTROUTING</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -t </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nat</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -o </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun1</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -j </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">MASQUERADE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/route-up-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.sh</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">chmod 700
/tmp/openvpncl/route-up-US.sh<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Tun1 route down
script<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">iptables</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">-D</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">POSTROUTING</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -t </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nat</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -o </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun1</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -j </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">MASQUERADE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/route-down-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.sh</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">chmod 700
/tmp/openvpncl/route-down-US.sh<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
of course, we need a username and password:<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#General Config<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">USER</span><span style="font-family: 'Courier New'; font-size: 10pt;"> > /tmp/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">password.txt</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">PASSWORD</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >> /tmp/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">password.txt</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now we bring up the tunnels. Note the
–route-nopull. This ignores routing info from the openvpn server.
We want to specify our own routing. Without that, openvpn seems to set
our default traffic to go out the last tunnel brought up. If you are
having any trouble on this step, run the line without –daemon.<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Setup
tunnels. <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">/usr/bin/killall
openvpn<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">/usr/sbin/openvpn
--config /tmp/openvpncl/openvpn-UK.conf --route-nopull --route-up
/tmp/openvpncl/route-up-UK.sh --down-pre /tmp/openvpncl/route-down-UK.sh
--daemon<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">/usr/sbin/openvpn
--config /tmp/openvpncl/openvpn-US.conf --route-nopull --route-up /tmp/openvpncl/route-up-US.sh
--down-pre /tmp/openvpncl/route-down-US.sh --daemon<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
In order to setup routes, we need to get our default
gateways for each interface. First, though, we hang out for a couple
seconds to allow the tunnels to establish:<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#The tunnels can
take a couple seconds to establish. Hold for 5 seconds to allow for this<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">sleep</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> 5<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># get gateway
addresses<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">IspGateway</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;">$(ip route list
table main | awk </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">'/default/ { print $3}'</span><span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">Tun0Gateway</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;">$(ip route list
table main | awk </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">'/tun0/ { print $1}'</span><span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-family: 'Courier New'; font-size: 10pt;">Tun1Gateway</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;">$(ip route list
table main | awk </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">'/tun1/ { print $1}'</span><span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in;">
<br /></div>
<div class="MsoNormal">
Now, we have our two tunnels established as tun0 (UK) and
tun1 (US). We also have our default (ppp0) route to our ISP. Now we
start getting fancy. B) <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We are going to use iptables to MARK our packets. Here
we tell iproute route any packets marked with a 2 based on the routing table,
2.<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># Create fwmark
to table bindings<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip rule add
fwmark 1 table main </span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># ISP<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip rule add
fwmark 2 table 2 </span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># Tunnel 0 UK<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip rule add fwmark 3 table 3 </span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># Tunnel 1 US<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
You can use ‘ip route show” to see current ip rules.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now we setup the routing for each table. For my setup,
I am just giving the default route.<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># Create table
to tunnel bindings<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip route add </span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">default</span><span style="font-family: 'Courier New'; font-size: 10pt;"> via </span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$Tun0Gateway</span><span style="font-family: 'Courier New'; font-size: 10pt;"> dev tun0 table
2 </span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Send
out UK Tunnel<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip route add </span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">default</span><span style="font-family: 'Courier New'; font-size: 10pt;"> via </span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$Tun1Gateway</span><span style="font-family: 'Courier New'; font-size: 10pt;"> dev tun1 table
3 </span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Send
out US Tunnel</span><o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
You can see the ip routes per table with:<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip route show
table 2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now we are ready to create specific rules. You will
probably have a lot more rules than the below. <o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#UK tunnel rules<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">iptables -A
PREROUTING -t mangle -s 192.168.1.0/24 -j MARK --set-mark 2<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#US Tunnel rules<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip rule add to
174.129.0.77</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">/</span><span style="font-family: 'Courier New'; font-size: 10pt;">32 table 3<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#ISP rules<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in;">
<span style="font-family: 'Courier New'; font-size: 10pt;">iptables -A PREROUTING -t mangle -p tcp
--destination-port 3389 -j MARK --set-mark 1</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
In order, we first say that anything coming from this
specific IP range (192.168.1.0/24) should route out the UK tunnel.<o:p></o:p></div>
<div class="MsoNormal">
Next we use a different way of layer 3 routing w/ ip
rule. I am actually just going to stick to the iptables MARKing for
simplicity but I wanted to show this was possible as well<o:p></o:p></div>
<div class="MsoNormal">
Finally, we mark a packet based on destination port.
So we are saying any RDP traffic should go out the ISP interface.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
That is all there is to it. Iptables is pretty full
featured, you can get pretty crazy w/ it. Good luck and if you do
something fun, please tell me about it.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Notes:<o:p></o:p></div>
<div class="MsoListParagraph" style="mso-list: l1 level1 lfo2; text-indent: -.25in;">
</div>
<ul style="text-align: left;">
<li><span style="font-size: 7pt; text-indent: -0.25in;"> </span><span style="text-indent: -0.25in;">If
one of your tunnels goes down, your routing for that tunnel goes away.
Your traffic will start to flow out your default interface. This may or
may not be ideal depending on the sensitivity of what you are passing.
You can manage that with the route down commands if you are concerned.</span></li>
<li><span style="text-indent: -0.25in;">the order your rules apply in matters. see ip rule output to see the order. If you want to 'override' the UK routing, in my example, you will need your rule to to have a lower ip rule id than the UK line.</span></li>
</ul>
<div style="text-indent: -24px;">
<br /></div>
<div style="text-indent: -24px;">
The full script is below:</div>
<div style="text-indent: -24px;">
<div class="MsoNormal">
<span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">mkdir</span><span style="font-family: 'Courier New'; font-size: 10pt;"> /tmp/openvpncl<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"-----BEGIN
CERTIFICATE-----</span></div>
<div class="MsoNormal">
<span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">--snip--</span></div>
<div class="MsoNormal">
<span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">-----END
CERTIFICATE-----<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">ca.crt</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Setup US Tunnel
Config<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">client</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">dev</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">proto</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">udp</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">remote</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">_YourVpnServer_</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 1194 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">resolv-retry</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">infinite</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nobind</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">persist-key</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">persist-tun</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">ca</span><span style="font-family: 'Courier New'; font-size: 10pt;"> /tmp/openvpncl/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">ca.crt</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tls-client</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> remote-cert-tls
</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">server</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> auth-user-pass
/tmp/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">password.txt</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">comp-lzo</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">verb</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 1 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">reneg-sec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 0 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Setup UK Tunnel
Config<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">client</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">dev</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">proto</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">udp</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">remote</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">_YourOtherVpnServer_</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 1194 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">resolv-retry</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">infinite</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nobind</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">persist-key</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">persist-tun</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">ca</span><span style="font-family: 'Courier New'; font-size: 10pt;"> /tmp/openvpncl/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">ca.crt</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tls-client</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> remote-cert-tls
</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">server</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> auth-user-pass
/tmp/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">password.txt</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">comp-lzo</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">verb</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 1 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">reneg-sec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 0 >>
/tmp/openvpncl/openvpn-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.conf</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Tun0 route up
script<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">iptables</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -A </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">POSTROUTING</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -t </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nat</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -o </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun0</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -j </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">MASQUERADE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/route-up-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.sh</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">chmod 700
/tmp/openvpncl/route-up-UK.sh<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Tun0 route down
script<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">iptables</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">-D</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">POSTROUTING</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -t </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nat</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -o </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun0</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -j </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">MASQUERADE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/route-down-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">UK.sh</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">chmod 700
/tmp/openvpncl/route-down-UK.sh<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Tun1 route up
script<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">iptables</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -A </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">POSTROUTING</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -t </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nat</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -o </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun1</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -j </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">MASQUERADE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/route-up-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.sh</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">chmod 700
/tmp/openvpncl/route-up-US.sh<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Tun1 route down
script<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">iptables</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">-D</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">POSTROUTING</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -t </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">nat</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -o </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">tun1</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -j </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">MASQUERADE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >
/tmp/openvpncl/route-down-</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">US.sh</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">chmod 700
/tmp/openvpncl/route-down-US.sh<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#General Config<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">USER</span><span style="font-family: 'Courier New'; font-size: 10pt;"> > /tmp/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">password.txt</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">echo</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">PASSWORD</span><span style="font-family: 'Courier New'; font-size: 10pt;"> >> /tmp/</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">password.txt</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Setup
tunnels. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">/usr/bin/killall
openvpn<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">/usr/sbin/openvpn
--config /tmp/openvpncl/openvpn-UK.conf --route-nopull --route-up
/tmp/openvpncl/route-up-UK.sh --down-pre /tmp/openvpncl/route-down-UK.sh
--daemon<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">/usr/sbin/openvpn
--config /tmp/openvpncl/openvpn-US.conf --route-nopull --route-up /tmp/openvpncl/route-up-US.sh
--down-pre /tmp/openvpncl/route-down-US.sh --daemon<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#The tunnels can
take a couple seconds to establish. Hold
for 5 seconds to allow for this<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">sleep</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> 5<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># get gateway
addresses<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">IspGateway</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;">$(ip route list
table main | awk </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">'/default/ { print $3}'</span><span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">Tun0Gateway</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;">$(ip route list
table main | awk </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">'/tun0/ { print $1}'</span><span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">Tun1Gateway</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;">$(ip route list
table main | awk </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">'/tun1/ { print $1}'</span><span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># Create fwmark
to table bindings<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip rule add
fwmark 1 table main </span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># ISP<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip rule add
fwmark 2 table 2 </span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># Tunnel 0 UK<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip rule add
fwmark 3 table 3 </span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># Tunnel 1 US<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;"># Create table
to tunnel bindings<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip route add </span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">default</span><span style="font-family: 'Courier New'; font-size: 10pt;"> via </span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$Tun0Gateway</span><span style="font-family: 'Courier New'; font-size: 10pt;"> dev tun0 table
2 </span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Send
out UK Tunnel<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip route add </span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">default</span><span style="font-family: 'Courier New'; font-size: 10pt;"> via </span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$Tun1Gateway</span><span style="font-family: 'Courier New'; font-size: 10pt;"> dev tun1 table
3 </span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#Send
out US Tunnel<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#UK tunnel rules<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">iptables -A
PREROUTING -t mangle -s 192.168.1.0/24 -j MARK --set-mark 2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#US Tunnel rules<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">ip rule add to
174.129.0.77</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">/</span><span style="font-family: 'Courier New'; font-size: 10pt;">32 table 3<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt;">#ISP rules<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">iptables -A
PREROUTING -t mangle -p tcp --destination-port 3389 -j MARK --set-mark 1<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
</div>
</div>
cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com11tag:blogger.com,1999:blog-10074565.post-67097759896324584032012-06-15T13:07:00.001+00:002012-07-26T17:22:11.426+00:00Powershell to run a DBCC checkdb loop for all databases<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
I needed a loop that would run a dbcc check db on all online
databases (other than tempdb). I did
this is sql first but I seemed to be getting strange errors. After a bit of research, I saw that I wasn’t
the only one and decided to drop out of sql and run the commands in as
separated a manner as possible. The
script below gets all online databases and runs dbcc checkdb on all of them. We use WITH NO_INFOMSGS so if we have any output,
we consider it a problem and send it to an operator. We use sqlcmd and a command processor so hopefully a single dbcc error will not corrupt the rest of the run...<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We take 3 arguments<o:p></o:p></div>
<div class="MsoNormal">
@SqlInstance – Name of sql instance to check<o:p></o:p></div>
<div class="MsoNormal">
@MailHost – we need an SMTP server to send the message
through<o:p></o:p></div>
<div class="MsoNormal">
@MailTo – address of the operator that will get the
error/warning messages<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p>This was developed against SQL Server 2008 but I see no reason it wouldn't work on others...</o:p></div>
<div class="MsoNormal">
Good luck<o:p></o:p><br />
<br />
Update: 20120620 - added a kill all connections based on <a href="http://www.sqlservercentral.com/scripts/Lock+and+Connection+Management/31966/">this post</a>. </div>
<div class="MsoNormal">
<br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">param</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlInstance</span><span style="font-family: 'Courier New'; font-size: 10pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MailHost</span><span style="font-family: 'Courier New'; font-size: 10pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MailTo</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">function</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">main</span><span style="font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$verbosity</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 2<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ScriptName</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$myInvocation</span><span style="font-family: 'Courier New'; font-size: 10pt;">.MyCommand.Name<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">void</span><span style="font-family: 'Courier New'; font-size: 10pt;">][</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">reflection.assembly</span><span style="font-family: 'Courier New'; font-size: 10pt;">]::</span><span style="color: saddlebrown; font-family: 'Courier New'; font-size: 10pt;">LoadWithPartialName</span><span style="font-family: 'Courier New'; font-size: 10pt;">(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"System.Data.SqlClient"</span><span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ConnString</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Server=$SqlInstance;Integrated
Security=SSPI;Application Name=$ScriptName"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MasterConn</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">new-object</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">'System.Data.SqlClient.SqlConnection'</span><span style="font-family: 'Courier New'; font-size: 10pt;">) </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ConnString</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MasterCmd</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">new-object</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">System.Data.SqlClient.SqlCommand</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MasterCmd</span><span style="font-family: 'Courier New'; font-size: 10pt;">.Connection </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MasterConn</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlDBCC</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"SELECT
name AS name FROM master..sysdatabases WHERE Name <> 'tempdb'AND
DATABASEPROPERTY(name, 'IsOffline') = 0"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MasterCmd</span><span style="font-family: 'Courier New'; font-size: 10pt;">.CommandText </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlDBCC</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MasterConn</span><span style="font-family: 'Courier New'; font-size: 10pt;">.Open()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Rset</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MasterCmd</span><span style="font-family: 'Courier New'; font-size: 10pt;">.ExecuteReader()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">If</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Rset</span><span style="font-family: 'Courier New'; font-size: 10pt;">.HasRows </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$true</span><span style="font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">While</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Rset</span><span style="font-family: 'Courier New'; font-size: 10pt;">.Read()) {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DatabaseName</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Rset</span><span style="font-family: 'Courier New'; font-size: 10pt;">[</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Name"</span><span style="font-family: 'Courier New'; font-size: 10pt;">]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> out-log
</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Working
with $DatabaseName. Killing Connections
at $(Date)"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlCmdOutput</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> sqlcmd -E -S </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlInstance</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -d </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DatabaseName</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -Q </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"exec
master.dbo.usp_KillConnections $DatabaseName"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> out-log
</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"$SqlCmdOutput<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;"> Starting
Check"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlCmdOutput</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> sqlcmd -E -S </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlInstance</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -d </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DatabaseName</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -Q </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"dbcc
checkdb WITH NO_INFOMSGS"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlCmdOutput</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Null</span><span style="font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> out-log
</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"DBCC
completed for $DatabaseName on $SqlInstance with no errors"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }
</span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">else</span><span style="font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> out-log </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"WARNING:
DBCC Completed with errors: <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;"> $SqlCmdOutput"</span><span style="font-family: 'Courier New'; font-size: 10pt;">
-ForeGroundColor Red<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MailSubject</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"$DatabaseName
@ $SqlInstance DBCC Failure"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MailFrom</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"DBCCRunner.$(hostname)@host.com"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MailBody</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"DBCC
reported errors. <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;"> Instance:
$SqlInstance<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;"> Database:
$DatabaseName<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;"> $SqlCmdOutput<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;"> "</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">new-object</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">Net.Mail.SmtpClient</span><span style="font-family: 'Courier New'; font-size: 10pt;">(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MailHost</span><span style="font-family: 'Courier New'; font-size: 10pt;">)).send(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MailFrom</span><span style="font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MailTo</span><span style="font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MailSubject</span><span style="font-family: 'Courier New'; font-size: 10pt;">, </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MailBody</span><span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Rset</span><span style="font-family: 'Courier New'; font-size: 10pt;">.Close()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$MasterConn</span><span style="font-family: 'Courier New'; font-size: 10pt;">.Close()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">function</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Out-Log</span><span style="font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#v.6 - ej
20120325 - Indented verbose output<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#v.5 - ej
20120210 - set logging to $env:HOMEDRIVE<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#v.4 - ej
20120207 - fixed tab issue that broke copy and paste to console.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#v.3 - ej
20111109 - added newline and removed the timestamps from display<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#version .2 -
ej, 20090114<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#this script
will allow for logging and screen output based on a requested verbosity level.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#taking a cue
from syslog, we are defining 0 as most critical errors.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#by default in
this script, verbosity is set as 1. so
we only print items specifically marked as 0 criticality to screen<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#default items
come in as a log level of 1, ie they are not printed. both of these can be overridden<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># all items are
logged to a file based on the scriptname and run date at
c:\toolkit\scripts\logs<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># it is expected
that the default log level will be used for warnings and some informational
messages<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># debug messages
will be given log levels of 2 and higher as detailed below.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># critical
messages should be marked w/ a log level of 0<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#usage:<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># in your script
you can include the function with:<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># .
c:\toolkit\scripts\out-log.ps1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># you can then
write all informational messages to log with<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># out-log
<StringToLog> [LogLevel] [ForeGroundColor]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#simplest case
(when in doubt, use this)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># out-log
"message to log"<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#if you want to
also ALWAYS print to screen you can set the message to level 0 with (use
sparingly)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># out-log
"message to log" 0<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#if you want
make it print in RED on the screen (dependent on whether it will print to
screen)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># out-log
"message to log" 0 RED<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#to change the
level of logging that you want to see on screen, you can set a global variable
'verbosity'<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#this script
will print log levels that are equal to or less than the variable '$verbosity'.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#a suggested
usage is to accept a command line argument with verbosity level.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#best way to
accept verbosity via cmd line is to add a param to the beginning of your
script. it needs to be first line.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># if the param
below is added to your script, you can add "-v 3" to your command
line to set the verbosity to 3,<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># this script
prints all log items with a lower loglevel than the chosen verbosity.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># if not set, we
assume verbosity 0.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># we then expect
that only critical errors would be sent to log level 0. default log level is 1.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#param(<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#[string]
$verbosity = 0<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># you can also
set deeper log levels. for example, if
you want log level 1 to be warnings and information about script progress<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># but you also want the option to
enable/disable debug messages, you can log all your debug messages to a higher
log<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># out-log
"debug string to log" 2<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#if you then
want to run your script such that you see debugging messages, you can run<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#./script.ps1
-verbosity 2<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#note that you
can use shortened command line arguments.
you just need enough to be unique so unless you<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># define another
param that starts w/ 'v', you can use<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#./script.ps1 -v
2<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">##### BEGIN
SCRIPT ######<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">param</span><span style="font-family: 'Courier New'; font-size: 10pt;">(<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">string</span><span style="font-family: 'Courier New'; font-size: 10pt;">] </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$incomingString</span><span style="font-family: 'Courier New'; font-size: 10pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">int</span><span style="font-family: 'Courier New'; font-size: 10pt;">] </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logLevel</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 1 ,<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ForegroundColor</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$host</span><span style="font-family: 'Courier New'; font-size: 10pt;">.</span><span style="color: saddlebrown; font-family: 'Courier New'; font-size: 10pt;">ui</span><span style="font-family: 'Courier New'; font-size: 10pt;">.</span><span style="color: saddlebrown; font-family: 'Courier New'; font-size: 10pt;">RawUI</span><span style="font-family: 'Courier New'; font-size: 10pt;">.</span><span style="color: saddlebrown; font-family: 'Courier New'; font-size: 10pt;">ForegroundColor</span><span style="font-family: 'Courier New'; font-size: 10pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$BackgroundColor</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$host</span><span style="font-family: 'Courier New'; font-size: 10pt;">.</span><span style="color: saddlebrown; font-family: 'Courier New'; font-size: 10pt;">ui</span><span style="font-family: 'Courier New'; font-size: 10pt;">.</span><span style="color: saddlebrown; font-family: 'Courier New'; font-size: 10pt;">RawUI</span><span style="font-family: 'Courier New'; font-size: 10pt;">.</span><span style="color: saddlebrown; font-family: 'Courier New'; font-size: 10pt;">BackgroundColor</span><span style="font-family: 'Courier New'; font-size: 10pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">switch</span><span style="font-family: 'Courier New'; font-size: 10pt;">]</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$NoNewLine</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> )<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#we are defining
the log directory on all machines to be, use trailing "\"<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logDirectory</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"$($env:HOMEDRIVE)\logs\"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#set your date<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logDate</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Get-Date</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-Format</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">yyyyMMdd-HHmmss</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#have we defined
verbosity?<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#if verbosity is
not defined, we set it here as 0<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$verbosity</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$null</span><span style="font-family: 'Courier New'; font-size: 10pt;">) {</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$verbosity</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 0}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#have we defined
the logfile?<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-not</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">test-path</span></b><span style="font-family: 'Courier New'; font-size: 10pt;">
variable:outlogfile)) {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#if no, create
it now based on todays datetime and progname<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#check for the
log path, create if not found<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">!</span><span style="font-family: 'Courier New'; font-size: 10pt;">(</span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Test-Path</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-path</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$LogDirectory</span><span style="font-family: 'Courier New'; font-size: 10pt;">)) {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$tmp</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">New-Item</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$LogDirectory</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -type </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">directory</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-Host</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">" --->
Created Log Directory at "</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$LogDirectory</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#define name
<ScriptName>-<Date>.log<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="font-family: 'Courier New'; font-size: 10pt;">(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$myInvocation</span><span style="font-family: 'Courier New'; font-size: 10pt;">.ScriptName </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-ne</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">""</span><span style="font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$scriptName</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">IO.Path</span><span style="font-family: 'Courier New'; font-size: 10pt;">]::</span><span style="color: saddlebrown; font-family: 'Courier New'; font-size: 10pt;">GetFileNameWithoutExtension</span><span style="font-family: 'Courier New'; font-size: 10pt;">(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$myInvocation</span><span style="font-family: 'Courier New'; font-size: 10pt;">.ScriptName)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }
</span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">else</span><span style="font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$scriptName</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"NONAME"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logName</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logDirectory</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$scriptName</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"-"</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logDate</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">".log"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-Host</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Logging
to: $logname"</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-ForegroundColor</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">DarkBlue</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-BackgroundColor</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">DarkYellow</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Set-Variable</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-Name</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">OutLogFile</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-Value</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logName</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-Scope</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">script</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#now we use the
Logfile<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#if the log
level is lower or equal to than the verbosity, we also spit to screen<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logLevel</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-le</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Verbosity</span><span style="font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-Host</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">" "</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">*</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logLevel</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$incomingString</span><span style="font-family: 'Courier New'; font-size: 10pt;">)
-ForegroundColor </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ForegroundColor</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -BackgroundColor </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$BackgroundColor</span><span style="font-family: 'Courier New'; font-size: 10pt;"> -NoNewline:</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$NoNewLine</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#date time stamp
for logging<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$stringToLog</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logDate</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">": "</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">" "</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">*</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$logLevel</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$incomingString</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#finally, stick
this in the log<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Out-File</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-filepath</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$outLogfile</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-inputObject</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$stringToLog</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-append</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt; line-height: 115%;">main</span><o:p></o:p></div>
</div>
</div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com3tag:blogger.com,1999:blog-10074565.post-76973859764297399192012-05-30T09:23:00.000+00:002012-07-26T17:22:01.269+00:00Differential and Partial Differential backups with Partitioned tables and Read only FileGroups<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
Here is a quick write up w/ little commentary. This is a corollary to an <a href="http://cornasdf.blogspot.co.uk/2012/05/basic-walkthrough-of-partial-backup-and.html">earlier article</a>. I wanted to see how differential backups are
affected by partitioning and read only. See
the comments to see where we are. If I
have time in the future I will try to hash it out but right now it is get it up
as this or don’t get it online at all.
Hope this helps someone.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The idea isn’t to run this whole block of code. Run it chunk by chunk and see what happens. Standard
disclaimers, if you don’t know what this is doing, it isn’t my problem if you
bork your system.<o:p></o:p></div>
<div class="MsoNormal">
<o:p><br /></o:p></div>
<div class="MsoNormal">
<o:p>This was all done on SQL 2008R2.</o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--Setup test dbs to use for walkthrough<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span><span style="color: red;">'testdb'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">IF</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">EXISTS</span><span style="color: blue;"> </span><span style="color: grey;">(<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> name<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WHERE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> name <span style="color: grey;">=</span> <span style="color: red;">N'TestDB'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DROP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> TestDB<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">CREATE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> TestDB<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ON</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">PRIMARY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">NAME<span style="color: grey;">=</span><span style="color: red;">'TestDB_Part1'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span><span style="color: grey;">=</span><span style="color: red;">'c:\data\TestDB_Part1.mdf'</span><span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">SIZE<span style="color: grey;">=</span>3<span style="color: grey;">,</span> MAXSIZE<span style="color: grey;">=</span>100<span style="color: grey;">,</span> FILEGROWTH<span style="color: grey;">=</span>1 <span style="color: grey;">),<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_Part2<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">NAME <span style="color: grey;">=</span> <span style="color: red;">'TestDB_Part2'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span> <span style="color: grey;">=</span><span style="color: red;">'c:\data\TestDB_Part2.ndf'</span><span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">SIZE <span style="color: grey;">=</span> 2<span style="color: grey;">,</span> MAXSIZE<span style="color: grey;">=</span>100<span style="color: grey;">,</span> FILEGROWTH<span style="color: grey;">=</span>1 <span style="color: grey;">),<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_Part3<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">NAME <span style="color: grey;">=</span> <span style="color: red;">'TestDB_Part3'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span> <span style="color: grey;">=</span><span style="color: red;">'c:\data\TestDB_Part3.ndf'</span><span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">SIZE <span style="color: grey;">=</span> 2<span style="color: grey;">,</span> MAXSIZE<span style="color: grey;">=</span>100<span style="color: grey;">,</span> FILEGROWTH<span style="color: grey;">=</span>1 <span style="color: grey;">),<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_Part4<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">NAME <span style="color: grey;">=</span> <span style="color: red;">'TestDB_Part4'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span> <span style="color: grey;">=</span><span style="color: red;">'c:\data\TestDB_Part4.ndf'</span><span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">SIZE <span style="color: grey;">=</span> 2<span style="color: grey;">,</span> MAXSIZE<span style="color: grey;">=</span>100<span style="color: grey;">,</span> FILEGROWTH<span style="color: grey;">=</span>1 <span style="color: grey;">),<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_Part5<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">NAME <span style="color: grey;">=</span> <span style="color: red;">'TestDB_Part5'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span> <span style="color: grey;">=</span><span style="color: red;">'c:\data\TestDB_Part5.ndf'</span><span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">SIZE <span style="color: grey;">=</span> 2<span style="color: grey;">,</span> MAXSIZE<span style="color: grey;">=</span>100<span style="color: grey;">,</span> FILEGROWTH<span style="color: grey;">=</span>1 <span style="color: grey;">);<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">USE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestDB<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 2 : Create Partition Range Function<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">CREATE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">PARTITION</span> <span style="color: blue;">FUNCTION</span>
TestDB_PartitionRange<span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">INT</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">AS</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">RANGE</span> <span style="color: grey;">LEFT</span> <span style="color: blue;">FOR<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">10<span style="color: grey;">,</span>20<span style="color: grey;">,</span>30<span style="color: grey;">,</span>40<span style="color: grey;">);<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">USE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestDB<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 3 : Attach Partition Scheme to FileGroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">CREATE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">PARTITION</span> SCHEME TestDB_PartitionScheme<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">AS</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">PARTITION</span> TestDB_PartitionRange<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">[PRIMARY]<span style="color: grey;">,</span> TestDB_Part2<span style="color: grey;">,</span> TestDB_Part3<span style="color: grey;">,</span>
TestDB_Part4<span style="color: grey;">,</span> TestDB_Part5<span style="color: grey;">);<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 4 : Create Table with Partition Key and Partition Scheme<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">CREATE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">TABLE</span> TestTable<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">ID <span style="color: blue;">INT</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">Date</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATETIME</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ON</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_PartitionScheme<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">);<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 5 : (Optional/Recommended) Create Index on Partitioned Table<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">CREATE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">UNIQUE</span> <span style="color: blue;">CLUSTERED</span> <span style="color: blue;">INDEX</span> IX_TestTable<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ON</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">(</span>ID<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ON</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_PartitionScheme<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">);<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 6 : Insert Data in Partitioned Table<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 1<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">1<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 2<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">11<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 2<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">12<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 4<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">32<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">42<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">52<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 3<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">22<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 7 : Test Data from TestTable<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 8 : Verify Rows Inserted in Partitions<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">partitions<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WHERE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">OBJECT_NAME</span><span style="color: grey;">(</span><span style="color: magenta;">OBJECT_ID</span><span style="color: grey;">)=</span><span style="color: red;">'TestTable'</span><span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- set FG 2 to read only<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ALTER</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <span style="color: blue;">MODIFY</span>
<span style="color: blue;">FILEGROUP</span> [TestDB_Part2] <span style="color: blue;">READONLY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Normal Full backup <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_Full.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Backup rw and ro separately<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">READ_WRITE_FILEGROUPS
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RW.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'TestDB_Part2'</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RO_Part2.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- add data<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 4<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">24<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">44<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">54<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Backup DIFF<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_DIFF.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <span style="color: blue;">DIFFERENTIAL</span> <span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--backup Partial (RW) diff<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">READ_WRITE_FILEGROUPS
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_DIFFPartial.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <span style="color: blue;">DIFFERENTIAL</span> <span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- list backup files. We did not
backup the read only file group in either diff<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FILELISTONLY</span> <span style="color: blue;">from</span> <span style="color: blue;">disk</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_Diff.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FILELISTONLY</span> <span style="color: blue;">from</span> <span style="color: blue;">disk</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_DiffPartial.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore RW portion w/ no recovery<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">drop</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">database</span> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RW.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">NORECOVERY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part2'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RO_Part2.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--hmm, some warnings:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----The roll forward start point is now at log sequence number (LSN)
20000000057700001. Additional roll forward past LSN 20000000061400001 is
required to complete the restore sequence.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----This RESTORE statement successfully performed some actions, but the
database could not be brought online because one or more RESTORE steps are
needed. Previous messages indicate reasons why recovery cannot occur at this
point.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- All files in restoring now...<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore partial dff<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_DIFFPartial.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- All files online now...<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--let's try w/ diff before the ro<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore RW portion w/ no recovery<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">drop</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">database</span> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RW.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">NORECOVERY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore partial diff and bring online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_DIFFPartial.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- still some warnings<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----The file "TestDB_Part2" was not fully restored by a database
or file restore. The entire file must be successfully restored before applying
this backup set.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----This RESTORE statement successfully performed some actions, but the
database could not be brought online because one or more RESTORE steps are
needed. Previous messages indicate reasons why recovery cannot occur at this
point.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part2'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RO_Part2.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- All files online now...<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- ok, for completeness, what is the difference if I use the 'full'
differential? (ie the non partial one)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore RW portion w/ no recovery<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">drop</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">database</span> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RW.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">NORECOVERY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore diff and bring online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_DIFF.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">recovery<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--hmmm got some errors<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----The file "TestDB_Part2" was not fully restored by a database
or file restore. The entire file must be successfully restored before applying
this backup set.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----This RESTORE statement successfully performed some actions, but the
database could not be brought online because one or more RESTORE steps are
needed. Previous messages indicate reasons why recovery cannot occur at this
point.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part2'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RO_Part2.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- All files online now...<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore the RO first (before the diff)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore RW portion w/ no recovery<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">drop</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">database</span> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RW.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">NORECOVERY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part2'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RO_Part2.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--same roll forward error:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----The roll forward start point is now at log sequence number (LSN)
20000000057700001. Additional roll forward past LSN 20000000061400001 is
required to complete the restore sequence.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----This RESTORE statement successfully performed some actions, but the
database could not be brought online because one or more RESTORE steps are
needed. Previous messages indicate reasons why recovery cannot occur at this
point.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see files in restoring<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore diff and bring online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_DIFF.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">recovery<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--ok, doesn't seem to matter much as long as we do all of them. Lets make a new file readonly<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- set FG 3 to read only<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ALTER</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <span style="color: blue;">MODIFY</span>
<span style="color: blue;">FILEGROUP</span> [TestDB_Part3] <span style="color: blue;">READONLY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Backup rw and new ro separately<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">READ_WRITE_FILEGROUPS
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RW.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'TestDB_Part3'</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RO_Part3.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- add data<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 3 SHOULD FAIL due to read only<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">25<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">35<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">55<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Backup DIFF<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_DIFF.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <span style="color: blue;">DIFFERENTIAL</span> <span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--backup Partial (RW) diff<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">READ_WRITE_FILEGROUPS
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_DIFFPartial.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <span style="color: blue;">DIFFERENTIAL</span> <span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- list backup files. We did not
backup the read only file group in either diff<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FILELISTONLY</span> <span style="color: blue;">from</span> <span style="color: blue;">disk</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_Diff.bak'</span>
<span style="color: green;">--has both read only files<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FILELISTONLY</span> <span style="color: blue;">from</span> <span style="color: blue;">disk</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_DiffPartial.bak'</span>
<span style="color: green;">--has neither read only file<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--try restoring with no read only files (just main and big diff)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">drop</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">database</span> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RW.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">NORECOVERY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore diff and bring online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_DIFF.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">recovery<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--despite saying the file is there in the backup, we still get issues with
RO files<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----The file "TestDB_Part2" was not fully restored by a database
or file restore. The entire file must be successfully restored before applying
this backup set.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----The file "TestDB_Part3" was not fully restored by a database
or file restore. The entire file must be successfully restored before applying
this backup set.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part2'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RO_Part2.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--warning we are still missing 3 so cannot come online<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part3'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RO_Part3.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--try restoring with partial diff<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">drop</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">database</span> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RW.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">NORECOVERY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore diff and bring online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_DIFFPartial.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">recovery<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--same issues with RO files<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----The file "TestDB_Part2" was not fully restored by a database
or file restore. The entire file must be successfully restored before applying
this backup set.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----The file "TestDB_Part3" was not fully restored by a database
or file restore. The entire file must be successfully restored before applying
this backup set.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part2'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RO_Part2.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--warning we are still missing 3 so cannot come online<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part3'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RO_Part3.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--it seems we cannot come online until all full, diffs and RO files are
restored. This is different <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- than when we have just a partial
backup and RO (no diffs), where we can come online after just the partial
backup<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--one more scenario. what if i make
something read only and then take a diff backup before a 'full' partial (i
should really look up the correct terminology)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- set FG 4 to read only<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ALTER</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <span style="color: blue;">MODIFY</span>
<span style="color: blue;">FILEGROUP</span> [TestDB_Part4] <span style="color: blue;">READONLY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- add data<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 4, SHOULD FAIL due to read only<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">35<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">55<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--backup RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'TestDB_Part4'</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RO_Part4.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Backup DIFF<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_DIFF2.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <span style="color: blue;">DIFFERENTIAL</span> <span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--backup Partial (RW) diff<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">READ_WRITE_FILEGROUPS
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_DIFFPartial2.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <span style="color: blue;">DIFFERENTIAL</span> <span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- list backup files. We did not
backup the read only file group in either diff<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FILELISTONLY</span> <span style="color: blue;">from</span> <span style="color: blue;">disk</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_Diff2.bak'</span>
<span style="color: green;">--has all read only files<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FILELISTONLY</span> <span style="color: blue;">from</span> <span style="color: blue;">disk</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_DiffPartial2.bak'</span>
<span style="color: green;">--has none of the read only files<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore test<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">drop</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">database</span> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RW.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">NORECOVERY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore diff and bring online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_DIFF2.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">recovery<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--same issues with RO files<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----The file "TestDB_Part2" was not fully restored by a database
or file restore. The entire file must be successfully restored before applying
this backup set.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">----The file "TestDB_Part3" was not fully restored by a database
or file restore. The entire file must be successfully restored before applying
this backup set.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part2'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB_RO_Part2.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part3'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RO_Part3.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part4'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RO_Part4.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--so this all works about how we would expect, except that you cannot come
online after just a base backup and<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- a partial diff restore. (you
must get your RO online as well before the db will come up). note that if you are <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restoring in place and your Read only hasn't changed since your base
backup, your RO will be found as in:<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore with no drop<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_RW.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">NORECOVERY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files offline<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore diff and bring online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'c:\data\TestDB2_DIFF.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'c:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">recovery<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- see all files online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span>
<span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name
<span style="color: grey;">=</span> <span style="color: red;">'testdb2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
</div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com3tag:blogger.com,1999:blog-10074565.post-791533923659743742012-05-14T11:47:00.000+00:002012-07-26T17:21:46.014+00:00Basic walkthrough of Partial Backup and Restore for Partitioned and Read Only SQL Server Databases<div dir="ltr" style="text-align: left;" trbidi="on">
Hi all,<br />
Building on an excellent article from <a href="http://blog.sqlauthority.com/2008/01/25/sql-server-2005-database-table-partitioning-tutorial-how-to-horizontal-partition-database-table/">Pinal Dave</a>, here is a walkthrough test of creating, partioning, backing up and restoring (partial and full) of a sql server database. These tests were done on sql 2008 but should be pretty generic.<br />
<br />
What I wanted to test is the ability to make parts of a large database read only and stop backing up the whole damn thing. The basic steps (detail below) are:<br />
<br />
<ol style="text-align: left;">
<li>Create partitioned table. This can be a new table and database (as below) or you can repartition an existing table (create your partition function and scheme and apply a clustered index). Note that repartitioning can take a long time and locks your table so test accordingly.</li>
<li>Set file group read only</li>
<li>Backup ReadWrite and ReadOnly filegroups separately.</li>
<li>Restore (Primary and) ReadWrite Filegroup (FG) in new db </li>
<li>Restore ReadOnly filegroup</li>
<li>Verify</li>
<li>Make new Filegroup read only in original DB</li>
<li>New backup of
ReadWrite Filegroup and new backup of new ReadOnly file group</li>
<li>Restore
ReadWrite Filegroup, tell database your first ReadOnly filegroup is in a good state already and to just recover it, restore newly ReadOnly Filegroup.</li>
<li>Verify</li>
</ol>
I do that a few times to verify the procedure and then have a disaster recovery version at the bottom. Below is a step by step walkthrough. <br />
<br />
First we create the test database, the partition function, scheme and table. We then insert data that will span several partitions. All of this is stolen more or less directly from <a href="http://blog.sqlauthority.com/2008/01/25/sql-server-2005-database-table-partitioning-tutorial-how-to-horizontal-partition-database-table/">Pinal Dave</a>, I had more steps to test so I added a few more partitions. Note, if you don't have a d drive, you will need to update the paths accordingly.<br />
<br />
Update: see <a href="http://cornasdf.blogspot.com/2012/05/differential-and-partial-differential.html">here</a> for details on differential backups.<br />
<br />
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Step 1: setup basic test database<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span><span style="color: red;">'testdb'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">IF</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">EXISTS</span><span style="color: blue;"> </span><span style="color: grey;">(<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> name<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WHERE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> name <span style="color: grey;">=</span> <span style="color: red;">N'TestDB'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DROP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> TestDB<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">CREATE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> TestDB<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ON</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">PRIMARY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">NAME<span style="color: grey;">=</span><span style="color: red;">'TestDB_Part1'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span><span style="color: grey;">=</span><span style="color: red;">'D:\data\TestDB_Part1.mdf'</span><span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">SIZE<span style="color: grey;">=</span>3<span style="color: grey;">,</span> MAXSIZE<span style="color: grey;">=</span>100<span style="color: grey;">,</span> FILEGROWTH<span style="color: grey;">=</span>1 <span style="color: grey;">),<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_Part2<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">NAME <span style="color: grey;">=</span> <span style="color: red;">'TestDB_Part2'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span> <span style="color: grey;">=</span><span style="color: red;">'D:\data\TestDB_Part2.ndf'</span><span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">SIZE <span style="color: grey;">=</span> 2<span style="color: grey;">,</span> MAXSIZE<span style="color: grey;">=</span>100<span style="color: grey;">,</span> FILEGROWTH<span style="color: grey;">=</span>1 <span style="color: grey;">),<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_Part3<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">NAME <span style="color: grey;">=</span> <span style="color: red;">'TestDB_Part3'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span> <span style="color: grey;">=</span><span style="color: red;">'D:\data\TestDB_Part3.ndf'</span><span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">SIZE <span style="color: grey;">=</span> 2<span style="color: grey;">,</span> MAXSIZE<span style="color: grey;">=</span>100<span style="color: grey;">,</span> FILEGROWTH<span style="color: grey;">=</span>1 <span style="color: grey;">),<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_Part4<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">NAME <span style="color: grey;">=</span> <span style="color: red;">'TestDB_Part4'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span> <span style="color: grey;">=</span><span style="color: red;">'D:\data\TestDB_Part4.ndf'</span><span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">SIZE <span style="color: grey;">=</span> 2<span style="color: grey;">,</span> MAXSIZE<span style="color: grey;">=</span>100<span style="color: grey;">,</span> FILEGROWTH<span style="color: grey;">=</span>1 <span style="color: grey;">),<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_Part5<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">NAME <span style="color: grey;">=</span> <span style="color: red;">'TestDB_Part5'</span><span style="color: grey;">,</span> <span style="color: blue;">FILENAME</span> <span style="color: grey;">=</span><span style="color: red;">'D:\data\TestDB_Part5.ndf'</span><span style="color: grey;">,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">SIZE <span style="color: grey;">=</span> 2<span style="color: grey;">,</span> MAXSIZE<span style="color: grey;">=</span>100<span style="color: grey;">,</span> FILEGROWTH<span style="color: grey;">=</span>1 <span style="color: grey;">);<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 2 : Create Partition Range Function<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">USE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestDB<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">GOCREATE <span style="color: blue;">PARTITION</span> <span style="color: blue;">FUNCTION</span>
TestDB_PartitionRange<span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">INT</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">AS</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">RANGE</span> <span style="color: grey;">LEFT</span> <span style="color: blue;">FOR<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">10<span style="color: grey;">,</span>20<span style="color: grey;">,</span>30<span style="color: grey;">,</span>40<span style="color: grey;">);<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">USE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestDB<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 3 : Attach Partition Scheme to FileGroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">CREATE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">PARTITION</span> SCHEME TestDB_PartitionScheme<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">AS</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">PARTITION</span> TestDB_PartitionRange<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">[PRIMARY]<span style="color: grey;">,</span> TestDB_Part2<span style="color: grey;">,</span> TestDB_Part3<span style="color: grey;">,</span>
TestDB_Part4<span style="color: grey;">,</span> TestDB_Part5<span style="color: grey;">);<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 4 : Create Table with Partition Key and Partition Scheme<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">CREATE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">TABLE</span> TestTable<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">ID <span style="color: blue;">INT</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">Date</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATETIME</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ON</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_PartitionScheme<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">);<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 5 : (Optional/Recommended) Create Index on Partitioned Table<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">CREATE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">UNIQUE</span> <span style="color: blue;">CLUSTERED</span> <span style="color: blue;">INDEX</span> IX_TestTable<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ON</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">(</span>ID<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ON</span><span style="font-family: 'Courier New'; font-size: 10pt;">
TestDB_PartitionScheme<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">);<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 6 : Insert Data in Partitioned Table<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 1<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">1<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 2<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">11<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 2<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">12<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 4<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">32<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">42<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">52<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 3<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">22<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 7 : Test Data from TestTable<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Step 8 : Verify Rows Inserted in Partitions<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">partitions<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WHERE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">OBJECT_NAME</span><span style="color: grey;">(</span><span style="color: magenta;">OBJECT_ID</span><span style="color: grey;">)=</span><span style="color: red;">'TestTable'</span><span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO</span><o:p></o:p></div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We can do two types of backups now. We can do a standard full backup which is fine on this size of database but as the dbs get large, syncing around and restoring very large dbs can be a PITA. If we can make some of our data read only (with all that entails), we can speed our backups, restores and copy times dramatically.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
First, we want to set partition 2 to ReadOnly. We do that with </div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- set FG 2 to read only<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ALTER</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <span style="color: blue;">MODIFY</span> <span style="color: blue;">FILEGROUP</span> [TestDB_Part2] <span style="color: blue;">READONLY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"><br /></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
We can now backup the RW FG's separately</div>
<br />
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Backup rw and ro separately<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">READ_WRITE_FILEGROUPS
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RW.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'TestDB_Part2'</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RO_Part2.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"><br /></span></div>
<div class="MsoNormal">
We have 2 backup files now. Check the IsPresent column for each FileGroup with:</div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- list backup files<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FILELISTONLY</span> <span style="color: blue;">from</span> <span style="color: blue;">disk</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RW.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FILELISTONLY</span> <span style="color: blue;">from</span> <span style="color: blue;">disk</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RO_Part2.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We can now begin our restore on the TestDB2 (imaginatively named, i know). First the RW filegroup (which, importantly, contains the PRIMARY FG)</div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore RW<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RW.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;"><br /></span></div>
<div class="MsoNormal">
All, well and good but if we check our table, we get an error as not all the data is present. One important note that is not shown below is that if we had another table in our database, we could query that w/ no problem. It is only queries that try to hit tables w/ missing data that fail. </div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Verify (should fail)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
To see why this fails run: </div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- check filegroups.</span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">especially
state_desc</span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">where</span><span style="font-family: 'Courier New'; font-size: 10pt;">
database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name <span style="color: grey;">=</span> <span style="color: red;">'TestDB2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
Note that our RO group is offline. We need to restore it.</div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part2'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RO_Part2.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p>Now we can verify</o:p></div>
<br />
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Verify (should succeed)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- check filegroups. especially
state_desc<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">where</span><span style="font-family: 'Courier New'; font-size: 10pt;">
database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name <span style="color: grey;">=</span> <span style="color: red;">'TestDB2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p>Lets add some more data to verify that we are restoring the correct backups. Remember that you cannot add any data to Partition 2!</o:p></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- add data<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 4<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">33<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES
</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">43<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">INSERT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">INTO</span> TestTable<span style="color: blue;"> </span><span style="color: grey;">(</span>ID<span style="color: grey;">,</span> <span style="color: blue;">Date</span><span style="color: grey;">)</span> <span style="color: green;">-- Inserted in Partition 5<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">VALUES </span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="font-family: 'Courier New'; font-size: 10pt;">53<span style="color: grey;">,</span><span style="color: magenta;">GETDATE</span><span style="color: grey;">());</span></span><o:p></o:p></div>
<br />
<div class="MsoNormal">
<o:p><br /></o:p></div>
<div class="MsoNormal">
<o:p>Now we want to test what happens when we backup and restore a copy of the RW data. We don't want to have to deal w/ the RO data</o:p></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Backup rw <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">READ_WRITE_FILEGROUPS
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RW2.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore RW <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RW2.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<o:p> </o:p><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Verify (should succeed)</span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- check filegroups. especially
state_desc<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">where</span><span style="font-family: 'Courier New'; font-size: 10pt;">
database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name <span style="color: grey;">=</span> <span style="color: red;">'TestDB2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p>Now we set another file to RO</o:p></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- set FG 3 to read only<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ALTER</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <span style="color: blue;">MODIFY</span>
<span style="color: blue;">FILEGROUP</span> [TestDB_Part3] <span style="color: blue;">READONLY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p>You may be tempted to just send the RO backup over but you need to send a new backup of the PRIMARY FG w/ the meta data about the RO FG. So we backup RW and the new RO and send them over.</o:p></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Backup rw <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">READ_WRITE_FILEGROUPS
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RW3.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- backup new RO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'TestDB_Part3'</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RO_Part3.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p>We start our restore w/ the RW and expect the verification to fail bc it is missing filegroups.</o:p></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore RW<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RW3.bak'</span> <span style="color: blue;">WITH</span> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">PARTIAL</span><span style="color: grey;">,</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Verify (should fail)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- check filegroups. especially
state_desc<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">where</span><span style="font-family: 'Courier New'; font-size: 10pt;">
database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name <span style="color: grey;">=</span> <span style="color: red;">'TestDB2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Restore your 'new' RO file and you may expect this to be enough (but you would be wrong)</div>
<br />
<br />
<br />
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part3'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RO_Part3.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part3.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Verify (should fail)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- check filegroups. especially
state_desc<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">where</span><span style="font-family: 'Courier New'; font-size: 10pt;">
database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name <span style="color: grey;">=</span> <span style="color: red;">'TestDB2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p>If you notice, Partition 2 is still recovery pending. But wasn't it there already? Well, yes, you just have to tell SQL server it is in a good state. Note that you could (if you wanted to waste IO) restore partition 2 from backup instead.</o:p></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- bring FG 2 online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <span style="color: blue;">FILEGROUP</span><span style="color: grey;">=</span><span style="color: red;">'TestDB_Part2'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">WITH</span> <span style="color: blue;">RECOVERY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Verify (should succeed)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- check filegroups. especially
state_desc<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">where</span><span style="font-family: 'Courier New'; font-size: 10pt;">
database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name <span style="color: grey;">=</span> <span style="color: red;">'TestDB2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p>One more runthrough of setting a FG RO and restoring it.</o:p></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- set FG 4 to read only<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">ALTER</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <span style="color: blue;">MODIFY</span>
<span style="color: blue;">FILEGROUP</span> [TestDB_Part4] <span style="color: blue;">READONLY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- Backup rw <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">READ_WRITE_FILEGROUPS
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RW4.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- backup new RO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">BACKUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'TestDB_Part4'</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">TO</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RO_Part4.bak'</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">WITH</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOFORMAT</span><span style="color: grey;">,</span> <span style="color: blue;">INIT</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SKIP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">NOREWIND</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--restore RW<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RW4.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">PARTIAL</span><span style="color: grey;">,</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">recovery<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Verify (should fail)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- check filegroups. especially
state_desc<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">where</span><span style="font-family: 'Courier New'; font-size: 10pt;">
database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name <span style="color: grey;">=</span> <span style="color: red;">'TestDB2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- bring FG 2, 3 online<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">'TestDB_Part2'</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FILEGROUP</span><span style="color: grey; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">'TestDB_Part3'<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">WITH</span> <span style="color: blue;">RECOVERY<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Verify (should fail)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <span style="color: blue;">where</span> database_id <span style="color: grey;">=</span>
13<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part4'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RO_Part4.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part4.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Verify (should succeed)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- check filegroups. especially
state_desc<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">where</span><span style="font-family: 'Courier New'; font-size: 10pt;">
database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name <span style="color: grey;">=</span> <span style="color: red;">'TestDB2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p><br /></o:p></div>
<div class="MsoNormal">
<o:p>And finally, a quick run through of a complete restore from scratch. Note that this uses the excellent usp_killconnections from <a href="http://www.sqlservercentral.com/scripts/Lock+and+Connection+Management/31966/">here</a>.</o:p></div>
<div class="MsoNormal">
<o:p><br /></o:p></div>
<br />
<br />
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- disaster recovery<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">drop</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">database</span> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">exec</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master</span><span style="color: grey;">.</span>dbo<span style="color: grey;">.</span>usp_killconnections<span style="color: blue;"> </span>[TestDB2]<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RW<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2] <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">read_write_filegroups<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">FROM</span> <span style="color: blue;">DISK</span> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RW4.bak'</span> <span style="color: blue;">WITH</span> <span style="color: blue;">PARTIAL</span><span style="color: grey;">,</span> <span style="color: blue;">FILE</span> <span style="color: grey;">=</span> 1<span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part1'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part1.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part2.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part3.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part4.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_Part5'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part5.mdf'</span><span style="color: grey;">,</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">MOVE</span> <span style="color: red;">N'TestDB_log'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_log.ldf'</span><span style="color: grey;">,</span>
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: magenta;">REPLACE</span><span style="color: grey;">,</span> <span style="color: blue;">NOUNLOAD</span><span style="color: grey;">,</span> <span style="color: green;">STATS</span> <span style="color: grey;">=</span> 10<span style="color: grey;">,</span> <span style="color: blue;">recovery<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part2'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RO_Part2.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part2'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part2.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part3'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RO_Part3.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part3'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part3.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- restore RO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">master<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">RESTORE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">DATABASE</span> [TestDB2]
<span style="color: blue;">FILEGROUP</span> <span style="color: grey;">=</span>
<span style="color: red;">'TestDB_Part4'</span>
<span style="color: blue;">FROM</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">DISK</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">=</span> <span style="color: red;">N'D:\data\TestDB_RO_Part4.bak'</span> <span style="color: blue;">WITH</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">MOVE</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: red;">'TestDB_Part4'</span> <span style="color: blue;">TO</span> <span style="color: red;">N'D:\data\TestDB2_Part4.mdf'<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">--- Verify (should succeed)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">use</span><span style="font-family: 'Courier New'; font-size: 10pt;"> testdb2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">SELECT</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">FROM</span><span style="font-family: 'Courier New'; font-size: 10pt;"> TestTable<span style="color: grey;">;<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">GO<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: 'Courier New'; font-size: 10pt;">-- check filegroups. especially
state_desc<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">select</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">master_files</span> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">where</span><span style="font-family: 'Courier New'; font-size: 10pt;">
database_id <span style="color: grey;">=</span><span style="color: blue;"> </span><span style="color: grey;">(</span><span style="color: blue;">select</span> database_id <span style="color: blue;">from</span> <span style="color: green;">sys</span><span style="color: grey;">.</span><span style="color: green;">databases</span> <span style="color: blue;">where</span> name <span style="color: grey;">=</span> <span style="color: red;">'TestDB2'</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
Good luck!</div>
<br />
<br />
<br /></div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com2tag:blogger.com,1999:blog-10074565.post-52425961210466303062012-02-07T13:45:00.000+00:002012-02-07T13:51:32.993+00:00Offline Access to sharepoint wiki<div dir="ltr" style="text-align: left;" trbidi="on">
We have an issue here where we have a lot of Ops documentation in a sharepoint wiki. This includes documentation on how to get sharepoint running and other emergency procedures. The problem is, if the sharepoint instance is down, we don't have access to our docs. Here is a simple script that will dump all the wiki pages to html pages in a directory. The links won't work but at least you have the text. This is sufficient for our purposes, please let me know if you extend it.<br />
<br />
The script needs to run on the sharepoint server (or somewhere it can source the libraries). It grabs each item and basically dumps the div that is the body of your wiki page. <br />
<br />
blogspot is having trouble urlencoding the tags below so you may want to fix the H1 tags in the body at the end of the script.<br />
<br />
<div class="MsoNormal">
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$uri</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"http://SHAREPOINT/sites/wiki"</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$list</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Wiki
Pages"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$outputDir</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"\\server\backups\Wiki"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$site</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">New-Object</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">Microsoft.SharePoint.SPSite</span><span style="font-family: 'Courier New'; font-size: 10pt;">(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$uri</span><span style="font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$web</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$site</span><span style="font-family: 'Courier New'; font-size: 10pt;">.openweb()<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$list</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$web</span><span style="font-family: 'Courier New'; font-size: 10pt;">.lists[</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$list</span><span style="font-family: 'Courier New'; font-size: 10pt;">]<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> 0<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"exporting
to: $outputDir"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$page</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$list</span><span style="font-family: 'Courier New'; font-size: 10pt;">.Items) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">xml</span><span style="font-family: 'Courier New'; font-size: 10pt;">]</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$objXML</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$page</span><span style="font-family: 'Courier New'; font-size: 10pt;">.xml<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$body</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$objXML</span><span style="font-family: 'Courier New'; font-size: 10pt;">.row.ows_WikiField<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$title</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$page</span><span style="font-family: 'Courier New'; font-size: 10pt;">.DisplayName<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"creating File $i : $title"</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$body</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"< H1 > $title < / H1 ></span><span style="color: maroon;">"</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$body</span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$body</span><span style="font-family: 'Courier New'; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Out-File</span></b><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-FilePath</span></i><span style="font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"$outputDir\$title.html"</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
</div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0tag:blogger.com,1999:blog-10074565.post-82653664820764485572012-01-27T11:59:00.000+00:002012-07-26T17:23:48.234+00:00ccmexec crashing on windows 2008 r2<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: red;">UPDATE</span>: looks like MS caved and released a hotfix. I have not tried it yet, please let me know if you do and if it solves this problem: <a href="http://support.microsoft.com/kb/2724939/en-us">http://support.microsoft.com/kb/2724939/en-us</a><br />
<br />
<div class="MsoNormal">
Hey all,<o:p></o:p></div>
<div class="MsoNormal">
I have been tracking an issue for some time. I have no fix but some things are becoming clear and I just found a good way to scope the problem, hence this post…<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
I am running Systems Center Configuration Manager 2007 SP2 R2 and I have been getting this error on some seemingly random set of my windows 2008 r2 servers:<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Log Name: Application<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Source: Application Error<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Date: 1/27/2012 5:52:09 AM<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Event ID: 1000<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Task Category: (100)<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Level: Error<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Keywords: Classic<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
User: N/A<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Computer: xxxxxxxxxxxxxxxxx<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Description:<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Faulting application name: CcmExec.exe, version: 4.0.6487.2000, time stamp: 0x4ab33e4d<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Faulting module name: ntdll.dll, version: 6.1.7601.17514, time stamp: 0x4ce7ba58<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Exception code: 0xc0000005<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Fault offset: 0x0009ce04<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Faulting process id: 0x1d58<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Faulting application start time: 0x01ccdcd93adaa8bf<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Faulting application path: C:\Windows\SysWOW64\CCM\CcmExec.exe<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Faulting module path: C:\Windows\SysWOW64\ntdll.dll<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: 0.5in;">
Report Id: f570d39f-48d4-11e1-b96c-6431504ea6e0<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Notes from <a href="http://t3chn1ck.wordpress.com/2010/11/12/sccm-2007-client-crashes-on-win2k8-r2/">this page</a> and especially the german write up <a href="http://www.markus-tech-blog.de/2011/11/29/configmgr2007-agent-sturzt-stundlich-ab/">here</a> (translation <a href="http://www.microsofttranslator.com/bv.aspx?ref=Internal&from=de&to=en&a=http://www.markus-tech-blog.de/2011/11/29/configmgr2007-agent-sturzt-stundlich-ab/">here</a>) were very helpful. To briefly summarize, when you run resource explorer, you create an ETS performance trace called: WDC.BE95A9B1-DE15-4B78-B923-A12AB70BE951. You can verify this by running ‘logman query –ets’ or in server manager -> Diagnostics -> Performance -> Data Collector Sets -> Event Trace Sessions.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Apparently the sccm client dislikes this trace and will crash, in my case every 65 minutes. Stopping the trace reportedly fixes it, I am still testing before I fully believe that. I have not found it necessary to reboot/reinstall etc as are suggested elsewhere. Stopping the trace will kill your Resource Monitor.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Next step would be looking into the trace to see if it is possible to adjust the trace. Word is MS is refusing to fix it.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The only thing I have to add is that I am seeing a status message of 669 (2 in fact) each time this happens. So in order to determine which machines this is happening on, run the report <b>Status Messages -> All messages for a specific message ID</b> and query for message ID <b>669</b>. Exported to excel (so I could mask server/site names more easily), it looks like this:<o:p></o:p></div>
<table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; margin-left: -0.75pt; width: 781px;"><tbody>
<tr style="height: 14.25pt;"><td style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: black; border-bottom-style: double; border-bottom-width: 2.25pt; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: black; border-top-style: double; border-top-width: 2.25pt; height: 14.25pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="bottom" width="91"><div class="MsoNormal">
<b><span style="color: darkred; font-family: Tahoma, sans-serif;">Record ID<o:p></o:p></span></b></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: black; border-bottom-style: double; border-bottom-width: 2.25pt; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: black; border-top-style: double; border-top-width: 2.25pt; height: 14.25pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="bottom" width="78"><div class="MsoNormal">
<b><span style="color: darkred; font-family: Tahoma, sans-serif;">Severity<o:p></o:p></span></b></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: black; border-bottom-style: double; border-bottom-width: 2.25pt; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: black; border-top-style: double; border-top-width: 2.25pt; height: 14.25pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="bottom" width="102"><div class="MsoNormal">
<b><span style="color: darkred; font-family: Tahoma, sans-serif;">Message ID<o:p></o:p></span></b></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: black; border-bottom-style: double; border-bottom-width: 2.25pt; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: black; border-top-style: double; border-top-width: 2.25pt; height: 14.25pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="bottom" width="120"><div class="MsoNormal">
<b><span style="color: darkred; font-family: Tahoma, sans-serif;">Component<o:p></o:p></span></b></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: black; border-bottom-style: double; border-bottom-width: 2.25pt; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: black; border-top-style: double; border-top-width: 2.25pt; height: 14.25pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="bottom" width="138"><div class="MsoNormal">
<b><span style="color: darkred; font-family: Tahoma, sans-serif;">Computer Name<o:p></o:p></span></b></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: black; border-bottom-style: double; border-bottom-width: 2.25pt; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: black; border-top-style: double; border-top-width: 2.25pt; height: 14.25pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="bottom" width="156"><div class="MsoNormal">
<b><span style="color: darkred; font-family: Tahoma, sans-serif;">Time<o:p></o:p></span></b></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-color: black; border-bottom-style: double; border-bottom-width: 2.25pt; border-left-color: initial; border-left-style: none; border-left-width: initial; border-right-color: initial; border-right-style: none; border-right-width: initial; border-top-color: black; border-top-style: double; border-top-width: 2.25pt; height: 14.25pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="bottom" width="96"><div class="MsoNormal">
<b><span style="color: darkred; font-family: Tahoma, sans-serif;">Site Code<o:p></o:p></span></b></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012608<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SCCM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 6:15:46 AM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC2<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012605<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--WEB3<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 6:08:23 AM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012607<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--WEB3<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 6:08:23 AM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012602<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--WEB2<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:51:38 AM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012604<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--WEB2<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:51:38 AM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012601<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SQLA2<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:50:07 AM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012603<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SQLA2<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:50:07 AM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012599<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--WEB1<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:44:05 AM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC2<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012600<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--WEB1<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:44:05 AM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC2<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012596<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SQLA1<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:32:24 AM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012598<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SQLA1<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:32:24 AM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012591<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SQLA2<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:24:14 AM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC2<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012593<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SQLA2<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:24:14 AM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC2<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012590<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SQLB1<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:21:40 AM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012592<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SQLB1<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:21:40 AM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012584<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SCCM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:10:17 AM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC2<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012585<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--SCCM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:10:17 AM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC2<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012577<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--WEB3<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:02:27 AM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012583<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--WEB3<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 5:02:27 AM<o:p></o:p></span></div>
</td><td style="border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
<tr style="height: 12.75pt;"><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 68.25pt;" valign="top" width="91"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1012574<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 58.8pt;" valign="top" width="78"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Error<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 76.2pt;" valign="top" width="102"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">669<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1.25in;" valign="top" width="120"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">Advanced Client<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 103.5pt;" valign="top" width="138"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SERVER--WEB2<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 117pt;" valign="top" width="156"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">1/27/2012 4:45:50 AM<o:p></o:p></span></div>
</td><td style="background-attachment: initial; background-clip: initial; background-color: gainsboro; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-color: initial; border-image: initial; border-left-style: none; border-right-style: none; border-top-style: none; border-width: initial; height: 12.75pt; padding-bottom: 0in; padding-left: 5.4pt; padding-right: 5.4pt; padding-top: 0in; width: 1in;" valign="top" width="96"><div class="MsoNormal">
<span style="font-family: Tahoma, sans-serif; font-size: 10pt;">SC1<o:p></o:p></span></div>
</td></tr>
</tbody></table>
<div class="MsoNormal">
<br /></div>
According to the ever handy <a href="http://www.systemcentercentral.com/BlogDetails/tabid/143/IndexID/84135/Default.aspx">SystemCenterCentral</a>:<o:p></o:p><br />
<b><span style="font-family: Arial, sans-serif;">Message ID 669:</span></b><span class="apple-converted-space"><span style="font-family: Arial, sans-serif;"> </span></span><span style="font-family: Arial, sans-serif;">This message is caused when SCCM component raised an exception but failed to handle it. We should further investigate this problem.</span><span style="font-size: 13.5pt;"><o:p></o:p></span><br />
<div class="MsoNormal">
So this could easily be from something else but this crash seems to be the primary (only) error I am seeing in my sites that is sending this message.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Please respond if you have any more details to add…<o:p></o:p><br />
<br />
Update: Feb 1, 2012. It looks like we are not getting any fixes to this in sccm 2007. It is fixed in 2012 and, despite the product not being released, MS has decided this is good enough. The options are to not run resource manager, accept the crashes, or (if you don't care about asset intelligence and CAL reports), to rename %WINDIR%\syswow64\ccm\ccm_caltrack.dll to ccm_caltrack.ThisFileSux. I have done this to a few machines and it seems to solve the problem.</div>
<div class="MsoNormal">
<br /></div>
<br class="Apple-interchange-newline" /></div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com1tag:blogger.com,1999:blog-10074565.post-35843670781335085882011-10-25T15:54:00.000+00:002011-10-25T16:01:07.414+00:00Exporting songs in Windows Media Player by star rating<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="WordSection1">
<div class="MsoNormal">
So, I used <a href="http://cornasdf.blogspot.com/2007/05/moving-from-itunes-to-wmp-11.html"> this</a> some forever ago to move song ratings from iTunes to Windows Media Player with a powershell function. Now I wanted to export the ratings to a file so I have that list outside of wmp. Annoyingly, i didn't see a way to export the song list, saving the playlist just saved the search terms. Meh, powershell to the rescue, yet again...<br />
<br />
This function will export the name of all files w/ ‘-starcount’ stars. Could be trivially modified to export other details.<br />
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">function</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">get-playlistbyStars</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">param</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$starcount</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> $(</span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">throw</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"need -starcount"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> )<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#get WMP<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$wmp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">New-object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">-COM</span></i><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">WMPlayer.OCX</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$WMPLibrary</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$wmp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.mediaCollection<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#set vars<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$rated</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$processed</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$added</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$unrated</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0 <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$1star</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0 <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$2star</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0 <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$3star</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0 <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$4star</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0 <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$5star</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0 <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$defstar</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ctr</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$allsongs</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$WMPLibrary</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.getall()<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colOut</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> @()<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">for</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0; </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-lt</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$allsongs</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.count; </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">++) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$processed</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$song</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$allsongs</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Item(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (@(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">".jpg"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">".png"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-notcontains</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> ([</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">System.IO.FileInfo</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">]</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$song</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.sourceURL).Extension ) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">switch</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$song</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.getiteminfo(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"UserRating"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"0"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$unrated</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$starcount</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colOut</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$song</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.sourceURL<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> } <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"1"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$1star</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$rated</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$starcount</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 1) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colOut</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$song</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.sourceURL<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"25"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$2star</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$rated</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$starcount</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 2) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colOut</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$song</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.sourceURL<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"50"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$3star</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$rated</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$starcount</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 3) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colOut</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$song</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.sourceURL<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"75"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$4star</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$rated</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$starcount</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 4) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colOut</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$song</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.sourceURL<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"99"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$5star</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$rated</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$starcount</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 5) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colOut</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$song</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.sourceURL<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">default</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#so I have something to query for random nums<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$defstar</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$starcount</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 42) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colOut</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$song</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.sourceURL<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#so I have something to watch<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ctr</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">++</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ctr</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">%</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">500 </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0) { </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-verbose</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ctr</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px;"> }</span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#output results<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-verbose</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Processed: $processed"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-verbose</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Rated: $rated"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-verbose</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Added: $added"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-verbose</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"1: $1star "</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-verbose</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"2: $2star "</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-verbose</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"3: $3star"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-verbose</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"4: $4star "</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-verbose</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"5: $5star"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-verbose</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"def: $defstar"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colOut</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">get-playlistbyStars</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 3 | out-file –filepath .\3starsongs.txt<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<br /></div>
</div>
</div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0tag:blogger.com,1999:blog-10074565.post-49821439225299296762011-10-14T13:29:00.002+00:002011-10-25T15:58:40.714+00:00SQL and Powershell: Attach all database mdf files in a directory<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="WordSection1">
<div class="MsoNormal">
<span class="apple-style-span"><span style="color: black; font-family: Arial, sans-serif;">Hey all, </span></span><span style="color: black; font-family: 'Trebuchet MS', sans-serif;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 12.0pt;">
<span class="apple-style-span"><span style="color: black; font-family: Arial, sans-serif;">I didn’t find this elsewhere on the web and I needed it. Since I actually had to do work, i figure I should give it out and spare somebody else that pain. </span></span><span style="color: black; font-family: 'Trebuchet MS', sans-serif;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 12.0pt;">
<span class="apple-style-span"><span style="color: black; font-family: Arial, sans-serif;">As part of a failover plan, I am synchronizing directories of sql files. In a failover, I am going to need to bring up a group of databases in a specific directory. The script below will take in a directory name and a SQL instance. It will get all the .mdf files in the directory and compare them against the database files attached to the SQL instance. Any files that are not attached already are attached, extrapolating the filename from the .mdf file. The MAJOR ASSUMPTION here is that you want to name your Database the same name as the .mdf file (without the .mdf). Several of my dbs have multiple files so I read the .mdf to get all the files it knows about. Another major ASSUMPTION is that you are replicating to/attaching from the same file paths on your new server.</span></span><span style="color: black; font-family: 'Trebuchet MS', sans-serif;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span class="apple-style-span"><span style="color: black; font-family: Arial, sans-serif;">I use my <a href="http://cornasdf.blogspot.com/2009/06/powershell-standard-logging-function.html">out-log function</a>. if you don’t want to use it, replace out-log with write-host in the below script.</span></span><span class="apple-style-span"><span style="color: blue; font-family: 'Courier New';"> </span></span><span style="color: black; font-family: 'Trebuchet MS', sans-serif;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">function</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">AttachMDFsInDir</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">param</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$dir</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> $( </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">throw</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Must specify -dir"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> ),<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$instance</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> $( </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">throw</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Must specify -instance"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> ),<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$verbosity</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 1 </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;"># for the out-log function. <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> )<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">out-log</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Starting AttachMDFsInDir with dir: $dir and inst: $instance"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$srv</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">new-Object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">Microsoft.SqlServer.Management.Smo.Server</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$instance</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> out-log </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Connected to $($srv.Name)"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#get a list of all attached database file names<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colAttachedMDFs</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> @()<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$db</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$srv</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Databases ) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$fg</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$db</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Filegroups) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$file</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$fg</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Files) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> out-log </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Adding to `$colattachedMDFs: $($file.Filename)"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 2<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colAttachedMDFs</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$file</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Filename<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> out-log </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Found $($colAttachedMDFs.count) mdfs attached in $instance"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#foreach mdf in $groupSQLDir<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colMDFsToAttach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> @()<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$mdf</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">dir</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"$dir\*.mdf"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-not</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colAttachedMDFs</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-contains</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$mdf</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> out-log </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Adding to `$colMDFsToAttach: $($mdf.Fullname)"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 2<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colMDFsToAttach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$mdf</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.FullName<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Remove-Variable</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">mdf</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Remove-Variable</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">file</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> out-log </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Found $($colMDFsToAttach.count) mdf(s) in the directory that are unattached"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$mdf</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colMDFsToAttach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#determine name to restore as from mdf file name.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DBNameFromFile</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> ([</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">System.IO.FileInfo</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">]</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$mdf</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">).Basename<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">out-log</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Named the db $DBNameFromFile based on the mdf: $mdf"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#get list of files<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colDBFiles</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$srv</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.EnumDetachedDatabaseFiles(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$mdf</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> out-log </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"$mdf specifies $($coldbfiles.count) files to attach."</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> out-log </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colDBFiles</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 2<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#add to collection<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$files</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">new-object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">system.collections.specialized.stringcollection</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$file</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colDBFiles</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$files</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Add(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$file</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">out-log</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Ready to attach db: $DBNameFromFile w/ $($files.count) files."</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#attach database<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$srv</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.AttachDatabase(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DBNameFromFile</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$files</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Trebuchet MS', sans-serif;">As a corollary to the above, i needed to check which of my dbs on the running servers did not have the same name as their .mdf. you can use this loop.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$instances</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> @(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"SERV\Inst1","Serv\INST2")</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> )<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$instance</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$instances</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$srv</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">new-Object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">Microsoft.SqlServer.Management.Smo.Server</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$instance</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">""</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"------------------------"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$srv</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Name<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"------------------------"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$db</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$srv</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Databases ) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$fg</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$db</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Filegroups) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$file</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$fg</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Files) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Fileinf</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">System.IO.FileInfo</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">]</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$file</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.filename<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Fileinf</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.extension </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">".mdf"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> ) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Fileinf</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.BaseName </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$db</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.name) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#"File: $($Fileinf.Basename) matches $($db.name)"<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> } </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">else</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Filename: $($Fileinf.Basename) DOES NOT MATCH DB Name: $($db.name)"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<o:p> </o:p><span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px;">}</span></div>
<div class="MsoNormal">
<br /></div>
</div>
</div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com1tag:blogger.com,1999:blog-10074565.post-63662133287212804812011-06-28T11:23:00.004+00:002011-06-28T11:24:58.613+00:00SCCM Child Primary site not replicating Update lists or deployments<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal">We ran across an issue this weekend with one of our SCCM child primary sites not replicating deployments or software update lists correctly. 2 of 3 primary sites were replicating fine but one primary was not getting new items. For this article, I will represent my central site as CEN and the non working primary site as PRI (imaginative, I know).<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">After several hours with the configuration manager logs, I had pretty much tracked it down to bad configuration items (patches) but I was stuck on what to do after trying various sync options, mostly detailed here: <a href="http://blogcastrepository.com/blogs/brian_tucker/archive/2009/06/18/how-to-resolve-site-replication-issues-with-sccm-2007-sp1-r2.aspx">http://blogcastrepository.com/blogs/brian_tucker/archive/2009/06/18/how-to-resolve-site-replication-issues-with-sccm-2007-sp1-r2.aspx</a>.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal">I called MS support and he gave me a set up queries to help figure out what was going on. <o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">At the end of the day, the problem can be seen in objreplmgr.log and you see sets of lines like:<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="margin-left: .5in;">Processing replication file C:\Program Files\Microsoft Configuration Manager\inboxes\objmgr.box\INCOMING\Retry\CEN_48964.CID in retry. SMS_OBJECT_REPLICATION_MANAGER 6/27/2011 9:42:31 AM 5640 (0x1608)<o:p></o:p></div><div class="MsoNormal" style="margin-left: .5in;">Referenced configuration items are not available yet: http://schemas.microsoft.com/systemsmanagementserver/<span class="Apple-style-span" style="color: red;">Site_A4F5CBC7-3D34-4DC1-A024-C496694647C5/SUM_914207c8-1e32-4e4e-acee-7ebdce4568b2</span>/2(2)(6); SMS_OBJECT_REPLICATION_MANAGER 6/27/2011 9:42:31 AM 5640 (0x1608)<o:p></o:p></div><div class="MsoNormal" style="margin-left: .5in;">Failed to insert Object e5c2a931-5c7c-4c0b-843a-343525f73e3d from replication file C:\Program Files\Microsoft Configuration Manager\inboxes\objmgr.box\INCOMING\Retry\CEN_48964.CID. SMS_OBJECT_REPLICATION_MANAGER 6/27/2011 9:42:31 AM 5640 (0x1608)<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Note the unique package name highlighted in red above. This is the key string. <o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">We did do an ‘attempt 1’ that was unsuccessful but may be worth trying. In this, we extract just the GUID of the CI and update the date in the CEN database and hope it replicates down. Get the GUID from the highlighted string above as everything after the SUM_. In our case it would be <span style="color: red;">914207c8-1e32-4e4e-acee-7ebdce4568b2</span>. In the query below, we have multiple CIs identified, you can put as many as you want in the query (gathered from different log lines).<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="margin-left: .5in; text-autospace: none;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">Update ci_configurationitems<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in; text-autospace: none;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">set datelastmodified = getdate()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in; text-autospace: none;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">where ci_uniqueid in (‘</span><span style="color: red;">914207c8-1e32-4e4e-acee-7ebdce4568b2</span>’<span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">,'</span> c4fca437-b931-48fc-a6bf-6cc7d0aefc2d’<span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">)<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">This didn’t do anything useful in our case so we continued on to ‘Attempt 2’.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">If you take your whole string and do a select in your SCCM database on both the primary and the central sites:<o:p></o:p></div><div class="MsoNormal" style="text-autospace: none; text-indent: .5in;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">SELECT * FROM ci_sdmpackages where SDMPackageName in (‘</span><span style="color: red;">Site_A4F5CBC7-3D34-4DC1-A024-C496694647C5/SUM_914207c8-1e32-4e4e-acee-7ebdce4568b2</span><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">’)<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Take note of the isDeleted and the SDMPackageVersion columns. For me, 95% of the items showing up in the logs were showing up as deleted in CEN but not in PRI. This can be fixed by running an update like:<o:p></o:p></div><div class="MsoNormal" style="margin-left: .5in; text-autospace: none;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">update ci_sdmpackages<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in; text-autospace: none;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;"> set Isdeleted = 1<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .5in;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;"> where SDMPackageName = '</span><span style="color: red;"> Site_A4F5CBC7-3D34-4DC1-A024-C496694647C5/SUM_914207c8-1e32-4e4e-acee-7ebdce4568b2</span><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">’ and SDMPackageVersion = '3'<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Note that you will change the GUID and the SDMPackage version. You want to update your PRI site to match CEN.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">One your DB is updated, you can move your replication file as ID’d above (CEN_48964.CID in this case) from the objmgr.box\incoming\retry to objmgr.box\incoming. Watch your objreplmgr.log for success.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Now, that worked but I had 110 CIDs to work through and I heartily ascribe to larry wall’s <a href="http://en.wikipedia.org/wiki/Larry_Wall#Virtues_of_a_programmer">3 virtues</a>. in order to shorten my workload a bit, this is how I did it. I didn’t have any good way to communicate between sites, unfortunately. If I did, I would have done this much more directly. I was on a bit of a deadline to get this up so I went for speed over elegance.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">1.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span>Get all the guids. I ran the following against the objreplmgr.log to pull out just my relevant configuration item IDs. I ran this against a copy w/ just one run of ‘failures’ initially but we do sort out unique so you can probably just run it against the real thing.<o:p></o:p></div><div class="MsoNormal" style="margin-left: .5in;"><br />
</div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$a</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">get-content</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> .\</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">objreplmgr.log</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">where</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$_</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-match</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Referenced configuration items are not available"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ciList</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> @()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">Foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$line</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$a</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$line</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-match</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">".*(Site_.*/SUM_.*?)/.*"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ciList</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Matches</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">[1]<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">2.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span>I tried to strip out duplicates. On my first run this only saved 2 items, next run saved me much more. If you run against the whole log, this is more important.<o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ciListSorted</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ciList</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">sort</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">–Unique<o:p></o:p></span></i></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">3.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span>Create my sql query:<o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$sqlQuery</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"SELECT * FROM ci_sdmpackages where SDMPackageName in ("</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">for</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">0; </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-lt</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ciListSorted</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.length </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 1; </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">++) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$sqlQuery</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"'$($ciListSorted[$i])', "</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$sqlQuery</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"'$($ciListSorted[$ciListSorted.Length-1])')"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;"><span style="color: black; font-family: 'MS Shell Dlg 2', sans-serif; font-size: 8.5pt;">4.<span style="font: normal normal normal 7pt/normal 'Times New Roman';"> </span></span>Run the sql query against both databases. I have this function in my standard library that I stole some time ago:<o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">function</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">query-SQL</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">param</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">(<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DBInstance</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">,<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Datatabase</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">,<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Query</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlConnection</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">New-Object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">System.Data.SqlClient.SqlConnection</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlConnection</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.ConnectionString </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Server = $DBInstance; Database =$Database; Integrated Security = True"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlCmd</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">New-Object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">System.Data.SqlClient.SqlCommand</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlCmd</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.CommandText </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$Query</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlCmd</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Connection </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlConnection</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlAdapter</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">New-Object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">System.Data.SqlClient.SqlDataAdapter</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlAdapter</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.SelectCommand </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlCmd</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DataSet</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">New-Object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">System.Data.DataSet</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlAdapter</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Fill(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DataSet</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SqlConnection</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Close()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DataSet</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Tables<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><br />
</div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;">Run against my Primary database<o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><br />
</div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">colPRI</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> query-SQL -Datatabase </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$database</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> -DBInstance </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$dbinstance</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> -Query </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$sqlQuery</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PRI</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> @()<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">Foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$line</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colPRI</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">[1]) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PRI</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"PRI,$($line.isDeleted),$($line.SDMPackageName),$($line.SDMPackageVersion)"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PRI</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> > </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">PRI.csv</span><o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><br />
</div><div class="MsoNormal" style="text-indent: .25in;">For the CEN site, I manually copied the sql query over w/ <o:p></o:p></div><div class="MsoNormal" style="text-autospace: none; text-indent: .25in;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$sqlQuery</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Out-File</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">sqlquery.txt</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-indent: .25in;"><br />
</div><div class="MsoNormal" style="text-indent: .25in;">Created the text file on the other side and brought it back in and ran it like so:<o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$sqlquery</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Get-Content</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> .\</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">sqlquery.txt<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><br />
</div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colCEN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> query-SQL -Datatabase </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$database</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> -DBInstance </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$dbinstance</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> -Query </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$sqlQuery</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CEN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> @() <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">Foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$line</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$colCEN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">[1]) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CEN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"CEN,$($line.isDeleted),$($line.SDMPackageName),$($line.SDMPackageVersion)"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CEN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> > </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">CEN.csv</span><o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal" style="text-indent: .25in;">Then, I brought my CEN.csv back over to PRI and brought it back to my powershell env.<o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal" style="margin-left: .25in;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CEN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Get-Content</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> .\</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">cen.csv<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal" style="margin-left: .25in;">Now we have $CEN and $PRI that are effectively .csv files in a variable. Check your lengths, do some spot verification that they are the same length and have the same IDs in the same order, etc. We did sort them above and everything should be fine and loop below does some checking but, well, defense in depth. Did you remember to back up your databases? Not my problem if not.<o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal" style="text-indent: .25in;">This loop spins through your two arrays and sets the PRI database to match what is in the CEN database. Note the query-sql line, you will need $database and $DBInstance defined already. <o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">for</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0; </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-lt</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PRI</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.length </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">1; </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">++) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$site</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CenIsDel</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CenID</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CenVersion</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CEN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">[</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">].split(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">","</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$site</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PriIsDel</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PriID</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">,</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PriVersion</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PRI</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">[</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">].split(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">","</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CenIsDel</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"True"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) { </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CenIsDel</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">1 } </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">else</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> { </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CenIsDel</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PriIsDel</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"True"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) { </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PriIsDel</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">1 } </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">else</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> { </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PriIsDel</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: green; font-family: 'Courier New'; font-size: 10pt;">#Make sure our lines are the same<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-not</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CenID</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PriID</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">throw</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"iteration $i, $CenID not equal to $PriID"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> ((</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PriIsDel</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-ne</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CenIsDel</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-or</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$PriVersion</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-ne</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$CenVersion</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)) {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$query</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"update ci_sdmpackages set Isdeleted = $CenIsDel where SDMPackageName = '$CenID' and SDMPackageVersion = '$CenVersion'"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Setting $PriID to $CenisDel and $CenVersion"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> query-sql -database </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$database</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> -dbinstance </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$dbinstance</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> -query </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$query</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> } </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">else</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"$PriId already matches central"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in; text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="text-indent: .25in;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal">After this, I dropped all the files from objmgr.box\incoming\retry back into objmgr.box\incoming. Success! Well, mostly. I still had about 8 bad CIDs. Looking in the log, some of them were due to lines that had two CIs mentioned. <o:p></o:p></div><div class="MsoNormal" style="margin-left: .5in;">Referenced configuration items are not available yet: <a href="http://schemas.microsoft.com/systemsmanagementserver/Site_A4F5CBC7-3D34-4DC1-A024-C496694647C5/SUM_40d3d142-5ea7-463c-a7c1-">http://schemas.microsoft.com/systemsmanagementserver/Site_A4F5CBC7-3D34-4DC1-A024-C496694647C5/SUM_40d3d142-5ea7-463c-a7c1-</a><span style="color: red;">9d34cdd5a7fc</span>/1(1)(6);http://schemas.microsoft.com/systemsmanagementserver/<span style="color: red;">Site_A4F5CBC7-3D34-4DC1-A024-C496694647C5/SUM_c4fca437-b931-48fc-a6bf-6cc7d0aefc2d</span>/1(1)(6);<o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal">My regex only accounts for 1. Rather than figure out a better regex, I ran through the steps above again I gathered the 3 CIs that I had that were specified as the second on a line. Then I ran through the steps above and manually added my 3 CIs to the <span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ciList</span>, when I was at that step. Moved the \retry items back into the box and all were consumed successfully. Gave it about 15 minutes and site replication is working again. W00t!<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-indent: .5in;"> <o:p></o:p></div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div><div class="MsoNormal" style="margin-left: .25in;"><br />
</div></div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0tag:blogger.com,1999:blog-10074565.post-48909309799850942642011-05-13T09:16:00.003+00:002011-06-28T19:43:48.756+00:00Using SQL and Powershell to set Extended Properties<div dir="ltr" style="text-align: left;" trbidi="on"><div class="WordSection1"><div class="MsoNormal">I searched around for a bit and didn’t find this anywhere easy so I banged it out myself. Hope this helps somebody to set an extended property on one of your SQL Objects using Powershell.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Assume you want to set a property on a database. If you don’t have your SQL psdrive loaded you can add it (assuming you have the prereqs) with:<o:p></o:p></div><div class="MsoNormal"><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">add-pssnapin</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">SqlServerProviderSnapin100</span><o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">The name of your property will be “TestName” and you want a value of “TestValue”.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">You will need your DB as an object. If you have your SQL PSDrive you can use:<o:p></o:p></div><div class="MsoNormal"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DBObject</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Get-Item</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> SQLSERVER:\SQL\SERVERNAME\INSTANCE\Databases\</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DBName</span> <o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">First, you create your new ExtendedProperty Object: <o:p></o:p></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ExtProp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">new-object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">Microsoft.SqlServer.Management.Smo.ExtendedProperty</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Then you need to designate what object you are attaching your new property to:<o:p></o:p></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ExtProp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Parent </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DBObject</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Set your Name and Value:<o:p></o:p></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ExtProp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Name </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"TestName"</span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ExtProp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Value </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"TestValue"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Finally, create the object. This seems to be more like applying it to me:<o:p></o:p></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ExtProp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Create()<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Full list:<o:p></o:p></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DBObject</span></span><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span></span><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small;"><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span></span><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span></span><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small;"><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Get-Item</span></b></span><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> SQLSERVER:\SQL\SERVERNAME\INSTANCE\Databases\</span></span><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DBName</span></span></span><br />
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;"></span></span>$ExtProp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">new-object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">Microsoft.SqlServer.Management.Smo.ExtendedProperty</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ExtProp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Parent </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$DBObject</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><br />
<div class="MsoNormal"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ExtProp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Name </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"TestName"</span></div></div><div class="MsoNormal"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ExtProp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Value </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"TestValue"</span></div></div></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ExtProp</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Create()<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div></div></div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0tag:blogger.com,1999:blog-10074565.post-3499851540794025232011-03-24T15:04:00.002+00:002011-03-24T15:01:45.168+00:00Using powershell to run SQL Jobs serially<div dir="ltr" style="text-align: left;" trbidi="on"><div class="WordSection1"><div class="MsoNormal">We had some backups fail due to disk space issues. Once we cleared the space, we needed to run the backups as I didn’t want to wait an entire day. I didn’t want to run them at once due to contention issues and I am way too lazy to manually start each one and wait for it to finish.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Powershell to the rescue. <o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">The SQL provider is slick, gives you a sql server psdrive that you can explore. Finding the jobs was easy enough. Finding failed jobs was easy enough. Running the jobs… wtf? Not hard, but seems like I should be able to just start a job rather than send it as a sql command. I hardly need the sql snapin for that.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Anyway, update SERVERNAME (and potentially instance) in the code below and it will find all your failed jobs and run them serially.<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal">Sweet<o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal" style="text-autospace: none;"><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">cd</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> SQLSERVER:\</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">SQL\SERVERNAME\DEFAULT\JobServer\Jobs</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$jobs</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">dir</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">where</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$_</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.lastrunoutcome </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-eq</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"failed"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><br />
</div><div class="MsoNormal" style="text-autospace: none;"><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$job</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$jobs</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"starting $($job.name)"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> invoke-sqlcmd -database msdb </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"sp_start_job '$($job.name)'"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">while</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> ((invoke-sqlcmd -database msdb </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"sp_help_jobactivity @job_id = NULL, @job_name = '$($job.name)'"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">).run_status </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-ne</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 1) {<o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"still running..."</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">sleep</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 120<o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Completed at $(date)"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal" style="text-autospace: none;"><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal"><br />
</div></div></div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0tag:blogger.com,1999:blog-10074565.post-58969499256744580712011-03-08T15:45:00.000+00:002011-06-28T11:10:56.548+00:00Timeouts Removing VMWare snapshots w/ PowerCLI<div dir="ltr" style="text-align: left;" trbidi="on">On commit of several of our vmsnapshots we are getting the annoy “Operation Timed Out” after the vcenter timeout limit is reached. Luckily, the remove snapshot operation is still performed in the background and eventually completes. Below is a quick and dirty way to delete a vm snapshot and wait for the process to complete. I check the existence of the snapshot every 60 seconds and return when it is gone. If it is still going after 2 hours, I throw an error. It is pretty noisy as I wanted to see what was happening but didn't feel like getting into logging, you will probably want to add to it if you need to actually use it. <br />
<br />
This is to be run in a PowerCLI window. Add the function and then you can use<br />
<span class="Apple-style-span" style="color: cadetblue; font-family: 'Courier New'; font-size: 13px;"> delete-vmsnapshot "VMName"</span><br />
<br />
Note: if you add <span style="color: black; font-family: 'Courier New'; font-size: 10pt;">-confirm:</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$false </span>to the remove-snapshot line, you won't be prompted to confirm the delete. I took it out of the below to add some protection against copying and pasting code. B)<br />
<br />
Note 2: if you don't care about how monitoring how long it takes you can just do something like the following. I wanted to loop through several serially and didn't want them starting over each other.<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> <span class="Apple-style-span" style="font-size: x-small;">get-vm -name "VMNAME" | get-snapshot | remove-snapshot</span></span><br />
<br />
<br />
<div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">function</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">delete-vmsnapshot</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">param</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> (</span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$vmname</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;">)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$d1</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> date<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"Starting at $d1"</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$vm</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> get-vm -name </span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$vmname</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$sn</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$vm</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> | get-snapshot<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"Deleting:"</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$sn</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> | </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">fl</span></b><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">*</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$sn</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> | remove-snapshot </span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$timesleeping</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> ((date) </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">-</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> d1).TotalSeconds<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">while</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> (</span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">-not</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> ((</span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$vm</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> | Get-Snapshot) </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">-eq</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$null</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;">)) {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span><span style="mso-spacerun: yes;"> </span><span style="mso-tab-count: 1;"> </span></span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$timesleeping</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> ((date) </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">-</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> d1).TotalSeconds<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">if</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> (</span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$timesleeping</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">-gt</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> 7200) {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 3;"> </span></span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">throw</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> (</span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"waiting over 2 hours for snapshot to delete"</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;">)<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>} </span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt;">else</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 3;"> </span></span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"Merging for $timesleeping seconds."</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span>}<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 2;"> </span></span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10.0pt;">sleep</span></b><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> 60<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span>}<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: purple; font-family: "Courier New"; font-size: 10.0pt;">$d2</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> ((date) </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt;">-</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"> d1).TotalSeconds<o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span></span><span style="color: maroon; font-family: "Courier New"; font-size: 10.0pt;">"Complete taking a total of $d2 seconds"</span><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span> <o:p></o:p></span></div><div class="MsoNormal" style="mso-layout-grid-align: none; text-autospace: none;"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;">}<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10.0pt;"><span style="mso-tab-count: 1;"> </span></span><o:p></o:p></div></div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0tag:blogger.com,1999:blog-10074565.post-7424747437821049552010-11-28T11:47:00.003+00:002011-06-28T11:09:18.075+00:00SCCM Distribution point tar file error<div dir="ltr" style="text-align: left;" trbidi="on">I spent all weekend fighting various sccm parent-> Child site replication issues. One I had around some of my software update packages had basically no information on the web despite what I would expect to be a very ‘searchable’ signature. the misspelling in signature in this line:<br />
<blockquote>failed to register the source with the signautre repository </blockquote>The full error message I was getting is below but the most obvious lines were (from distmgr.log on the child)<br />
<blockquote>invalid tar file signature <br />
UnpackFolderW failed; 0x80040299 <br />
UnpackFolder() failed <br />
failed to register the source with the signautre repository <br />
UpdateStagedFolderRdcW failed; 0x80070299 <br />
Cannot copy package CEN00004 from e <br />
Failed to copy package CEN00004 from e <br />
STATMSG <br />
Forward package status for pkg CEN00004 to site CEN <br />
Error occurred.</blockquote>I was stuck in a loop w/ two of my packages where they would expand to an e:\_S XXXXXXX temp directory but would fail during or just after that step w/ the above errors. <br />
<span class="Apple-style-span" style="font-size: large;"><br />
</span><br />
<span class="Apple-style-span" style="font-size: large;">Resolution:</span><br />
Short answer:<br />
Delete from dp, turn off binary replication, repush.<br />
<br />
Step by step:<br />
What finally worked was to remove the packages from the child distribution point at the parent server, turn off binary replication, and re-add them to the DP. So, from the parent server Computer Management –> Software Updates –> Deployment Packages –> My Package –> right click on distribution points –> manage distribution points –> delete from selected. Once I saw this go through in the distmgr log of the child site, which looks something like: <br />
<blockquote>Updated replicated package info for package CEN00004 <br />
Updated replicated package server ["Display=\\childsite\"]MSWNET <br />
Updated replicated package program info for package CEN00004, program *, dependent program <br />
Successfully processed C <br />
Removing package CEN00004 from the active package array.</blockquote>Right click on your package under Deployment Packages and uncheck ‘Enable Binary Replication’.<br />
Right click on Deployment Packages –> your package –> distribution points and add a new DP.<br />
You should see it uncompress to the _S temp folder and then continue to creating the directory structure and moving the files into your SMSPGKE$ (or whichever drive is appropriate).<br />
Full log of the repeating (erroring) attempt below. <br />
Hopefully this will save somebody an afternoon.<br />
Good luck<br />
<br />
<br />
Starting package processing thread,thread ID = 1670 <br />
Sleep 3600 seconds... <br />
STATMSG <br />
Retrying package CEN00004 <br />
No action specified for the package CEN00004. <br />
Start adding package to server ["Display=\\childsite\"]MSWNET <br />
["Display=\\childsite\"]MSWNET <br />
Will wait for 1 threads to end. <br />
Thread Handle = 7056 <br />
Attempting to add or update a package on a distribution point. <br />
for ["Display=\\childsite\"]MSWNET <br />
STATMSG <br />
Established connection to ["Display=\\childsite\"]MSWNET <br />
Signature share exists on distribution point path MSWNET <br />
Found the existing package path on MSWNET <br />
Validating the compressed file E <br />
Used 1 out of 7 allowed processing threads. <br />
Sleep 3600 seconds... <br />
The package file requires a NTFS drive to decompress to. <br />
Decompressing package E <br />
Processing incoming file C <br />
Package CEN00004 is currently being processed <br />
Processing incoming file C <br />
Package CEN00004 is currently being processed <br />
Used 1 out of 7 allowed processing threads. <br />
Sleep 3600 seconds... <br />
Used 1 out of 7 allowed processing threads. <br />
Sleep 3600 seconds... <br />
Used 1 out of 7 allowed processing threads. <br />
Sleep 3600 seconds... <br />
STATMSG <br />
GetPackageSignature() called for package CEN00004 with version 3. UnpackedSignature = 0 <br />
RDC <br />
for ["Display=\\childsite\"]MSWNET <br />
IISPortsList in the SCF is "80". <br />
IISSSLPortsList in the SCF is "443". <br />
IISWebSiteName in the SCF is "". <br />
IISSSLState in the SCF is 0. <br />
Virtual Directory SMS_DP_SMSPKGE$ for the physical path E <br />
for ["Display=\\childsite\"]MSWNET <br />
IISPortsList in the SCF is "80". <br />
IISSSLPortsList in the SCF is "443". <br />
IISWebSiteName in the SCF is "". <br />
IISSSLState in the SCF is 0. <br />
Virtual Directory SMS_DP_SMSSIG$ for the physical path E <br />
Get access to the package directory and the number of free bytes at that location. <br />
Attempting to make an accessible connection to MSWNET <br />
Established connection to MSWNET <br />
Getting the NAL path's NOS equivalent. <br />
The NOS path is \\childsite\SMSPKGE$\CEN00004\ <br />
Getting the number of free bytes. <br />
The number of free K bytes 221886568 <br />
Successfully made an accessible connection, got a NOS path, and, if requested, got the number of free bytes at this location. <br />
Attempting to make an accessible connection to MSWNET <br />
Established connection to MSWNET <br />
Getting the NAL path's NOS equivalent. <br />
The NOS path is \\childsite\SMSSIG$\ <br />
The number of free bytes at the specified location has not been requested. <br />
Successfully made an accessible connection, got a NOS path, and, if requested, got the number of free bytes at this location. <br />
Successfully set access security on MSWNET <br />
GetPackageSignature() called for package CEN00004 with version 3. UnpackedSignature = 0 <br />
RDC <br />
RegisterSignatureUsage() called with for Package CEN00004, Version 3 with Targetpath as E <br />
invalid tar file signature <br />
UnpackFolderW failed; 0x80040299 <br />
UnpackFolder() failed <br />
failed to register the source with the signautre repository <br />
UpdateStagedFolderRdcW failed; 0x80070299 <br />
Cannot copy package CEN00004 from e <br />
Failed to copy package CEN00004 from e <br />
STATMSG <br />
Forward package status for pkg CEN00004 to site CEN <br />
Error occurred. <br />
Performing error cleanup prior to returning. <br />
DP thread with array index 0 ended. <br />
DP thread with thread handle 7056 and thread ID 5628 ended. <br />
Updating package info for package CEN00004 <br />
Only retrying local DP update for package CEN00004, no need to replicate package definition to child sites or DP info to parent site. <br />
StoredPkgVersion (3) of package CEN00004. StoredPkgVersion in database is 3. <br />
SourceVersion (3) of package CEN00004. SourceVersion in database is 3. <br />
STATMSG <br />
Failed to process package CEN00004 after 3 retries, will retry 97 more times</div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0tag:blogger.com,1999:blog-10074565.post-14935727375542640452010-08-03T18:50:00.003+00:002011-06-28T11:10:10.049+00:00Automatically closing SCOM alerts w/ powershellYou may have seen my post earlier about <a href="http://cornasdf.blogspot.com/2010/06/syslog-monitoring-walkthrough-with.html" linkindex="15">Syslog Monitoring Walkthrough with Systems Center Operations Manager 2007</a>. Well, I went on vacation and my colleagues got a little overzealous in what we directed at scom. I came back to over 200k warnings from one device that was sending alerts at waaaay too low a threshhold. These were going into a view that wasn’t normally checked (it seems) and now we have a problem. The console crashes when trying to select all of them (surprise) and I do not want to do this by hand. Powershell to the rescue?<br />
After opening the OpsMgr PS console, we can get started. Setting the alert to closed (ResolutionState =255) should be trivial. We mustn’t forget to update the alert after we set the state. The interesting part is that we need to get our collection of alerts with as little impact as possible.<br />
I could just do:<br />
$colAgents = get-alert <br />
but that would crush my database and take forever. To narrow this down a bit, I am going to select by source (as basically all of these came from the same source.) <br />
We could run a get-alert | where {SOMETHING} but that would have to return all the alerts and then parse them which would be very heavy. The SCOM cmdlets have a –criteria to do the filtering in the db, lets use that.<br />
Source seems to translate, at an object level, to MonitoringObjectDisplayName so I set my criteria, do the query and loop through the results like so:<br />
<div class="MsoNormal"><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$criteria</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">“ResolutionState = 0 AND MonitoringObjectDisplayName = ‘SERVERNAME’”</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span></div><span style="color: black; font-family: "Courier New"; font-size: 10pt;"></span><br />
<div class="MsoNormal"><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$colSysLogAlerts</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">get-alert</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">-criteria $criteria</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span></div><span style="color: black; font-family: "Courier New"; font-size: 10pt;"></span><br />
<div class="MsoNormal"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">foreach</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">(</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$Alert</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">in</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$colSysLogAlerts</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">) { </span></div><span style="color: black; font-family: "Courier New"; font-size: 10pt;"></span><br />
<div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$Alert</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.ResolutionState </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> 255 </span></div><span style="color: black; font-family: "Courier New"; font-size: 10pt;"></span><br />
<div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">write-host</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">“Closing $($Alert.id)”</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span></div><span style="color: black; font-family: "Courier New"; font-size: 10pt;"></span><br />
<div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$Alert</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.Update(</span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"Closed by Powershell"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">) </span></div><span style="color: black; font-family: "Courier New"; font-size: 10pt;"></span><br />
<div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;">} </span></div><span style="color: black; font-family: "Courier New"; font-size: 10pt;"></span><br />
<blockquote></blockquote>Powershell to the rescue indeed.cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0tag:blogger.com,1999:blog-10074565.post-14795114308499518142010-06-08T11:17:00.002+00:002010-06-08T12:20:12.148+00:00Syslog Monitoring Walkthrough with Systems Center Operations Manager 2007Building on excellent posts <a href="http://ianblythmanagement.wordpress.com/2007/05/25/syslog/">here</a>, <a href="http://contoso.se/blog/?p=158">here</a> and <a href="http://blogs.technet.com/b/cliveeastwood/archive/2007/09/07/generating-alerts-from-unix-linux-syslog-messages-in-operations-manager-2007.aspx">here</a> and feedback on the forums <a href="http://social.technet.microsoft.com/Forums/en-US/operationsmanagergeneral/thread/18ce5b69-2d1f-4abd-9de3-543a6a1bf630">here</a>, I am going to describe our Operations manager 2007 syslog setup.<br />
<br />
<br />
First step was to build a group of servers that will be our Syslog collectors in Opsmgr. Populate your Syslog Collectors group w/ the servers you will be pointing your syslog messages towards. I created a new management pack called _Default_Syslog that will hold all the work in this section. <br />
<br />
<a href="http://lh3.ggpht.com/_RuRKSkpoFrM/TA4moeUHNxI/AAAAAAAAAS8/3cAdGR4IB1s/s1600-h/image%5B27%5D.png"><img alt="image" border="0" height="656" src="http://lh3.ggpht.com/_RuRKSkpoFrM/TA4mosfu7JI/AAAAAAAAATA/suce1fa1Enw/image_thumb%5B13%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="745" /></a> <br />
<br />
Once I have my group, I want to create a new rule. Under the rule wizard, I select Alert Generating Rules –> Event Based-> Syslog (Alert). <br />
<br />
I am going to have 3 Syslog rule. One for each state, warning, error and informational. The first rule I am making is the error rule. So we are going to name it, Syslog Error. (I know, imaginative)<br />
<br />
Since I am collecting Alerts, it seems “Alert” would be a good rule target but I will admit to being a bit hazy on this area of SCOM and what it implies. If you know better, please let me know.<br />
<br />
For rule target, I am just going to pick Windows Computers. Note that at some point I tried to target this at the Agent and this caused problems when I wanted to use a Management server as a collector. To quote Graham Davies from the System Center Operations Manager General <a href="http://social.technet.microsoft.com/Forums/en-US/operationsmanagergeneral/thread/18ce5b69-2d1f-4abd-9de3-543a6a1bf630">forums</a>: <br />
<blockquote>If you want the rule to run on the RMS \ Gateway then you'll need to target the appropriate class - management server. Although the Management Servers include "agent capability", they are not agents and hence won't get the rule if you target agent.</blockquote>MAKE SURE you unselect Rule is Enabled or you will turn on syslog collection for all of your servers. We will override to turn on these rules for our specific group later.<br />
<br />
<br />
<a href="http://lh4.ggpht.com/_RuRKSkpoFrM/TA4xBNyt59I/AAAAAAAAAUg/YGf86deQP6g/s1600-h/image%5B80%5D.png"><img alt="image" border="0" height="569" src="http://lh6.ggpht.com/_RuRKSkpoFrM/TA4xBfFKfdI/AAAAAAAAAUk/J2fu0xiOA88/image_thumb%5B44%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="555" /></a> <br />
<br />
For Event Expressions, I want to catch all events w/ a Severity of less than or equal to 3. So I build my Filter like so:<br />
<br />
<a href="http://lh6.ggpht.com/_RuRKSkpoFrM/TA4mp7G4oaI/AAAAAAAAATM/Sm3WgIcc6pg/s1600-h/image%5B14%5D.png"><img alt="image" border="0" height="155" src="http://lh4.ggpht.com/_RuRKSkpoFrM/TA4mqWOwizI/AAAAAAAAATQ/xTFeR4tFTD4/image_thumb%5B6%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="546" /></a> <br />
<br />
For my alerts, I like to get more data so I am going to put the following in the description:<br />
<blockquote>Facility: <br />
$Data/EventData/DataItem/Facility$ <br />
Severity: <br />
$Data/EventData/DataItem/Severity$ <br />
Priority: <br />
$Data/EventData/DataItem/Priority$ <br />
Priority Name <br />
$Data/EventData/DataItem/PriorityName$ <br />
Time Generated: <br />
$Data/EventData/DataItem/TimeStamp$ <br />
Hostname: <br />
$Data/EventData/DataItem/HostName$ <br />
Message: <br />
$Data/EventData/DataItem/Message$</blockquote><a href="http://lh6.ggpht.com/_RuRKSkpoFrM/TA4mrH_LeZI/AAAAAAAAATU/bZ4KnwhXLAM/s1600-h/image%5B18%5D.png"><img alt="image" border="0" height="420" src="http://lh4.ggpht.com/_RuRKSkpoFrM/TA4mrpcz_QI/AAAAAAAAATY/RAvslM5JZJI/image_thumb%5B8%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="546" /></a> <br />
<br />
Click create to finish the wizard.<br />
<br />
Repeat the above for the Warning Alerts. You will only need to change the Name, the severity on the alert and make your Filter equal to 4 like so:<br />
<br />
<a href="http://lh3.ggpht.com/_RuRKSkpoFrM/TA4mr1t1MMI/AAAAAAAAATc/U_-0aMNUT0M/s1600-h/image%5B22%5D.png"><img alt="image" border="0" height="50" src="http://lh4.ggpht.com/_RuRKSkpoFrM/TA4mscKYE7I/AAAAAAAAATg/kWR7uFOT0UM/image_thumb%5B10%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="522" /></a> <br />
<br />
And again for your Informational alerts. Your filter will be greater than or equal to 5 and don’t forget to change your severity.<br />
<br />
I chose to capture these as infomational alerts for now, I am going to see how spammy this gets. another option is to create these as Event collection rules without alerts. That will allow you to hold on to the data but not alert on it. It will depend on your alerting requirements. You can also manage what you send from your sending device’s syslog configuration.<br />
<br />
To enable these rules on specific servers, right click on your rule and choose ‘Overrides’ –> Override the Rule –> For a group…<br />
<br />
<a href="http://lh4.ggpht.com/_RuRKSkpoFrM/TA4xB4gesBI/AAAAAAAAAUo/j4RDE9q5Ooc/s1600-h/image%5B88%5D.png"><img alt="image" border="0" height="219" src="http://lh6.ggpht.com/_RuRKSkpoFrM/TA4xCVJqulI/AAAAAAAAAUs/pn0jKwOiS_o/image_thumb%5B48%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="766" /></a> <br />
<br />
Select your Syslog Servers group and override the rule to enable it on these servers.<br />
<br />
<a href="http://lh5.ggpht.com/_RuRKSkpoFrM/TA4xDHWiYQI/AAAAAAAAAUw/mihXOyxdq1A/s1600-h/image%5B92%5D.png"><img alt="image" border="0" height="726" src="http://lh6.ggpht.com/_RuRKSkpoFrM/TA4xDi-12iI/AAAAAAAAAU0/1OkogmNZV3Y/image_thumb%5B50%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="719" /></a> <br />
<br />
You can verify that the syslog listener is enabled by getting on the machine you expect to be listening and checking for UDP 514 in netstat. Open a command windows and type ‘netstat –an | findstr 514’ (findstr = grep). You want to see a line like the below. If you don't get anything, you are not listening for syslog packets.<br />
<br />
<a href="http://lh6.ggpht.com/_RuRKSkpoFrM/TA4xEH-X0RI/AAAAAAAAAU4/oU4YYQKBvnI/s1600-h/image%5B96%5D.png"><img alt="image" border="0" height="35" src="http://lh6.ggpht.com/_RuRKSkpoFrM/TA4xEneFijI/AAAAAAAAAU8/3O5y4Q9T8B8/image_thumb%5B52%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="480" /></a> <br />
<br />
In order to make this easy to see, I also created a view. Under the SCOM Console Monitoring view, find your _default_syslog folder –> right click –> New –> Alert View. Include alerts ‘created by specific sources’. Pick your rules that you just created.<br />
<br />
<br />
<br />
<a href="http://lh4.ggpht.com/_RuRKSkpoFrM/TA4xFEMFijI/AAAAAAAAAVA/wtzx0SUIuik/s1600-h/image%5B101%5D.png"><img alt="image" border="0" height="603" src="http://lh3.ggpht.com/_RuRKSkpoFrM/TA4xFjNW9ZI/AAAAAAAAAVE/8gsY2-Qxzzw/image_thumb%5B55%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="746" /></a> <br />
<br />
You should end up w/ a view like (your source will probably be a computer name):<br />
<br />
<br />
<a href="http://lh3.ggpht.com/_RuRKSkpoFrM/TA4mtpY6QgI/AAAAAAAAATs/2AVBoVmsDf0/s1600-h/image%5B69%5D.png"><img alt="image" border="0" height="711" src="http://lh4.ggpht.com/_RuRKSkpoFrM/TA4muEw56gI/AAAAAAAAATw/Te31V3H5pFk/image_thumb%5B39%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="736" /></a> <br />
<br />
More info I found two ways to display more info in the line. The first way is the most straightforward and I typed it up first so I am going to show it anyway. You probably want the second way. B)<br />
The first way:<br />
<br />
You can add more information to your alert and then set your view to show it. Under your alert configuration, you can add custom alert fields. I added fields for both my hostname and my priority name.<br />
<br />
<a href="http://lh5.ggpht.com/_RuRKSkpoFrM/TA4muz1XsrI/AAAAAAAAAT4/smtjFSU9ZfE/s1600-h/image%5B37%5D.png"><img alt="image" border="0" height="484" src="http://lh4.ggpht.com/_RuRKSkpoFrM/TA4mvcFsiYI/AAAAAAAAAT8/JzEtd6uVlBg/image_thumb%5B19%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="590" /></a> <br />
<br />
Send a few more test syslogs. BTW, the <a href="http://www.kiwisyslog.com/kiwi-sysloggen-download/">kiwi syslog generator</a> works perfectly for this. Update your view so that you show Custom Field 1 and Custom Field 2 from the Display tab under your view properties.<br />
<br />
<a href="http://lh3.ggpht.com/_RuRKSkpoFrM/TA4mv3zhLQI/AAAAAAAAAUA/xT7KPPIRVdw/s1600-h/image%5B45%5D.png"><img alt="image" border="0" height="599" src="http://lh3.ggpht.com/_RuRKSkpoFrM/TA4mwEZQLQI/AAAAAAAAAUE/YgsLSwOVdiY/image_thumb%5B23%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="747" /></a> <br />
<br />
Note that for some reason my extra columns were not displaying initially. I had to delete and recreate the view. Since my source was always the same, I also stopped showing the source. You can see the syslog entry created after the change has populated the custom fields:<br />
<br />
<a href="http://lh5.ggpht.com/_RuRKSkpoFrM/TA4mwufENyI/AAAAAAAAAUI/_CTKnrDEBxI/s1600-h/image%5B60%5D.png"><img alt="image" border="0" height="167" src="http://lh6.ggpht.com/_RuRKSkpoFrM/TA4mw8lIkBI/AAAAAAAAAUM/CtAr9qLr5ls/image_thumb%5B32%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="947" /></a> <br />
<br />
The second way:<br />
<br />
This initially involved some (simple) XML munging so I was going to have an advanced and a simple method, the simple being the one above. Once I figured out how in the XML, it turns out you can do it in the GUI as well. <br />
<br />
I first exported the MP and saw the below XML<br />
<blockquote> <Name>Syslog Error</Name> <br />
<Description>Facility: <br />
{0} <br />
Severity: <br />
{1} <br />
Priority: <br />
{2} <br />
Priority Name <br />
{3} <br />
Time Generated: <br />
{4} <br />
Hostname: <br />
{5} <br />
Message: <br />
{6}</Description></blockquote>Note that the curly bracked enclosed items are expanded to our variables. So {5} is analogous to $Data/EventData/DataItem/HostName$ in our GUI based alert description. Putting $Data/EventData/DataItem/HostName$ in the alert name doesn’t work but putting {5} does. So I changed the XML to <br />
<blockquote> <i><span style="color: red;"><b><Name>Syslog Error: {5} - {3}</Name></b></span></i> <br />
<Description>Facility: <br />
{0} <br />
Severity: <br />
{1} <br />
Priority: <br />
{2} <br />
Priority Name <br />
{3} <br />
Time Generated: <br />
{4} <br />
Hostname: <br />
{5} <br />
Message: <br />
{6}</Description></blockquote>When I checked my alert view, voila!, My alert name has changed as in the screen shot below. My next thought was why can’t I do that from the gui? So, i edited my alert name to be: Syslog Warning: {5} - {3}<br />
<br />
<a href="http://lh6.ggpht.com/_RuRKSkpoFrM/TA4mxSTWfZI/AAAAAAAAAUQ/fbVzAucH-fE/s1600-h/image%5B54%5D.png"><img alt="image" border="0" height="592" src="http://lh5.ggpht.com/_RuRKSkpoFrM/TA4mxuHUX-I/AAAAAAAAAUU/iSMgx3HfanU/image_thumb%5B28%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="601" /></a> <br />
<br />
Back to my alert view and, check it out, useful alert names!! Maybe I am too excited about this but it makes it much more supportable in my opinion. B)<br />
<br />
<a href="http://lh4.ggpht.com/_RuRKSkpoFrM/TA4myKHxDxI/AAAAAAAAAUY/a0cT0r44JLk/s1600-h/image%5B73%5D.png"><img alt="image" border="0" height="573" src="http://lh5.ggpht.com/_RuRKSkpoFrM/TA4mzYiN2MI/AAAAAAAAAUc/OpHk179Iks0/image_thumb%5B41%5D.png?imgmax=800" style="border: 0px none; display: inline;" title="image" width="678" /></a> <br />
<br />
One note, I am putting the syslog collector on other running servers. We have only a few devices that are sending data here and only critical events are expected. YMMV, you may want to dedicate a server to this.cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com5tag:blogger.com,1999:blog-10074565.post-45998490298378985022010-05-06T13:59:00.002+00:002012-12-03T11:24:38.528+00:00Using Powershell to create groups, populate groups and retrieve LDAP distinguished names<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="WordSection1">
<div class="MsoNormal">
<span style="color: #cc0000; font-size: large;">Update 20121203 - I just noticed this is still getting hits. this is largely deprecated, from Powershell 2.0 and beyond, do your self a favor and use the <a href="http://blogs.msdn.com/b/adpowershell/archive/2009/02/25/ad-powershell-quick-start-guide.aspx" target="_blank">ActiveDirectory module</a>. if you don't have access to that module for some reason (they do exist) the below should still work.</span><br />
<br />
Update: 20100507 - updated the sam search string to do fuzzy matching.<br />
<br />
A couple more functions I needed during a recent project. Using powershell of course, we needed to create a group in ad in a specific OU. We also wanted to populate that group. To do the second, I needed a helper function to get the distinguished name of a group or user. I leverage <a href="http://www.leadfollowmove.com/archives/powershell/managing-group-membership-in-active-directory-with-powershell-part-2">two</a> <a href="http://blogs.technet.com/benp/archive/2007/03/26/searching-the-active-directory-with-powershell.aspx">main</a> sites for most of these with some light modifications. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
For create group we pass it the name of our new group and the OU we want to create our group in, such as:<o:p></o:p></div>
<div class="MsoNormal">
Create-group “Newgroup” “OU=ServerGroups,DC=example,DC=com”<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">function</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">create-group</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$groupname</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">, </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$strOU</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$OU</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">adsi</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">]</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"LDAP://$strOU"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$group</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$ou</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Create(</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Group"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">, </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"CN=$groupname"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$group</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.setinfo()<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$g2</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">adsi</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">]</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"LDAP://CN=$groupname,$strOU"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$g2</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.sAMAccountName </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$groupname</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$g2</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.setinfo()<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-Host</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Created $groupname in $strOU"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">F</span>or add-usertogroup we pass it a user DN. DNs are the full LDAP distinguished name like: <o:p></o:p></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">LDAP://CN=myuser,OU=Admins,</span>DC=example,DC=com <o:p></o:p></div>
<div class="MsoNormal" style="text-autospace: none;">
So we would pass something like<o:p></o:p></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">Add-usertogroup “LDAP://CN=myuser,OU=Admins,DC=example,DC=com” “LDAP://CN=Newgroup,OU=ServerGroups,DC=example,DC=com”<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
That is kind of annoying so you could also use the get-dn function below. <o:p></o:p></div>
<div class="MsoNormal" style="text-autospace: none;">
The safe way:<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$userDN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">get-dn</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"myuser"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$groupDN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">get-dn</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"newgroup"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .5in; text-autospace: none;">
<span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">add-usertogroup</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$userDN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$groupDN<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
or the one liner<o:p></o:p></div>
<div class="MsoNormal" style="text-autospace: none; text-indent: .5in;">
<span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">add-usertogroup</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">get-dn</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"myuser"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) (</span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">get-dn</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"newgroup"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">function</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">add-usertogroup</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$userDN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">, </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$groupDN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$user</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">adsi</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">]</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$userDN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$group</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">adsi</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">]</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$groupDN</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Write-Host</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Adding $($user.cn) to $($group.cn)"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$members</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$group</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.member<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$group</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.member </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$members</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$user</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.distinguishedName<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$group</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.setinfo()<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal">
I would further note <a href="http://confluence.atlassian.com/display/DEV/How+to+write+a+LDAP+search+filter">this</a> excellent site describing how to write an LDAP filter. It cleared a few things up for me at long last. I can’t believe I never realized that & was a logical AND... Pretty straightforward afterwards but the writeup above helped me bridge the gap. Note that it is for some software or other so ignore the part about escaping the special characters at the top. B)<o:p></o:p></div>
<div class="MsoNormal" style="text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">function</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">get-dn</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$SAMName</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$root</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> [</span><span style="color: teal; font-family: 'Courier New'; font-size: 10pt;">ADSI</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">]</span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">''</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$searcher</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">new-object</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">System.DirectoryServices.DirectorySearcher</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$root</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="font-family: 'Courier New'; font-size: 10pt;"><span class="Apple-style-span" style="color: #38761d;"> #note: if you don't want fuzzy searches, remove the *s from the line below. </span></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New'; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;"><span class="Apple-style-span" style="color: #38761d;"> #this will force a match of the search string only - thanks jc for the tip</span></span></span><br />
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"></span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;"> $searcher</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.filter </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"(&(|(objectClass=user)(objectClass=group))(sAMAccountName=*$SAMName*))"</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$user</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$searcher</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.findall()<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">if</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$user</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.count </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-gt</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 1)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> { <o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$count</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 0<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">foreach</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">(</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">in</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$user</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">write-host</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$count</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">": "</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$i</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.path<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$count</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$count</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">+</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> 1<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$selection</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">=</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Read-Host</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: maroon; font-family: 'Courier New'; font-size: 10pt;">"Please select item: "</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$user</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">[</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$selection</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">].path<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> } </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">else</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">return</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$user</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">[0].path<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="text-autospace: none;">
<span style="color: black; font-family: 'Courier New'; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Note that it matches the SAM Account Name (aka the ‘Pre-Windows 2000’ name in the AD snapin)<o:p></o:p></div>
<div class="MsoNormal">
Enjoy<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
</div>
</div>
cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com5tag:blogger.com,1999:blog-10074565.post-5638343987977319852010-05-05T09:59:00.005+00:002010-06-12T00:06:20.985+00:00Use powershell to quickly backup all TFS Work Item Types<div class="WordSection1"><span style="color: black; font-family: "Trebuchet MS","sans-serif"; font-size: 11pt;">Hey all, <o:p></o:p></span><br />
<span style="color: black; font-family: "Trebuchet MS","sans-serif"; font-size: 11pt;">Just a quickie to easily backup all your current work items from all projects in Team Foundation Server 2008 SP1. I wanted to do this ahead of a big migration and I am adverse to manual labor.<o:p></o:p></span><br />
<br />
<span style="color: black; font-family: "Trebuchet MS","sans-serif"; font-size: 11pt;">It starts w/ a function i found a couple years ago. I don’t recall where or I would give credit here. It is very useful for any tfs powershell manipulation.<o:p></o:p></span><br />
<br />
<span style="color: black; font-family: "Trebuchet MS","sans-serif"; font-size: 11pt;">Edit below to enter your $TFSHost and update your path if necessary. I recommend running from a blank directory. It will create a directory for each project and export each WIT for that project to the respective directories.</span><br />
<br />
<span style="color: black; font-family: "Trebuchet MS","sans-serif"; font-size: 11pt;">Update: I added another function from my library test-win32 and had that manage the default paths for x64 and x86 archs. </span><br />
<span style="color: black; font-family: "Trebuchet MS","sans-serif"; font-size: 11pt;"><o:p></o:p></span><br />
<br />
<span style="color: black; font-family: "Trebuchet MS","sans-serif"; font-size: 11pt;">Good luck<o:p></o:p></span><br />
<div class="MsoNormal"><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$tfshost</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"thshost"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><br />
<br />
<span style="color: purple; font-family: "Courier New"; font-size: 10pt;"> </span><style>
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-520092929 1073786111 9 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
span.EmailStyle15
{mso-style-type:personal;
mso-style-noshow:yes;
mso-style-unhide:no;
mso-ansi-font-size:11.0pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.WordSection1
{page:WordSection1;}
-->
</style> <br />
<div class="MsoNormal"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">function</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">Test-Win32</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">() {<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">return</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> [</span><span style="color: teal; font-family: "Courier New"; font-size: 10pt;">IntPtr</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">]::</span><span style="color: saddlebrown; font-family: "Courier New"; font-size: 10pt;">size</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">-eq</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> 4<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;">}</span><o:p></o:p></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">test-win32</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">) { <o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$tfstoolspath</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;">} </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$tfstoolspath</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;">}</span><o:p></o:p></div><br />
</div><div class="MsoNormal"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">function</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">get-tfs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;">#10-08 - cornasdf - i stole this from the web but this is a great way to connect to TFS<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;"># in your code you use: $tfs = get-tfs $TFSHost <o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;">#some quick examples from resolvedticketsmail.ps1:<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;">#get select from Stored query<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;">#$query = $tfs.WIT.Projects[$ProjectHoldingQuery].StoredQueries | where{$_.Name -eq $QueryViewName}<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;">#get results of specified query<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;">#$oldTickets = $tfs.WIT.Query($query.QueryText)<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">param</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">(<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> [</span><span style="color: teal; font-family: "Courier New"; font-size: 10pt;">string</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">] </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$serverName</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> $(</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">throw</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'serverName is required'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">)<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> )<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">begin</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;"># load the required dll<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> [</span><span style="color: teal; font-family: "Courier New"; font-size: 10pt;">void</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">][</span><span style="color: teal; font-family: "Courier New"; font-size: 10pt;">System.Reflection.Assembly</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">]::</span><span style="color: saddlebrown; font-family: "Courier New"; font-size: 10pt;">LoadWithPartialName</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">(</span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"Microsoft.TeamFoundation.Client"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">)<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$propertiesToAdd</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'VCS'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">, </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'Microsoft.TeamFoundation.VersionControl.Client'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">, </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">),<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'WIT'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">, </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'Microsoft.TeamFoundation.WorkItemTracking.Client'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">, </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">),<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'CSS'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">, </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'Microsoft.TeamFoundation'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">, </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'Microsoft.TeamFoundation.Server.ICommonStructureService'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">),<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'GSS'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">, </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'Microsoft.TeamFoundation'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">, </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'Microsoft.TeamFoundation.Server.IGroupSecurityService'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">)<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> )<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">process</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;"># fetch the TFS instance, but add some useful properties to make life easier<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;"># Make sure to "promote" it to a psobject now to make later modification easier<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> [</span><span style="color: teal; font-family: "Courier New"; font-size: 10pt;">psobject</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">] </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$tfs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer(</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$serverName</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">)<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">foreach</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$entry</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">in</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$propertiesToAdd</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">) {<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$scriptBlock</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'<o:p></o:p></span></div><div class="MsoNormal"><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;"> [System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null<o:p></o:p></span></div><div class="MsoNormal"><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;"> $this.GetService([{1}])<o:p></o:p></span></div><div class="MsoNormal"><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;"> '</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">-f</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$entry</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">[1],</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$entry</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">[2]<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$tfs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">add-member</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">scriptproperty</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$entry</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">[0] </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$ExecutionContext</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.</span><span style="color: saddlebrown; font-family: "Courier New"; font-size: 10pt;">InvokeCommand</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.</span><span style="color: saddlebrown; font-family: "Courier New"; font-size: 10pt;">NewScriptBlock</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">(</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$scriptBlock</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">)<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">return</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$tfs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;">} <o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$tfs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">get-tfs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$tfshost</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$projects</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$tfs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.wit.Projects <o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">foreach</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$proj</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">in</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$projects</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">) {<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> ( </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">-not</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">Test-Path</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><i><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">-path</span></i><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> .\$(</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$proj</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.Name))) {<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">New-Item</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> .\$(</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$proj</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.Name) -type directory<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">foreach</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$wit</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">in</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$proj</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.WorkItemTypes) {<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"Exporting $($proj.Name) : $($wit.Name) -> .\$($proj.Name)\$($wit.Name).xml"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> & </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"$tfstoolspath\witexport.exe"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> /p </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"$($proj.Name)"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> /n </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"$($wit.Name)"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> /f </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">".\$($proj.Name)\$($wit.Name).xml"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> /t </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$tfshost</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> <o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal"><span style="color: black; font-family: "Courier New"; font-size: 10pt;">}</span></div></div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com4tag:blogger.com,1999:blog-10074565.post-13280152145949224382010-04-20T13:42:00.001+00:002011-06-28T11:11:23.422+00:00Systems Center Operations Manager R2 CU1 Issues and command line update<p>Just a quick one on our recent opsmgr R2 CU1 update.  </p> <p>Kevin Holman has a good post about his experiences.  Start <a href="http://blogs.technet.com/kevinholman/archive/2010/01/17/opsmgr-2007-r2-cu1-rollup-hotfix-ships-and-my-experience-installing-it.aspx">here</a>.  I would add the below</p> <p>1.  The gateway update does not copy the update msp to the agentmanagement folder.  Due to this, when I approved updates for agents on the other side of a gateway, they did not get the update.  You could fix this by copying the files from your gateway server before you approve your pending agent updates.  Copy the files at c:\Program Files\System Center 2007 R2 Hotfix Utility\KB974144\agent to the appropriate directory under c:\Program Files\System Center Operations Manager 2007\AgentManagement.  Make sure you copy the x86 update to the x86 folder.  x64 goes in AMD64 and ia64 goes in ia64.</p> <p>2.  Only remotely managed agents will offer an update.  In my case, my only agents that were manually installed were due to troubleshooting or other issues.  Another solution from Kevin Holman shows how to reset your agents to be remotely managed.  Pay attention to the <a href="http://blogs.technet.com/kevinholman/archive/2010/02/20/how-to-get-your-agents-back-to-remotely-manageable-in-opsmgr-2007-r2.aspx">whole post</a> to make sure it is right for you.</p> <p>3.  If you didn’t realize your gateways were not updated (like me) or put in the wrong password for one of your domains, you may need to update manually.  You can go on each server and run the installer and then choose install agent but that seemed annoying.  You can do it from the server over the network w/:</p> <p>"\\GATEWAYSERVER\c$\Program Files\System Center 2007 R2 Hotfix Utility\KB974144\SetupUpdateOM.exe" /silent /x86msp:KB974144-x86.msp /amd64msp:KB974144-x64.msp /UpdateAgent</p> <p>4.  or you can do what I did and psexec it w/:</p> <p>psexec -u DOMAIN\user "\\comp1,comp2,compN" cmd /c "\\GATEWAYSERVER\c$\Program Files\System Center 2007 R2 Hotfix Utility\KB974144\SetupUpdateOM.exe" /silent /x86msp:KB974144-x86.msp /amd64msp:KB974144-x64.msp /UpdateAgent</p> <p>Note that you need to pass the user to psexec (which will query for a password) so you can access network resources.  Also note that I needed to enclose my computer list in “ to get it to pass correctly.  YMMV.</p> <p>Also note that this will not work w/ 2k8+ clients as UAC gets in the way.  You could add –s to the the psexec line but then you would need a file share that the machine accounts could get at.  You could also probably do a small script that did a net use and then accessed the files.  I cheesed out and logged on directly as I only had a few that needed to be done manually.  </p> <p>Good luck.</p> cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0tag:blogger.com,1999:blog-10074565.post-34965690685912466082010-04-15T12:24:00.005+00:002011-07-04T22:28:44.978+00:00How does windows determine a cipher strength for an encrypted connection OR SQL Server data in transit cipher strength<div dir="ltr" style="text-align: left;" trbidi="on">This question is really just “how does windows determine a cipher strength for an encrypted connection” as SQL server just hands off to the windows schannel.dll to deal w/ this. But I was looking to determine the answer for SQL Data in transit encryption. <br />
<br />
This was pretty muddy to track down. There are some reference details <a href="http://blogs.msdn.com/sql_protocols/archive/2007/06/30/ssl-cipher-suites-used-with-sql-server.aspx">here</a>, <a href="http://msdn.microsoft.com/en-us/library/aa374757%28VS.85%29.aspx">here</a> and <a href="http://msdn.microsoft.com/en-us/library/aa380123%28VS.85%29.aspx">here</a>. <br />
<div><br />
At the end of the day, it comes down to an OS version question (potentially influenced by some OS/registry settings or patches). I couldn’t find any matrix anywhere so I am going to start one here. I am going to start out w/ the few I tested and hopefully fill this in w/ reader submissions (hint, hint). The guidance I can find seems to say that Win 2k8R2 and Win 7 have the same schannel capabilities so I am going to list them together. </div><div><br />
</div><div align="center"><table align="center" border="1" cellpadding="0" cellspacing="0" style="width: 774px;"><tbody>
<tr> <td valign="top" width="131"><b>Client\Server</b></td> <td valign="top" width="253"><b>Windows 2008 R2</b></td> <td valign="top" width="199"><b>Windows 2003 SP2</b></td> <td valign="top" width="189"><b>Windows 2000 SP4</b></td> </tr>
<tr> <td valign="top" width="131"><b>Windows 2008R2/7</b></td> <td valign="top" width="253">TLS_RSA_WITH_AES_128_CBC_SHA</td> <td valign="top" width="199">SSL_RSA_WITH_RC4_128_MD5</td> <td valign="top" width="189">SSL_RSA_WITH_RC4_128_MD5</td> </tr>
<tr> <td valign="top" width="131"><b>Windows 2003 SP2</b></td> <td valign="top" width="253">SSL_RSA_WITH_RC4_128_SHA</td> <td valign="top" width="199">SSL_RSA_WITH_RC4_128_MD5</td> <td valign="top" width="189">SSL_RSA_WITH_RC4_128_MD5 </td> </tr>
<tr> <td valign="top" width="131"><b>Windows XP SP3</b></td> <td valign="top" width="253">SSL_RSA_WITH_RC4_128_SHA</td> <td valign="top" width="199">SSL_RSA_WITH_RC4_128_MD5</td> <td valign="top" width="189">SSL_RSA_WITH_RC4_128_SHA</td> </tr>
</tbody></table></div>How to use this table: Find the client OS listed vertically down the left side and then find the server OS listed horizontally across the top. Where the row and column meet is your the cipher which, under the default settings, they should negotiate to use. More on the ciphers <a href="http://msdn.microsoft.com/en-us/library/aa374757%28VS.85%29.aspx">here</a>. <br />
<br />
How did we determine this? The only way I was able to find was to sniff the beginning of the SSL conversation. <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=983b941d-06cb-4658-b7f6-3088333d062f">Netmon 3.3</a> is an excellent tool for this. Note that you may need to set your Windows parsers from stub to full in order to decrypt the TDS packets. You can do this in Tools -> options -> Parser. Set Windows to ‘Full’ <br />
<br />
<a href="http://lh4.ggpht.com/_RuRKSkpoFrM/S8cFdefr5ZI/AAAAAAAAAQQ/RFEHeEcLflk/s1600-h/image%5B23%5D.png"><img alt="image" border="0" height="343" src="http://lh3.ggpht.com/_RuRKSkpoFrM/S8cFd1esObI/AAAAAAAAAQU/nD6uSaBw67Y/image_thumb%5B13%5D.png?imgmax=800" style="border-width: 0px; display: inline;" title="image" width="423" /></a> <br />
<br />
Start your trace before you start your encrypted connection. I like netmon b/c it will separate the network traffic into conversations. Find the conversation you are looking for by IP and port. For my purposes I was looking for my web server IP and my DB IP going to port 1433 on my DB. <br />
<br />
Once you have found your conversation, you are going to want to find the SSL conversation. In netmon, it will look like this: <br />
<a href="http://lh5.ggpht.com/_RuRKSkpoFrM/S8cFfOBdAXI/AAAAAAAAAQY/KuclLGoY69E/s1600-h/clip_image001%5B7%5D.png"><img alt="clip_image001" border="0" height="33" src="http://lh4.ggpht.com/_RuRKSkpoFrM/S8cFfgn2v-I/AAAAAAAAAQc/7wg1d8Q4yOE/clip_image001_thumb%5B4%5D.png?imgmax=800" style="border-width: 0px; display: inline;" title="clip_image001" width="757" /></a> <br />
<br />
What happens here, generally, is that the client offers a list of supported ciphers in the SSL: Client Hello. In netmon, you can see this by selecting that packet as I have done above. In the ‘Frame details’ pane, you can expand ssl: Client Hello.–> TlsRecordLayer: –> SSLHandshake –> Client Hello:. You should see a list of CipherSuites listed in order of preference. See the bottom of the picture below. <br />
<a href="http://lh6.ggpht.com/_RuRKSkpoFrM/S8cFgJQCCJI/AAAAAAAAAQg/LygCkrXOZIQ/s1600-h/image%5B11%5D.png"><img alt="image" border="0" height="527" src="http://lh4.ggpht.com/_RuRKSkpoFrM/S8cFgnxmNSI/AAAAAAAAAQk/1n_ct1YwGGk/image_thumb%5B5%5D.png?imgmax=800" style="border-width: 0px; display: inline;" title="image" width="642" /></a> <br />
<br />
The server will respond with cipher it wants. You can see this in the (likely) next packet under ssl –> TlsRecofdLayer-> SSLHandshake –> ServerHello –> CipherSuite. In this case, both client and server are running Win 2k8 r2. <br />
<a href="http://lh6.ggpht.com/_RuRKSkpoFrM/S8cFhO8qKvI/AAAAAAAAAQo/sjB9Kw7YNro/s1600-h/image%5B17%5D.png"><img alt="image" border="0" height="393" src="http://lh6.ggpht.com/_RuRKSkpoFrM/S8cFhlNE3rI/AAAAAAAAAQs/_Dd-aO2n0_U/image_thumb%5B9%5D.png?imgmax=800" style="border-width: 0px; display: inline;" title="image" width="618" /></a> <br />
<br />
As you can see, between Win 2k8r2 and Win 2k8r2 we attain TLS_RSA_WITH_AES_128_CBC_SHA. <br />
There are several methods to influence the SSL Handshake. The links above will be useful in starting that journey. <br />
<br />
One note on AES-128 cipher strength. For a measure of scale, a computer with a billion processing elements, each capable of trying a billion keys every second, would be able to try (2^60 keys/second). That means it would take (2^128 keys) / (2^60 keys/second) = 2^68 seconds to brute-force check all 128-bit keys. That is about 10^13 years to crack the key, or about 1000 times the age of the universe. Realistically, you would only need to try half the keys on average so that would be 500 times the age of the universe. <br />
<br />
Or you could find a flaw in the algorithm... <br />
or steal the certificate/password...</div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com2tag:blogger.com,1999:blog-10074565.post-90696476550515099802010-03-31T16:43:00.006+00:002013-12-30T19:48:26.041+00:00Using powershell to get ntfs info (such as cluster size)<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="WordSection1">
<div class="MsoNormal">
20100331 - slight update. Converting the hex items to dec and allowing passing of multiple drives.<br />
20131230 - slight update. Changed the convert to use an Int64 instead of int32 as I was getting overflow on larger drives<br />
<br />
A new function for my library. Base idea copped from Jacques Barathon [MS] at the bottom of <a href="http://www.vistax64.com/powershell/77645-getting-cluster-size-your-hard-disk-2.html">this</a> thread and hashed out to get all the properties.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-alt:"Arial Rounded MT Bold";
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-520092929 1073786111 9 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
span.EmailStyle15
{mso-style-type:personal;
mso-style-noshow:yes;
mso-style-unhide:no;
mso-ansi-font-size:11.0pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.WordSection1
{page:WordSection1;}
-->
</style> <br />
<div class="MsoNormal">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">function</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">get-ntfsinfo</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">param</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> ([</span><span style="color: teal; font-family: "Courier New"; font-size: 10pt;">char</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">[]]</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$drive</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"c"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$drive</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">foreach</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">test-path</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"$($_):"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$cs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">new-object</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">PSObject</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$cs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">add-member</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">NoteProperty</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">Drive</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$_</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$output</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (fsutil fsinfo ntfsinfo </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"$($_):"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">foreach</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$line</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">in</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$output</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$info</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$line</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.split(</span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">':'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: green; font-family: "Courier New"; font-size: 10pt;">#if the value is hex, convert to dec and put hex in ()<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$info</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">[1].trim().startswith(</span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'0x0'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">)) { <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$info</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">[1] </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> [</span><span style="color: teal; font-family: "Courier New"; font-size: 10pt;">Convert</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">]::</span><span style="color: saddlebrown; font-family: "Courier New"; font-size: 10pt;">ToInt64</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">((</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$info</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">[1].Trim()),16).</span><span style="color: saddlebrown; font-family: "Courier New"; font-size: 10pt;">toString</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">() </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">+</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">" ("</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">+</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$info</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">[1].Trim().toString() </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">+</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">")"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$cs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">add-member</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">NoteProperty</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$info</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">[0].trim().Replace(</span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">' '</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">,</span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">'_'</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">) </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$info</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">[1].trim()<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$info</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">=</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$null</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$cs</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> } </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">else</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">throw</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"Drive '$_' not found"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> } <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;">}</span><o:p></o:p></div>
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span><br />
<div class="MsoNormal">
<br />
A basic run gives you:<br />
<span style="font-family: "Courier New",Courier,monospace;">PS C:\Windows\system32> get-ntfsinfo e<br />
<br />
<br />
Drive : e<br />
NTFS_Volume_Serial_Number : 0xeabe7aefbe7ab423<br />
Version : 3.1<br />
Number_Sectors : 558614527 (0x00000000214bc7ff)<br />
Total_Clusters : 69826815 (0x00000000042978ff)<br />
Free_Clusters : 36249097 (0x0000000002291e09)<br />
Total_Reserved : 0 (0x0000000000000000)<br />
Bytes_Per_Sector : 512<br />
Bytes_Per_Cluster : 4096<br />
Bytes_Per_FileRecord_Segment : 1024<br />
Clusters_Per_FileRecord_Segment : 0<br />
Mft_Valid_Data_Length : 262144 (0x0000000000040000)<br />
Mft_Start_Lcn : 786432 (0x00000000000c0000)<br />
Mft2_Start_Lcn : 2 (0x0000000000000002)<br />
Mft_Zone_Start : 786496 (0x00000000000c0040)<br />
Mft_Zone_End : 837664 (0x00000000000cc820)<br />
RM_Identifier : 04E578BF-2D2F-11DF-9782-18A9055883A2</span><br />
<br />
But the nice thing here is being able to say<br />
<span style="font-family: "Courier New",Courier,monospace;">PS C:\Windows\system32> (get-ntfsinfo e).Bytes_Per_Cluster</span><br />
<span style="font-family: "Courier New",Courier,monospace;">4096</span><br />
<br />
<br /></div>
<div class="MsoNormal">
I then looped it to check cluster size (what I really wanted) on each drive on the server.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt;">foreach</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$drive</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">in</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">Get-PSDrive</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: "Courier New"; font-size: 10pt;">where</span></b><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> {</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$_</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.Provider.name </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">-eq</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"FileSystem"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">}) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">if</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> (</span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$drive</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">.free </span><span style="color: red; font-family: "Courier New"; font-size: 10pt;">-ne</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: purple; font-family: "Courier New"; font-size: 10pt;">$null</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;">) {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> </span><span style="color: maroon; font-family: "Courier New"; font-size: 10pt;">"$drive - $((get-ntfsinfo $drive.name).bytes_per_cluster)"</span><span style="color: black; font-family: "Courier New"; font-size: 10pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: black; font-family: "Courier New"; font-size: 10pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br />
gives output like:</div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-alt:"Arial Rounded MT Bold";
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-520092929 1073786111 9 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
span.EmailStyle15
{mso-style-type:personal;
mso-style-noshow:yes;
mso-style-unhide:no;
mso-ansi-font-size:11.0pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-size:10.0pt;
mso-ansi-font-size:10.0pt;
mso-bidi-font-size:10.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.WordSection1
{page:WordSection1;}
-->
</style> <br />
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
C - 4096<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
E - 4096<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
G - 65536<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
J - 4096<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
K - 4096<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
L - 4096<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
M - 65536<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
N - 65536<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
O - 65536<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
Q - 4096<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
S - 65536<o:p></o:p></div>
<div class="MsoNormal" style="font-family: "Courier New",Courier,monospace;">
T - 65536<o:p></o:p></div>
<div class="MsoNormal">
<span style="font-family: "Courier New",Courier,monospace;">Z – 4096</span><o:p></o:p></div>
</div>
<div class="MsoNormal">
<br />
<br />
Let me know if you use it…</div>
</div>
</div>
cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com7tag:blogger.com,1999:blog-10074565.post-59572413617166451272010-03-29T17:09:00.005+00:002011-03-09T09:10:17.923+00:00powershell: delete files older than X<div dir="ltr" style="text-align: left;" trbidi="on">It really is that easy.<br />
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-alt:"Arial Rounded MT Bold";
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-520092929 1073786111 9 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
span.EmailStyle15
{mso-style-type:personal;
mso-style-noshow:yes;
mso-style-unhide:no;
mso-ansi-font-size:11.0pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.WordSection1
{page:WordSection1;}
-->
</style> <br />
<div class="MsoNormal"><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Get-ChildItem</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$env:temp</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">/myfiles</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">where</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$_</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Lastwritetime </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-lt</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (date).addminutes(</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">15)} | </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">remove-item</span></b></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b>E</b>verybody has needed the 'delete files older than X' script. One more thing that is easier in powershell. In this case I have<span style="color: purple; font-family: 'Courier New'; font-size: 10pt;"> $env:temp</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">/myfiles</span> as my directory containing the files. I could also add -recurse to get-childitem if I wanted to get subdirectories as well. Anonymous noted below that you can add a test to exclude directories if you just want to clean the files out of the directory structure. I am using addminutes to delete files older than now - 15 minutes but you have other options. More on that <a href="http://msdn.microsoft.com/en-us/library/system.datetime_members.aspx">here</a>.</div><div class="MsoNormal"><br />
Note that if we want to delete all files older than X we would use -lt. ie, the timestamp of the file is older than 15 minutes ago. If we want to delete files newer than X we would use -gt. ie, the timestamp of the file is newer than 15 minutes ago. X, in our case, is the time now minus 15 minutes.<br />
<o:p></o:p></div><div class="MsoNormal"><br />
We are going to 'at' it. Although the Vista and later scheduling engine is vastly improved and renamed to schtasks.<br />
<br />
We are going to run this every 15 minutes.<br />
schtasks /create /ru "NT Authority\NETWORK SERVICE" /F /sc daily /mo 1 /ri 15 /st 00:00 /du 0023:50 /tr "powershell -command {<br />
<div class="MsoNormal"><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">Get-ChildItem</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> </span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$env:temp/myfiles</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> | </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">where</span></b><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> {`</span><span style="color: purple; font-family: 'Courier New'; font-size: 10pt;">$_</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">.Lastwritetime </span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-lt</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;"> (date).addminutes(</span><span style="color: red; font-family: 'Courier New'; font-size: 10pt;">-</span><span style="color: black; font-family: 'Courier New'; font-size: 10pt;">15)} | </span><b><span style="color: cadetblue; font-family: 'Courier New'; font-size: 10pt;">remove-item -recurse</span></b>" /TN "File Delete"}<br />
<br />
<br />
Updated: 20110310 - fixed some issues w/ the schtask line (notice the `) and added a note about the pscontainers test noted by anonymous below.</div><o:p></o:p></div></div>cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com11tag:blogger.com,1999:blog-10074565.post-21504297219668577382010-03-26T13:11:00.007+00:002010-06-21T11:27:26.888+00:00Fully patch a server using powershell and vbs<p>Update: 201006018 – changed the reboot portion of the script to watch uptime instead of ping, some of my servers weren’t coming down fast enough.  B)</p> <p>For our last patch cycle we used Harry Johnston's vbs script to manage our updates.  His script is <a href="http://www.scms.waikato.ac.nz/%7Eharry/wsusupdate.vbs" linkindex="16">here</a>. (His very basic home page is <a href="http://www.scms.waikato.ac.nz/%7Eharry" linkindex="17">here</a>. I found the script from a newsgroup post or I would ping back or similar.  Thanks Harry if you see this.)</p> <p>If you want to do this completely with powershell, James O’Neill has posted is a pretty definitive discussion, <a href="http://blogs.technet.com/b/jamesone/archive/2009/01/27/managing-windows-update-with-powershell.aspx">Managing Windows Update with PowerShell</a>.  I don’t have powershell on all of my servers and don’t want to make that a requirement for this solution.  As such, we are doing the actual work w/ the already present cscript engine and just managing the process w/ powershell. <br /> <br />Harry’s very useful script works whether you are pointing to windows updates or your own WSUS server.  It checks for new updates, downloads, installs and reports whether you need a reboot.  If you don't need a reboot, it runs itself again until it either needs a reboot or finds no patches.  Cool script.  we modified it slightly to spit out the hostname we were working w/ as we psexec'd it to run on a bunch of computers. <br /> <br />When we did this at first, we ran a few loops.  First we copied the winupdates.vbs script to the c:\ on each computer to be updated.  We would have run it from the fileshare but we wanted to have a single solution for our servers.  Win2k8 servers run into a UAC problem w/ psexec.  there may be a better way but we decided to pass -s to psexec to run as system (thus avoiding the UAC issues).  Because we need to run as system, we cannot call the script from a network location (more specifically, we didn’t want to manage opening a network location that could be read by all the machine accounts) <br /> <br />We then ran a loop to pop out a command window for each server and run the script through sysinternal's psexec.  When the script finished, it would report if it needed a boot.  We would boot and then run the script again until the script had nothing to do. <br /> <br />This was much easier than getting on the servers and doing it but meh, it was still too much work. <br /> <br />The below powershell script will automate the copying the script and then loop the running, booting, waiting until there are no more patches to install.  I did put in a 10 boot limit and a 15 minute limit waiting for reboots. <br /> <br />Save the script below as PSPatch.ps1.  you will need to update the path to your winupdates.vbs and psexec at the top.   To run it, just pass it a server name. <br />./pspatch.ps1 servertopath <br /> <br />Let me know if you use it... <br /><style><br /><!-- /* Font Definitions */ @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-alt:"Times New Roman"; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-520092929 1073786111 9 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}span.EmailStyle15 {mso-style-type:personal; mso-style-noshow:yes; mso-style-unhide:no; mso-ansi-font-size:11.0pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; color:windowtext;}.MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}@page WordSection1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;}div.WordSection1 {page:WordSection1;}--></style> <br /></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: green; font-size: 10pt">#patch server <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: blue; font-size: 10pt">param</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> ( <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span></span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$server</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt">) <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p> </p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$scriptpath</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">=</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"c:\toolkit\scripts\winupdates.vbs"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$psexec</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">=</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"C:\Toolkit\sysint\psexec.exe"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p> </p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: blue; font-size: 10pt">if</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><span style="font-family: "Courier New"; color: red; font-size: 10pt">-not</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">Test-Path</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$scriptpath</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">)) { </span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">throw</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Could not find Winupdates.vbs.<span style="mso-spacerun: yes">  </span>Set location at top of script."</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> } <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: blue; font-size: 10pt">if</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><span style="font-family: "Courier New"; color: red; font-size: 10pt">-not</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">Test-Path</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$psexec</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">)) { </span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">throw</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Could not find psexec.<span style="mso-spacerun: yes">  </span>Set location at top of script."</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> } <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: green; font-size: 10pt">#make sure the name is resolvable <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: blue; font-size: 10pt">try</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> {</span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$dnsresult</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">=</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> [</span><span style="font-family: "Courier New"; color: teal; font-size: 10pt">System.Net.DNS</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">]::</span><span style="font-family: "Courier New"; color: saddlebrown; font-size: 10pt">GetHostEntry</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">(</span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$server</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">)} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: blue; font-size: 10pt">catch</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> { <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span></span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">throw</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Servername '$server' does not resolve to an IP"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt">} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: green; font-size: 10pt">#check if the server is alive <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$ping</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">=</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">new-object</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">System.Net.NetworkInformation.Ping</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$Reply</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">=</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$ping</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">.Send(</span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$server</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">) <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: blue; font-size: 10pt">if</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> ($(</span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$Reply</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">.status) </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">-ne</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Success"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">) { <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span></span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">throw</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Could not ping $server.<span style="mso-spacerun: yes">  </span>Response $($reply.Status).<span style="mso-spacerun: yes">  </span>Skipping..."</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt">}<span style="mso-tab-count: 1">     </span> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p> </p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p> </p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: green; font-size: 10pt">#check if winupdate.vbs is in place <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: blue; font-size: 10pt">if</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><span style="font-family: "Courier New"; color: red; font-size: 10pt">-not</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">test-path</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"\\$server\c$\winupdates.vbs"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">)) { <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span></span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">Write-Host</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Copying winupdates.vbs to \\$server\c$"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><i><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">-ForegroundColor</span></i><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">Yellow</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span></span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">copy</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$scriptpath</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">\\$server\c$</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt">} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p> </p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$i</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">=</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> 0 </span><span style="font-family: "Courier New"; color: green; font-size: 10pt">#as a sanity check we are only allowing 10 loops <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: blue; font-size: 10pt">while</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$i</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">-lt</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> 10) { <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span></span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$i</span><span style="font-family: "Courier New"; color: red; font-size: 10pt">++</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span></span><span style="font-family: "Courier New"; color: green; font-size: 10pt">#run update <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span>&</span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$psexec</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> \\$server -s cscript c:\winupdates.vbs <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span></span><span style="font-family: "Courier New"; color: green; font-size: 10pt">#check exit code <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span></span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">switch</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$LASTEXITCODE</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">) { <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span>2<span style="mso-tab-count: 1">     </span>{ </span><span style="font-family: "Courier New"; color: green; font-size: 10pt"># no more updates to install <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 3">                  </span></span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">write-host</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Servername '$server' is fully patched after $i loops"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><i><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">-ForegroundColor</span></i><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">green</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 3">                  </span>exit <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 2">            </span>} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span>3<span style="mso-tab-count: 1">     </span>{ </span><span style="font-family: "Courier New"; color: green; font-size: 10pt">#reboot needed <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 3">                  </span></span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">Write-Host</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Reboot required..."</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><i><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">-ForegroundColor</span></i><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">Yellow</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 3">                  </span></span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$j</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">=</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> 0 </span><span style="font-family: "Courier New"; color: green; font-size: 10pt">#as a sanity check we are only allowing 15 loops here as well <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 3">                  </span></span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$uptime</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">=</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">Get-WmiObject</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><i><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">-computer</span></i><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$server</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><i><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">-class</span></i><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">Win32_PerfFormattedData_PerfOS_System</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">).SystemUptime <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 3">                  </span>shutdown /r /m </span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$server</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 3">                  </span></span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">while</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$uptime</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">-gt</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> 600 )<span style="mso-spacerun: yes">  </span>{  <span style="font-family: 'Courier New'; color: green; font-size: 10pt"># We are checking the uptime and waiting until we get a value of less than 5 minutes uptime as our ‘reboot finished’ test </span></span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 4">                        </span></span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$j</span><span style="font-family: "Courier New"; color: red; font-size: 10pt">++</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 4">                        </span></span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">sleep</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> 60 <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 4">                        </span></span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$ErrorActionPreference</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">=</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Stop"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 4">                        </span></span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">try</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> { <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 5">                              </span></span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$uptime</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">=</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">Get-WmiObject</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><i><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">-computer</span></i><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$server</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><i><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">-class</span></i><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">Win32_PerfFormattedData_PerfOS_System</span><span style="font-family: "Courier New"; color: black; font-size: 10pt">).SystemUptime <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 5">                              </span></span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">Write-Host</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Waiting for server to reboot ($uptime)"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 4">                        </span>} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 4">                        </span></span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">catch</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> { <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 5">                              </span></span><b><span style="font-family: "Courier New"; color: cadetblue; font-size: 10pt">Write-Host</span></b><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Waiting for server to reboot ($uptime)"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 4">                        </span>} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 4">                        </span></span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">if</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> (</span><span style="font-family: "Courier New"; color: purple; font-size: 10pt">$j</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: red; font-size: 10pt">-gt</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> 15) {<span style="mso-spacerun: yes">  </span></span><span style="font-family: "Courier New"; color: green; font-size: 10pt">#if we have looped 15 times we have a problem <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 5">                              </span></span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">throw</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"Server has not rebooted in 15 minutes. Something is wrong"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 4">                        </span>} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 4">                        </span> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 3">                  </span>} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 5">                              </span> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 2">            </span><span style="mso-spacerun: yes"> </span>} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 2">            </span><span style="mso-spacerun: yes"> </span> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span></span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">default</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> { </span><span style="font-family: "Courier New"; color: green; font-size: 10pt">#error or unexpected code <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 2">            </span></span><span style="font-family: "Courier New"; color: blue; font-size: 10pt">throw</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> </span><span style="font-family: "Courier New"; color: maroon; font-size: 10pt">"We either have an error above or an unexpected error code.<span style="mso-spacerun: yes">  </span>Please check above for details"</span><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 2">            </span>} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"><span style="mso-tab-count: 1">      </span>} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt">} <p></p> </span></p> <p style="mso-layout-grid-align: none" class="MsoNormal"><span style="font-family: "Courier New"; color: black; font-size: 10pt"> <p> </p> </span></p> <div class="MsoNormal"></div> cornasdfhttp://www.blogger.com/profile/02328281836126704285noreply@blogger.com0