|
Jelmylicious posted:e: Aparently Get-Eventlog System should work too, so your second line should work as intended. Apart from it not showing the full info in your text file. So, at least use the export-csv. And then cry when the formatting is all messed up.
|
# ? Nov 23, 2011 16:33 |
|
|
# ? May 21, 2024 17:28 |
|
Thanks man, appreciate the help.
|
# ? Nov 23, 2011 16:33 |
|
Phone posted:And then cry when the formatting is all messed up. Piped with Format-List at the end? Would that help?
|
# ? Nov 23, 2011 16:34 |
|
Export-CSV is awesome and works most of the time, but when you get on one of those edge cases where whatever list of data you're trying to enumerate and get into a readable format it sucks. Luckily Technet has a ton of stuff about PS and a decent # of articles about piping stuff to Export-CSV.
|
# ? Nov 23, 2011 16:39 |
|
My quick test showed a nice CSV cooming from this, so I figured it would fit here. I always try using it first, if it doesn't work, then I start looking at alternatives/fixing it.
|
# ? Nov 23, 2011 16:46 |
|
kampy posted:I would just modify the script a bit, or perhaps just run something like: Sorry for the late reply, but thanks for the help. The project got backburnered for a while and we ended up just deleting all the files and redownloading and enforcing unique names on creation. But I'm going to keep this around regardless, thanks!
|
# ? Nov 23, 2011 19:55 |
|
Phone posted:Export-CSV is awesome and works most of the time, but when you get on one of those edge cases where whatever list of data you're trying to enumerate and get into a readable format it sucks. Honestly I never trust Export-CSV anymore and just use my own custom objects added to a list then export that. I've run into more cases where it doesn't work than where it does. code:
adaz fucked around with this message at 02:36 on Nov 24, 2011 |
# ? Nov 23, 2011 22:08 |
|
adaz posted:Honestly I never trust Export-CSV anymore and just use my own custom objects added to a list then export that. I've run into more cases where it doesn't work than where it does. This is awesome. I will probably work towards doing this for some of the things I am setting up. I finally have some free time so I started getting into my PS book. We have alot of user accounts in AD that are missing phone numbers, so I wrote/modified a little script to give me the names of these accounts. I figure next step is let it take arguments (or build it a little gui) so I can search for other empty attributes and allow it to select which OU to search instead of just the root of our users OU.
|
# ? Nov 24, 2011 02:01 |
|
Moey posted:This is awesome. I will probably work towards doing this for some of the things I am setting up. I finally have some free time so I started getting into my PS book. We have alot of user accounts in AD that are missing phone numbers, so I wrote/modified a little script to give me the names of these accounts. I figure next step is let it take arguments (or build it a little gui) so I can search for other empty attributes and allow it to select which OU to search instead of just the root of our users OU. Yep, this is a good idea and one of the many tasks Powershell is perfectly suited for. Even better if you can feed it data from SQL/CSV or whatever and let it fill in the phone number for you. ALso there was a typo in that code snippet, I fixed it just now.
|
# ? Nov 24, 2011 02:37 |
|
Is there anyway to automate this process with Windows Office 2010? I want to copy a table from a Microsoft Word document and paste it in excel. I wrote code that opens up a folder of .docx files, copies the whole table, opens up a specific Excel file, and than I'm stuck at appending (pasting) the table to the excel file. I'd assume that Powershell has access to the clipboard provided in Office 2010, correct?
|
# ? Dec 1, 2011 00:10 |
|
Rabid Snake posted:Is there anyway to automate this process with Windows Office 2010? I want to copy a table from a Microsoft Word document and paste it in excel. Yes it isn't too bad - how far does this Scripting Guys article on copying from excel/excel get you? Should cover what you need http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/08/copy-data-from-one-excel-spreadsheet-to-another-with-powershell.aspx You'll be dealing with the Office Interop namespace primarily. let me know if you get stuck and I can look into explicitly how to do it (I don't know off the top of my head, sorry )
|
# ? Dec 1, 2011 01:08 |
|
Howdy. I'm running into a frustrating issue trying to send a simple SMTP message from a server in Powershell v1. Here's the relevant portion of the script; the attachment is present and the path is correct. (I've omitted some object dumps I've added in the course of troubleshooting for clarity.) code:
code:
What am I doing wrong?
|
# ? Dec 2, 2011 19:00 |
|
You're not doing anything wrong by that code sample I stared at it for like 10 minutes and can't see anything wrong. I mean just copy pasting that code block gets me this: e: Oh you're using powershell v1. I don't have v1 handy anywhere to test it on, sec guessing it's because you're using an older version of the framework let me look at it. e2: If you do $msg.To after constructing/adding the address what is outputted? Are DisplayName, User,Host,Address also all blank? Even by v2 of the framework you aren't doing anything wrong. adaz fucked around with this message at 19:32 on Dec 2, 2011 |
# ? Dec 2, 2011 19:17 |
|
adaz posted:You're not doing anything wrong by that code sample I stared at it for like 10 minutes and can't see anything wrong. I mean just copy pasting that code block gets me this: DisplayName is blank, User, Host and Address have the appropriate entries. If it helps narrow it down, this is 64-bit Server 2008 Enterprise SP2 with the Windows Powershell feature installed. I'm guessing we need either to install v2 or put in a later version of .NET (v2, 3, and 3.5 are currently installed). Hypnobeard fucked around with this message at 20:44 on Dec 2, 2011 |
# ? Dec 2, 2011 20:38 |
|
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 21:36 on Dec 2, 2011 |
# ? Dec 2, 2011 21:21 |
|
Jethro posted: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. $psversiontable doesn't exist (empty response). $Host.Version returns: code:
|
# ? Dec 2, 2011 21:27 |
|
Tolan posted:DisplayName is blank, User, Host and Address have the appropriate entries. Oh that's fine, displayname isn't a required attribute you don't need it to send email. For whatever reason with v1 it's not displaying address when you just check the $msg and output it to the shell but it should still send the actual email just fine. V2 looks like displays address by default or displayname if it's filled in. You can create a valid MailAddress with a displayname if you really care about how it shows up (http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx) adaz fucked around with this message at 21:39 on Dec 2, 2011 |
# ? Dec 2, 2011 21:37 |
|
adaz posted:Oh that's fine, displayname isn't a required attribute you don't need it to send email. For whatever reason with v1 it's not displaying address when you just check the $msg and output it to the shell but it should still send the actual email just fine. V2 looks like displays address by default or displayname if it's filled in. You can create a valid MailAddress with a displayname if you really care about how it shows up (http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx) I'm not too worried about the displayname; it's refusing to send the email period because of the lack of recipient. I guess the answer is upgrade to v2, which means it's time to start the approval process. Meh. Thank you very much for the help.
|
# ? Dec 2, 2011 21:47 |
|
Tolan posted:I'm not too worried about the displayname; it's refusing to send the email period because of the lack of recipient. I guess the answer is upgrade to v2, which means it's time to start the approval process. Meh. Weird, it shouldn't care at all about display name. I was looking at some of my old code I know was created in the V1 days and I've never had to add a display name. So something like this won't work? It still whines about invalid recipient? There has to be something else going on here, in particular i'm wondering about that from part, it really shouldn't be displaying it like that from everything I remember, almost like it's html code:
adaz fucked around with this message at 22:12 on Dec 2, 2011 |
# ? Dec 2, 2011 22:10 |
|
adaz posted:Weird, it shouldn't care at all about display name. I was looking at some of my old code I know was created in the V1 days and I've never had to add a display name. So something like this won't work? It still whines about invalid recipient? There has to be something else going on here, in particular i'm wondering about that from part, it really shouldn't be displaying it like that from everything I remember, almost like it's html Grrr. Turns out the McAfee client on the server was set to block port 25 transactions. Fixing that resolved the problem. It's still weird that it doesn't show the recipient addresses on the MailMessage object, though. Again, thanks for the help.
|
# ? Dec 2, 2011 22:44 |
|
Ahh that makes more sense. It's odd it didn't throw a connection refused error message though. As far as displaying null on the addresses, just one of those things. The default display value must have been display name to the shell. They've definitely changed it in V2. Also you should put through that request to have v2 on your servers anyway, definitely not a bad idea.
|
# ? Dec 2, 2011 22:50 |
|
Version 2 also has the very easy to work with Send-MailMessage built in, and if you have .NET 4.0 you gain a lot of additional capabilities on top of that.
|
# ? Dec 3, 2011 01:43 |
|
I am trying to identify and move disabled accounts within in AD. I am able to ID the account that are disabled but I am having problems getting the user account to move. The error that is appearing is in the $from.PSBase.Moveto. What am I missing? Here is what I currently have code:
|
# ? Dec 7, 2011 21:34 |
|
Your MoveTo syntax is a bit off, for reference: http://msdn.microsoft.com/en-us/library/w8stwdkc.aspx Code wise it looks like so: code:
|
# ? Dec 8, 2011 00:04 |
|
adaz posted:Your MoveTo syntax is a bit off, for reference: http://msdn.microsoft.com/en-us/library/w8stwdkc.aspx Bah, So close yet so far. That you so much. Made that change this morning and it ran exactly how I expected.
|
# ? Dec 8, 2011 13:57 |
|
I've written a Powershell script that copies a table from Microsoft Word and pastes them to an excel document. I want to append it after the last used row in column A. I got this code so far: --- $Excel = New-Object -ComObject Excel.Application $Excel.Visible = $True $ExcelWordBook = $Excel.Workbooks.Open($ExcelPath) $ExcelWorkSheet = $Excel.WorkSheets.item("Sheet1") $ExcelWorkSheet.activate() This is where I get confused, I want to be able to find the last row that is used in the Excel WorkSheet. $lastRow = $ExcelWorkSheet.UsedRange.rows("A").count $nextRow = $lastRow + 1 $ExcelWorkSheet.Range("A$nextRow").Select $ExcelWorkSheet.Paste() --- I feel like I'm so close after this. I was trying to use the UsedRange property in the Office Interlop to determine the last row in the Excel WorkSheet. (http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.worksheet.usedrange(v=vs.80).aspx) Any ideas? I feel like I'm using the UsedRange function incorrectly.
|
# ? Dec 9, 2011 23:19 |
|
You were really close. There are also some other ways of doing it including using specialCells property on the range interface.code:
adaz fucked around with this message at 00:02 on Dec 10, 2011 |
# ? Dec 10, 2011 00:00 |
|
adaz posted:You were really close. There are also some other ways of doing it including using specialCells property on the range interface. edit: it might be because I have three columns and it's counting all three columns' rows. edit edit: appreciate the help a lot by the way, was stuck on this for quite some time. Donald Driver is my favorite receiver on the GB receiving corp Rabid Snake fucked around with this message at 00:20 on Dec 10, 2011 |
# ? Dec 10, 2011 00:17 |
|
Figures. Well looks like we get to use specialCells (http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.specialcells.aspx) anyway! code:
|
# ? Dec 10, 2011 00:42 |
|
Actually I just figured it out using your first solution! I changed this.code:
code:
|
# ? Dec 10, 2011 00:55 |
|
String Formatting will be the death of me. Literally, some guy who screws it up as often as me is going to be in charge of some piece of medical equipment keeping me alive and welp. At least it was something easy and it's working.
|
# ? Dec 10, 2011 00:59 |
|
adaz posted:
I have discovered that there are two types of command interfaces in the world of computing: good interfaces and user interfaces. -- Daniel J. Bernstein
|
# ? Dec 10, 2011 01:55 |
|
I'm incredibly new to Powershell, as a senior helpdesk monkey I can see how it's going to be incredibly helpful. I've got a shitload of user accounts (100+) of people that have left the company that I need to clean up/archive. My first step is to move them all into a "To be Terminated" OU. I then need to remove them from all Security/Distribution lists (except Domain Users) - this is where Powershell will come in handy as I'd prefer to run a quick script rather than go into each user and remove the groups manually! It looks like I need a script that will strip group memberships based on the object's OU. With a bit of Googling, I found this one but am having a bit of trouble deciphering it: code:
|
# ? Dec 16, 2011 00:25 |
|
psylent posted:I'm incredibly new to Powershell, as a senior helpdesk monkey I can see how it's going to be incredibly helpful. Get-AdGroup will return security groups in a given OU. So this command seems to strip all members of the groups you get, except for computer accounts. I will dissect the command for you later. What you need, is a command that gets all the users in an OU and then strip their memberships.
|
# ? Dec 16, 2011 08:07 |
|
That's definitely what I need I'll keep looking!
|
# ? Dec 19, 2011 00:38 |
|
I rarely use the powershell AD cmd-lets (I got used to the .NET classes they are based on and just use those), so there is probably an easier one liner for doing this but hey, it works. What we are doing is using Get-ADuser (http://technet.microsoft.com/en-us/library/ee617241.aspx) to retrieve a list of all users in a single OU without any filtering as from what you said that OU just will contain the users we want to delete. After we get the user we iterate through each one and bind to the DirectoryEntry object for that user (http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.aspx) which contains all the useful stuff. This allows us access to the MemberOf attribute for each user. We then use the Remove-ADGroupMember cmd-let to remove the user from each one. If you want to see what it'll do you can append -whatif to the end of that Remove-AdGroupMember command and it'll go through and list all the users/groups it will remove. code:
adaz fucked around with this message at 07:10 on Dec 19, 2011 |
# ? Dec 19, 2011 07:05 |
|
psylent posted:I'm incredibly new to Powershell, as a senior helpdesk monkey I can see how it's going to be incredibly helpful. An easier way to do this is to define deny rights on your filesystems and just plop them in that group when they leave (after disabling the account). More work beforehand, but very simple day-to-day.
|
# ? Dec 19, 2011 13:00 |
|
What is the correct way to use a variable that is a command line program in a script? I'm kind of new so I'll try to make it clearer: I am trying to run a mysql dump as part of a powershell script. I've defined the following variables: code:
code:
code:
Any tips? Also is this going to behave differently in my script than if I'm running it right from the PowerShell console?
|
# ? Dec 20, 2011 17:25 |
|
When you run the command you need to pass the ENTIRE command to the string. If you are doing - outside the string Powershell thinks those are parameters that are supposed to be passed to Invoke-Command which is why you are getting those errors as Invoke-Command doesn't accept -u or -p. So the proper way to do it is this long as heck string code:
|
# ? Dec 20, 2011 20:10 |
|
|
# ? May 21, 2024 17:28 |
|
Aha, that works beautifully. I also decided that adding the C:\Program Files\MySQL\MySQL Server 5.1\bin\ to the script environmental path would be easier to deal with as well:code:
code:
|
# ? Dec 20, 2011 22:30 |