- 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
|
|
#
¿
Dec 2, 2011 20:21
|
|
- 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
|
|
#
¿
Jan 3, 2012 16:39
|
|
- 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?
|
|
#
¿
Jan 9, 2012 16:57
|
|
- 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.
|
|
#
¿
Jan 9, 2012 18:13
|
|
- 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
|
|
#
¿
Jan 11, 2012 17:44
|
|
- Jethro
- Jun 1, 2000
-
 I was raised on the dairy, Bitch!
|
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!"
}
}
|
|
#
¿
Jan 29, 2013 17:25
|
|
- Jethro
- Jun 1, 2000
-
 I was raised on the dairy, Bitch!
|
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
|
|
#
¿
Mar 22, 2013 16:32
|
|