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

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
KS
Jun 10, 2003
Outrageous Lumpwad
I have what I think is a very basic question. For commands that return data tables like this:

adaz posted:

pre:
HostName   DisplayName      EntryDate            Usages
compy1      blahblah         1/1/1000             10000
compy2      blahblah         1/1/1000             10000
compy3      foobar           1/1/1000             10000
compy4      snafu            1/1/1000             10000
compy5      foobar           1/1/1000             10000
compy6      foobar           1/1/1000             10000

How should I be scraping arbitrary data out of it? For instance, if I know I want the last row? Or just the hostname value from the last row? I know how to use | where and match a regex, but I am more interested in how it should be done when the data in the fields isn't known.


Edit: finally answered my own question reading about manipulating objects. select-object is what I needed.

KS fucked around with this message at 07:11 on Aug 23, 2011

Adbot
ADBOT LOVES YOU

KS
Jun 10, 2003
Outrageous Lumpwad

adaz posted:

There are a lot of different ways of doing it ... Is any of that any help?

Thanks so much for the effort you put into this. I found the specific tool I needed and found a toolbox full of other useful things to boot.

Another question: I think I have a pretty good grasp on handling errors and building logic into a script to handle failures. However, yesterday I had one script simply hang -- it didn't error out, but one of the cmdlets in the script hung indefinitely. What are the methods for dealing with this mode of failure?

KS
Jun 10, 2003
Outrageous Lumpwad
So I'm a rank beginner at this and I'm embarrassed to post this snip. When a SAN-based snapshot is presented to a different server, it shows up with some flags set on the volumes. I am trying to enumerate those volumes and generate a diskpart script to unset the flags.

code:
$diskpart = diskpart /s diskpartlist.txt | Select-String -pattern "Hidden"

$a = $diskpart[0]
$a = $a.tostring()
$a = $a.substring(2,13)
$a = "select $a"

$b = $diskpart[1]
$b = $b.tostring()
$b = $b.substring(2,13)
$b = "select $b"


write-output $a "att vol clear readonly" "att vol clear hidden" "att vol clear shadowcopy" $b 
`"att vol clear readonly" "att vol clear hidden" "att vol clear shadowcopy" | out-file diskpart.txt

diskpart /s diskpart.txt
The content of diskpartlist.txt is just "list volume" The above generates a file that can be fed into diskpart that looks like:

code:
select volume 3
att vol clear readonly
att vol clear hidden
att vol clear shadowcopy
select volume 7
att vol clear readonly
att vol clear hidden
att vol clear shadowcopy
I ran into so many things I need to learn along the way with the format of the data and breaking it up into useful chunks: system objects vs. arrays vs. strings and the tools you can use for each. For instance, you can write "select $a" to a file and it works, but you cannot write "select $a.substring(2,13)"

I know it shouldn't be this hard, and I really want to learn how to do this better (and generalize it for result sets of indeterminate size). I just feel lost without awk and sed.

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