|
I'm finally digging in and figuring out this PowerShell crap. I'm rewriting a VBscript in PS and so far things are going as expected. I ran into some weird behavior where this:code:
Manufacturer: LENOVO Model: 276712U Memory: 3.9 Gb Number of Processors: 1 Name: TACO-T400 With the name at the bottom instead of the top. I hopped on irc and asked for help and was told to use Format-List instead which works great. This is what I'm using instead: code:
Ashex fucked around with this message at 00:29 on Sep 17, 2011 |
# ¿ Sep 17, 2011 00:21 |
|
|
# ¿ May 6, 2024 13:20 |
|
I feel stupid, for some reason when I just tried doing that things sorta broke. I actually tried using Here-Strings and I kept getting the following error (as I am now) code:
code:
For the Disks I want to record each drive but from how I'm using the Excel it inserts each WMI Property into its own cell so only the last disk reported will be recorded (I need to figure out a way to just add columns when there is more then one line given back, I'm considering a for loop with that property). Ashex fucked around with this message at 18:19 on Sep 19, 2011 |
# ¿ Sep 19, 2011 18:05 |
|
Am I missing something? Edit: Going back to using format-list, I remembered why I was having issues storing it in a variable, when I try doing as you suggested before this happens when I try to print the variable with write-Host: code:
Ashex fucked around with this message at 20:53 on Sep 19, 2011 |
# ¿ Sep 19, 2011 20:15 |
|
Thanks for pointing that out for me, I don't see an easy way to append data to that without piping the gently caress out of it so I'm going to stick with Here-Strings (mainly because I'm more or less done with the script). I've got one last question (thanks for hanging around to help me), how exactly does one do error handling? I've searched around on the web and there are a few different methods but none of them seem particularly clear. Now that I've built all the functions, I'm going to stick it in a for loop. I'm under the assumption I'll use something like Catch to check for an error, do I have to write a Catch for each type of error if I want to know what went wrong? This is the loop I'm talking about : code:
|
# ¿ Sep 20, 2011 00:27 |
|
Got it, I'm going to add some Catches for WMI. Is there an easy way to find what errors it can throw? I mostly want to write a catch for access denied (done), unable to connect, and other weird WMI errors that may occur. Edit: Looks like I've got it all, I want to catch a couple WMI errors like GetWMIManagementException and GetWMICOMException but they're not actual Exceptions Ashex fucked around with this message at 21:57 on Sep 20, 2011 |
# ¿ Sep 20, 2011 19:44 |
|
Thanks for looking around, error handling with WMI is a bitch. I couldn't find a good way to handle connection failures so I'm using Test-Connection to make sure each computer is online before it runs a report.
|
# ¿ Sep 22, 2011 00:10 |
|
I've run into a slight problem with an incrementing variable that I can't control, basically I have a function that retrieves the disk drives on a computer and enters it into a spreadsheet. The problem is I'm using an excel function that writes one cell at a time so to adjust for multiple drives I have it insert a row to add a new drive, because of this I end up with a blank row at the end if there's only one disk drive. This is the function: code:
|
# ¿ Sep 22, 2011 17:56 |
|
I see you have run into the same problem I was having! I wanted to be able to catch the RPC error message but couldn't find a way to do it, I eventually caved and wrote a General Catch that actually explained to the user what to do if they got X error from WMI. I found this article to be somewhat helpful though. As for using $colitems.count, For some reason I don't get anything back: code:
|
# ¿ Sep 22, 2011 22:42 |
|
I'm running it on my laptop, if I do $colitems.name I get my C: drive. $colitems|gm spits out all the properties available. Edit: This is interesting, I ran it against a server 2008 box and I do get a number back. Edit Edit: Okay this is interesting, if I use a computer with more then one drive: code:
code:
Edit: Nope, I tried using if ($colitems.count) {$global:intRow++} with no success. Ashex fucked around with this message at 00:18 on Sep 23, 2011 |
# ¿ Sep 23, 2011 00:00 |
|
Phone posted:Did you submit your issue to Hey, Scripting Guy!? If not... uh... I'll give you the complete script :P Just send me a pm. Edit: I sent an email to him, I'll see what I get. Ashex fucked around with this message at 17:56 on Sep 26, 2011 |
# ¿ Sep 26, 2011 17:49 |
|
|
# ¿ May 6, 2024 13:20 |
|
I tried what you suggested and when I tested it out it looked like it would work but when I used it in the script it didn't increment the row for the computer with one drive code:
|
# ¿ Sep 29, 2011 20:22 |