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
Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
This will do what you want (untested):

code:
foreach ($i in Get-ChildItem \\roamserver\profiles) {
  Remove-Item $i\ntprofile\Spark -recurse
}
You may have to tack \\roamserver\profiles\ on there before the $i.

Here is a page on loops in powershell that I used to recall syntax. It should give you an idea of what's possible. You're probably going to use foreach more than any other loop structure in system admin.

To add the logging functionality just tack an echo statement or whatever you prefer in that loop. $i is a Directory object that you can do all sorts of fun things with.

Dessert Rose fucked around with this message at 21:08 on Mar 31, 2010

Adbot
ADBOT LOVES YOU

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

adaz posted:

LDAP properties & names are the same with powershell as vbscript.

What you ran into was something really stupid and annoying with the language: Case Doesn't Matter Except When It Does. It's my fault I'm used to it so didn't even think to mention it - the properties returned off of the search result collection are lower case ONLY. If you try to access them in uppercase it'll return null and not throw and error or anything helpful. Your code will work fine with this one change:


I actually filed a bug report about it as powershell is essentially supposed to be case agnostic but apparently it's just How .NET Works

e: Note that the $csvobject is also retarded in that you can assign using any case - it'll even display in that case - but gently caress all if you can access it with specific case:



I don't know if it actually works if you spell it right, but I'm sure it won't work if you spell it wrong.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
I'm trying to replace some text in a file, and Powershell is thwarting my attempts to make it useful.

Basically I have a .prf exported from the Office Customization Tool, and I want to replace the account name with whatever the user puts in. According to everyone on the internet, I want to do some variant of:

code:
(Get-Content input.prf) | foreach {$_ -replace "LOGIN", "BBQ"} | Set-Content new.prf
but it does worse than not working - it mangles the file and doesn't actually replace what I'm trying to replace.

In the case of the above code, it destroys line endings horribly. I also tried:

code:
$what = Get-Content input.prf
$what -replace "LOGIN", "BBQ" > new.prf
but that not only doesn't replace the login text but intersperses NULLs between every character in the output file.

Powershell can't be this incompetent at working with text files. What am I missing? I'm about to punt and just do it with C#.

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