Search Amazon.com:
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 $3,400 per month for bandwidth bills alone, and since we don't believe in shoving popup ads to our registered users, we try to make the money back through forum registrations.
  • Post
  • Reply
Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

How sure are you that you're running v1? I'm pretty sure 2008 SP2 has v2 already. Try looking at $psversiontable. If it exists, you're running v2. If not you are indeed on v1.

E: \/\/ I guess I was wrong, since that is definitely what one would expect from v1.

Jethro fucked around with this message at Dec 2, 2011 around 20:36

Adbot
ADBOT LOVES YOU

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Moey posted:


Thanks again everyone!

Edit: Just out of curiosity sake, how would I add "where-object {$_.psiscontainer -eq false}" to my last line of code there? Everything I try breaks it.

code:
#Renames file to append crap user wants
gci | where-object {$_.psiscontainer -eq $false} | rename-item -newname {$_.basename + " - Cat Picture.tif"}

#Creates folders based on first 9 chars
gci | where-object {$_.psiscontainer -eq $false} | %{new-item -name $_.tostring().substring(0,9) -type directory -path .}

#moves files into folders based on file number
gci | where-object {$_.psiscontainer -eq $false} | %{move-item -path $_.name -destination "$($_.directoryname)\$($_.tostring().substring(0,9))\$($_.name)" }
Note that it's $false not false

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Siets posted:

Looks good, but do sub-expressions work inside of other sub-expressions? So I would ultimately have:

[regex]"(?<Amount>\d{1,3}(\,\d{3})*)"

edit: Removing instances of 134,04 and the like!
edit2: Crap, is ?<Amount> a Powershell-only syntax for use with -match, and doesn't work inside of .NET [regex]'s?
That's the standard .NET syntax for a named capture group, not just PowerShell. Is it giving you problems?

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

It seems to me that it would make a lot more sense to import this into a database of some sort (assuming it's not already in one) or Excel or something, since those tools are more or less designed to do this sort of thing.

If you really need to do this all in Powershell, I'd suggest you start by creating objects and adding properties see here.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

The Get-Date cmdlet can take a date, so something like [int](Get-Date -UFormat %V -Date $_.CreationTime) would get you what you want.

Add-Member wouldn't really help you here, because it only adds the member to a particular object instance.

Jethro fucked around with this message at Jan 11, 2012 around 17:54

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

adaz posted:

first solution

String.Split has a count parameter which you can use to limit the number of elements in the array. Also, if you use the -split operator (PS 2.0+), you can use regexes.
code:
$formatTable = @{}
foreach($line in $strlines) {
    $splitLine = $line -split "\s*:\s*", 2
    # this returns an array with a maximum of 2 elements.
    # Also, whitespace on either side of the : is discarded. 

    if($splitLine -is [system.array] -and $splitLine.Count = 2) {
       # first element is always going to be our key, I assume you don't want the white space so we trim that out and add it.
       # Still using fulltrim in case the key has leading whitespace
       $key = $splitLine[0].fulltrim
       $value = $splitLine[1]
       # make sure we aren't trying to add an empty key which will error out on us...
       if($key -ne [string]::empty) {
           $formatTable.add($key,$value)
       }
    }else {
      # Line with no : ! Unable to process, probably better write out an error or something here.
      write-host "Unable to process the line $line no : found in input string!"
    }
}

Adbot
ADBOT LOVES YOU

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

jonnii posted:

I added cmdletbinding, changed all the write-hosts to write-verbose, removed most of the aliases (what does mkdir alias to? is it new-item?).
Technically mkdir is not an alias, but a function that calls New-Item with -Type Directory

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