|
I've just started trying to get into Powershell. I do a fair amount of scripting, with both VBScript and batch files. My problem is that I don't really have a problem right now that I need a new script for. Is there any benefit to replacing my current vbs and bat files with powershell scripts? Or is there anything flat-out awesome that it does, maybe a solution that I could find a problem for? I can make it beep, but that isn't really useful.
|
# ¿ May 6, 2010 04:30 |
|
|
# ¿ Apr 27, 2024 23:50 |
|
adaz posted:I guess next time you need a script written pop in here with the problem and we'll go through it. Or if you want to rewrite one of your current ones can help yo out with that. It's funny you should mention that...I spent most of the day poking around at a script that I already have a version of, but this new one would be way nicer. Right now, it's a vbs that reads the username, sn, and lastlogin time from AD and writes it to an excel file. Then I run a macro to delete every row with a lastlogin time that's less than 30 days from today, so I'm left with a list of accounts that haven't logged into the domain in the last month. I have the export part working, and I have the macro working, but I can't get the export to open and write in the file with the macro. It doesn't need to be so convoluted, but this is tons simpler than the first version.
|
# ¿ May 7, 2010 03:42 |
|
adaz posted:The full script, coming in at a cool 22 lines This was just what I needed, and with a few tweaks I can use it for a couple of other things, thanks!
|
# ¿ May 11, 2010 03:02 |
|
adaz posted:You only wanted a few properties returned, so let's set those. The [void] is a type accelerator that casts the return to, well, null. If you remove it you'll see the $Searcher object returns a number indicating how many items it's searching for everytime you add something. Doesn't hurt anything, but annoying if you leave it. I ran into some issues with this today. I tried to add some additional properties to look for, but they don't print. I added them to the 3 spots I quoted, and instead of displaying like the rest, they create a column where I tell it and then leaves it empty. For example, if I wanted to add SamAccountName I would do this: code:
code:
code:
|
# ¿ May 12, 2010 03:44 |
|
adaz posted:What you ran into was something really stupid and annoying with the language: Case Doesn't Matter Except When It Does. Hey, it worked! That seems pretty stupid, though. Is there an online resource for that sort of thing? I've tried Technet's scripting center, but it's nearly impossible for me to find what I'm looking for there.
|
# ¿ May 13, 2010 03:04 |
|
I've been messing around with Powershell for a week or so, and I've found another question. Is there something you can do at the command prompt that you can't do with Powershell? I do a pretty fair amount of my daily work in a command window, and I've tried a half-dozen or so commands that worked in Powershell. It would be nice to not have to keep switching shells to do different things. I tried to google this, but the only real result was about how awesome Powershell is for scripting.
|
# ¿ May 20, 2010 00:25 |
|
What's going on with my script? I have a directory with about 200 files. There's 8 different extensions, making it: file.ex1, file.ex2, file.ex3, file2.ex1, file2.ex2, file2.ex3... I only care about 4 of the extensions, and I need all 4 of them. My thought is to count the number of files with the extensions I care about and put the numbers in an excel document. That part works:code:
code:
On a slightly related note, how do I create an excel document with 5 worksheets? This thing is done to 5 different directories, and my script starts making GBS threads all over when I need sheet 4.
|
# ¿ Jun 18, 2010 04:43 |
|
dalin posted:The equality operator is "-eq", not "=". Also I don't think you can string them together like that (x -eq y -eq z). Try this: Hey, that worked, thanks! If anyone else is curious about adding worksheets to excel, I found this today: code:
Another question: any resources on how to format the output of select-string? I have a 2-liner that produces pretty decent output if I paste it into my session, but if I run the .ps1, the output changes.
|
# ¿ Jun 19, 2010 02:57 |
|
adaz posted:Can you give us the example? I mean, select-string outputs whatever it finds as a string, not sure what you want to do with it. I'll have to look when I get to work. I just tried it at home and it worked like I wanted it to.
|
# ¿ Jun 21, 2010 22:57 |
|
adaz posted:Powershell v1 versus v2 maybe? Also keep in mind that if powershell is returning some really stupid formatting or type for whatever reason the [string] type accelerator can be golden. Works fantastic for a lot of things, especially ADSI type searches that output fine until you try to work with them. I'm running Win7 on both machines. That comes with v2 out of the box, right? The differences were something like: code:
code:
|
# ¿ Jun 22, 2010 04:43 |
|
adaz posted:What is the full code though that's generating all this? I'm not sure.. what are you piping to select string (or inputting)? This is the script: code:
code:
code:
|
# ¿ Jun 24, 2010 04:40 |
|
adaz posted:That is really bizarre and I don't know why it is doing that to you. I tried quite a few things to get your original code to work executed as a ps1 but nothing would, sorry. I did, however, find a way around that output problem and it that works just fine. I'll give that a shot tomorrow. Some other things I came up with today were creating a batch file with the powershell commands in it or some crazy thing that I found on Technet that will sort and filter the results. I don't really understand it, so I was having issues making it work.
|
# ¿ Jun 25, 2010 03:02 |
|
|
# ¿ Apr 27, 2024 23:50 |
|
Bob Cthulhu posted:I'll give that a shot tomorrow. Some other things I came up with today were creating a batch file with the powershell commands in it or some crazy thing that I found on Technet that will sort and filter the results. I don't really understand it, so I was having issues making it work. I got it working today. Did a Get-Childitem with a format-table and the second line was a select-string, I believe a sort to get what I needed, and a format-table. I found something interesting today: if you use a format-table in your script, you have to format-table every line that has output. You can't mix implied and explicit formatting.
|
# ¿ Jun 26, 2010 03:38 |