|
I love Powershell and I'm here to tell you why: We have a team of 1000 developers who regularly release a new version of their vertical. It's huge. We are a SOX shop, so one of the controls is that the developers cannot branch their own code. We do the branching. They send us an Excel spreadsheet with all the versions they need branched. I wrote a Powershell script to extract the versions and convert them into SVN branch commands. My script also updates the Excel spreadsheet with the new branch numbers. The best part is that this is all automated. We create a change request and roll out the branches into production without any problems. EDIT: To accomplish the same thing in C# is loving painful and not worth the effort. tango alpha delta fucked around with this message at 04:27 on Aug 3, 2014 |
# ? Aug 3, 2014 04:23 |
|
|
# ? May 16, 2024 00:02 |
|
tango alpha delta posted:I love Powershell and I'm here to tell you why: Sounds like you came up with a good solution to an insane problem.
|
# ? Aug 3, 2014 15:31 |
|
I'm trying to create a PowerShell script that will send a Lync message to all users in column "A" the text in columns "B" and "C". I started out using this guide- http://blogs.technet.com/b/csps/archive/2011/05/05/sendim.aspx I believe I have most of the framework down, but my main issue is figuring out how to actually IM the user. When I run my script I get "Cannot find an overload for "AddParticipant" and the argument count: "1"." Here's what I have so far (the million try statements were to help troubleshoot). e; updated broken code. TheEffect fucked around with this message at 21:27 on Aug 6, 2014 |
# ? Aug 4, 2014 17:36 |
|
tango alpha delta posted:I love Powershell and I'm here to tell you why: I hope you are claiming this is taking you hours of work, and then playing Zuma's Revenge all day
|
# ? Aug 4, 2014 18:03 |
|
Okay, can someone help me with this one, because I'm just not getting it. Basically, I just want to grab the current AD group membership of one user and apply the same group membership to another user, so, grab the groups that user jdoe1 is a member of and add user jdoe2 to those same groups. code:
Running it through code:
code:
code:
code:
I'm pretty new to PowerShell and I'm working my way through Learn PS in a Month of Lunches book, so sorry if this is a dumb question with a really obvious answer. Edit: Okay, I got it working by using the ForEach-Item cmdlet and running $jdoe1_groups through Get-ADGroup first: code:
1. $jdoe1_groups contains an array and thus requires ForEach-Item for iterative processing 2. Add-ADGroupMember -Identity parameter requiring Get-ADGroup to produce the appropriate object type Hoping someone can help further clarify what's going on here if I'm not on the right track. along the way fucked around with this message at 16:18 on Aug 5, 2014 |
# ? Aug 5, 2014 14:37 |
|
I want to change all contacts in all Outlook clients in my company. I want to get rid of middle names and put them all Firstname=Firstname, Lastname=Middle+Lastname. Can I do this with Powershell or should I go vbscript? Thanks in advance.
|
# ? Aug 5, 2014 19:10 |
|
TheEffect posted:I'm trying to create a PowerShell script that will send a Lync message to all users in column "A" the text in columns "B" and "C". Updated my code and re-framed the question with some clarification. Not sure why this isn't working; every guide I look at online seems to match what I have for the most part. Can't for the life of me figure out why I'm getting that error. This question appears similar but it has no real solution: http://stackoverflow.com/questions/19254906/exception-calling-beginsendmessage-with-3-arguments-value-does-not-fall I'm not even sure how useful this application will be (why wouldn't you just create a group and then ask via group chat whatever information you needed?) but goddamn am I determined to get it working. Edit- Got a bit further with this. Apparently "AddParticipant" does not want a string but a URI. So I changed my code to convert via $contact = $LyncClient.ContactManager.GetContactByUri("yourperson@domain.com") $Convo.AddParticipant($contact) however now I'm getting "Exception calling "GetContactByUri" with "1" argument(s): "Value does not fall within the expected range." The exception is- NotSpecified: ( [], MethodInvocationException TheEffect fucked around with this message at 17:21 on Aug 7, 2014 |
# ? Aug 5, 2014 21:30 |
|
capitalpunctuation posted:Can't see anything in event viewer to clue me in to what's going on. All the googling says remotely executing msi files, or batch files, is trivially easy, but I've followed a hundred tutorials to no avail. What am I missing? Just a guess but you're probably running into the problem outlined in this article: http://technet.microsoft.com/en-us/magazine/jj853299.aspx quote:I'm having a hard time wrapping my head around why this works, but I think it's because: code:
This might not be the case with ForEach-Item (I almost always use ForEach-Object), but generally I've found that you can force iteration by doing "$Variable | ForEach-Whatever {do thing}", or if the commands "play nice", you can do a "Do-Thing -Identity(Get-Thing)", and it will iterate through that way. You should enable debug mode (select a line in the ISE, make sure the script is saved to disk, hit F9) and step through the script a few times to make sure it isn't double-iterating on you. I've also found that generally $variable = get-object | select SomeProperty doesn't behave the way you think it does. $Variable probably still refers to the object returned by Get-Object, not the properties returned by Select-Object. So, you most likely specifically Select-Objected into GM and got ADGroup, when in actuality the $variable was still referring to the parent object that contains a child object that is an AD group. That probably explains your Object -> ADGroup conversion error. Try piping into get-member without doing the Select-Object and see if it still returns an ADGroup.
|
# ? Aug 6, 2014 03:56 |
|
Reiz posted:You basically figured it out. Sort of. $jdoe1_groups probably doesn't "technically" contain an array, but it does need to be iterated through. Your script is a little messy looking to me (not that it matters, though) and could probably be cleaned up with some dot sourcing. I can't really tell without testing, and I don't have an AD environment at home, but to me it looks like: Yeah, I noticed the double iteration and changed the (Get-ADGroup $jdoe_groups) portion to read from the variable being piped in with (Get-ADGroup $_). Also, I goofed on filling in ForEach-Item when I meant ForEach-Object. I was actually using the alias foreach in the PS prompt and filled it in mistakenly after the fact. Thanks for the clarifications. Like I said, I'm just starting out with Powershell with my only scripting experience being with batch files up until recently, so stuff like dot sourcing is a little beyond me for now.
|
# ? Aug 6, 2014 13:04 |
|
How do I code for Sharepoint list queries via CSOM when I'm told that I can only retrieve X number of rows per query? I've never worked with that kind of constraint before - do I perform multiple queries until the database says "you've reached the end" and push everything into some kind of holding array? For example, take the following query that limits me to 200 rows per query: code:
|
# ? Aug 6, 2014 23:40 |
|
TheEffect posted:Got a bit further with this. Apparently "AddParticipant" does not want a string but a URI. So I changed my code to convert via With help from someone on another forum I was able to find the solution to my problem. Posting here in case anyone else was interested- I stepped through and outputted $UserName each time the code touched it and I figured out that $UserName.Trim() only OUTPUTS the trimmed string and does not store it (of course!), so I changed it to $UserName = $UserName.Trim() and everything is working beautifully. What was happening was I was taking "lastname, firstname" from a cell in Excel and formatting it so that it would be "firstname.lastname@domain.com" but due to there being a space after the comma I had to use .trim() to get rid of it, but I never considered how .trim() worked and so the variable was retaining the space character.
|
# ? Aug 7, 2014 19:45 |
Hey, I have a question. Pardon me if it's basic. I've done some very minor powershell scripting but I'm not an expert by any means. I work with backup software, and I serve as a top escalation point for our support staff. If they get stuck they gather some logs from the customers' machines. I regularly have to search event logs for specific, backup-related events. Searching event logs in the Event Viewer is slow as hell. Seriously it's awful. Can powershell scan saved event logs and pull out individual events based on various criteria? For example, take this basic VSS event: Log Name: Application Source: VSS Date: 8/14/2014 10:03:30 AM Event ID: 8224 Task Category: None Level: Information Keywords: Classic User: N/A Computer: MX-DC.robbinstbm.com Description: The VSS service is shutting down due to idle timeout. Event Xml: <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="VSS" /> <EventID Qualifiers="0">8224</EventID> <Level>4</Level> <Task>0</Task> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2014-08-14T15:03:30.000000000Z" /> <EventRecordID>801229</EventRecordID> <Channel>Application</Channel> <Computer>MX-DC.robbinstbm.com</Computer> <Security /> </System> <EventData> <Data> </Data> </EventData> </Event> Could I have powershell scan the event log, find anything from Source: VSS, and print the results to a text file? Could I do the same based upon text in the Description section? Could I define a date range for this? Say, last 7 days?
|
|
# ? Aug 15, 2014 00:09 |
|
Two ways to do that as I know:code:
code:
Does that help at all?
|
# ? Aug 15, 2014 00:31 |
CLAM DOWN posted:Two ways to do that as I know: That's about 10x easier than I expected. Is it possible to grab any event that includes a word in the description?
|
|
# ? Aug 15, 2014 00:33 |
|
ConfusedUs posted:That's about 10x easier than I expected. Is it possible to grab any event that includes a word in the description? code:
The above gives me an output file that looks something like: code:
vvv No problem! CLAM DOWN fucked around with this message at 01:00 on Aug 15, 2014 |
# ? Aug 15, 2014 00:46 |
That rocks. I can adapt that easily for my needs. Thank you!
|
|
# ? Aug 15, 2014 00:50 |
|
I need to accomplish a task and I'm thinking powershell might be my only hope. I need to schedule a task on 10 VMs, but I need to have it specific to a second. For example, at 08:40:15 I want to launch notepad.exe on VM1. Then at 08:40:20 I want to launch notepad.exe on VM2. Ideally, I'd like to sit at my workstation and use powershell to schedule the tasks. What I have been doing is using the taskscheduler GUI but its clunky and takes forever to work my way through 10 VMs. I've tried learning more about SCHTASKS in command prompt but you can only schedule by the minute, you can't schedule by the second. All computers will be running Windows 7. Can powershell handle something this or do I need to get more creative? *I was thing maybe I could use the TaskScheduler GUI to create my task which will open notepad at 08:40:15. Then open powershell or command prompt and find that task, then copy it out to the other machines. Not sure if that would work. Hughmoris fucked around with this message at 03:49 on Aug 16, 2014 |
# ? Aug 16, 2014 03:43 |
|
I'm away from my desk but I would start with get-help new-ScheduledTask -full I'll test it out in a bit and see if I can get something to work. How are you going to be getting the times? Can you make a csv with the VM and time?
|
# ? Aug 16, 2014 03:53 |
|
Dr. Arbitrary posted:I'm away from my desk but I would start with get-help new-ScheduledTask -full I think those were added in windows 8.
|
# ? Aug 16, 2014 03:59 |
|
Dr. Arbitrary posted:I'm away from my desk but I would start with get-help new-ScheduledTask -full I opened powershell, ran get-help new-ScheduledTask -full and receiver the error code:
I'm not positive what you mean about getting the times. It would run something like this: code:
|
# ? Aug 16, 2014 04:01 |
|
Ithaqua posted:I think those were added in windows 8. poo poo. I hate when that happens. Maybe it can be done with .NET I still want to make it work. This is a fun challenge.
|
# ? Aug 16, 2014 04:10 |
|
Dr. Arbitrary posted:poo poo. I hate when that happens. I'll have to do it without installing any further software. And you're right, while its irritating its also a fun brain puzzler. After googling, I'm thinking maybe create the task on all the machines using the command prompt for 08:00. Then somehow export the task which appears to be an XML, edit the XML to have the time be 08:00:05, then import it. Not sure if I'm going crazy after dealing with this all day.
|
# ? Aug 16, 2014 04:39 |
|
Hughmoris posted:I'll have to do it without installing any further software. .Net is a prerequisite for powershell so that won't be a problem. I think you might start with this: http://letitknow.wordpress.com/2011/05/20/create-scheduled-task-by-using-powershell/ The key element is $service = NewObject -ComObject("Schedule.Service") You can then use $Service | Get-Member To find new properties. This is pretty difficult territory for me so I'd just carefully look at the examples and try to work it out.
|
# ? Aug 16, 2014 04:46 |
|
Dr. Arbitrary posted:.Net is a prerequisite for powershell so that won't be a problem. At first glance it looks like the site you listed could be a more elegant solution but I'm not too familiar with a lot of the code being used. So, I went about solving it like a caveman. 1. At my workstation, I create a local task in command-prompt: code:
code:
4. I then export that newly adjusted task file to each VM: code:
I tested it on 2 machines and it appears to work. Ugly but effective. I'm definitely ears for other solutions though. Hughmoris fucked around with this message at 05:33 on Aug 16, 2014 |
# ? Aug 16, 2014 05:29 |
|
Hughmoris posted:At first glance it looks like the site you listed could be a more elegant solution but I'm not too familiar with a lot of the code being used. So, I went about solving it like a caveman. I've taken a similar approach (the COM stuff sucks). But why not use PowerShell to set the time in the XML instead of manually editing it? This should work: code:
New Yorp New Yorp fucked around with this message at 17:10 on Aug 16, 2014 |
# ? Aug 16, 2014 17:06 |
I've created a number of scripts to generate randomized data and files to test backups. I'm happy with all of them except my MSSQL script. For that one, I have a .sql file that I call with powershell. It works well enough, but is there a way to talk to MSSQL and insert data into a table from powershell itself?
|
|
# ? Aug 16, 2014 19:54 |
|
ConfusedUs posted:I've created a number of scripts to generate randomized data and files to test backups. You can use the extensive .NET framework libraries in the System.Data namespace.
|
# ? Aug 16, 2014 21:32 |
|
Ithaqua posted:I've taken a similar approach (the COM stuff sucks). But why not use PowerShell to set the time in the XML instead of manually editing it? Thanks for taking the time to do this. I don't know powershell but I think I can piece together whats happening. I'm going to try it out later tonight and I'll let you know how it works out.
|
# ? Aug 16, 2014 23:17 |
|
Hughmoris posted:Thanks for taking the time to do this. I don't know powershell but I think I can piece together whats happening. I'm going to try it out later tonight and I'll let you know how it works out. Just to follow up, I attempted to create this PS script. I was unable to run the script due to being restricted by the system. After a little reading, I tried to allow it with: set-executionpolicy remotesigned. Received the error that I couldn't alter the regkey. So, there goes that. Not sure if our IT department will unlocked that for me. Either way, the higher ups want to start all this crap at 0830 Monday morning so it won't do me much good. I do have AutoIt installed on this workstation, so I guess I'll try and figure out how to write your script in AutoIt. Unless it would be easier to write some sort of command-prompt script.
|
# ? Aug 17, 2014 03:45 |
|
Hughmoris posted:Just to follow up, I attempted to create this PS script. I was unable to run the script due to being restricted by the system. After a little reading, I tried to allow it with: set-executionpolicy remotesigned. Received the error that I couldn't alter the regkey. So, there goes that. Not sure if our IT department will unlocked that for me. Either way, the higher ups want to start all this crap at 0830 Monday morning so it won't do me much good. Copy it all into notepad, then paste it into powershell and see if it works.
|
# ? Aug 17, 2014 03:50 |
|
This should work but it doesn't, and the maddening thing is I've done this before. I'm running this dedupe finder: http://poshcode.org/4008 I want to pipe the output to a text file; I've done this in the past, and in fact after I make this post I'm going to click the 'find other posts by this user' button to see if I figured it out here. When I try this: code:
When I try this: code:
When I try this: code:
code:
|
# ? Aug 21, 2014 21:00 |
|
Scaramouche posted:I don't get anything, the file doesn't even get created. The output of the script above is using Write-Host, which >> should be hijacking based on everything I read. e.g., the summary output: Those Write-Hosts need to be Write-Outputs to stream them to an output like that. Write-Host specifically writes to the console, which is why your redirects aren't working. You can also use Start-Transcript and Stop-Transcript, which will work with Write-Hosts since it'll grab anything written to the console.
|
# ? Aug 21, 2014 21:34 |
|
Change write-host to write-output.
|
# ? Aug 21, 2014 21:36 |
|
Reminder that Start/Stop-Transcript does not work in the ISE.
|
# ? Aug 21, 2014 21:40 |
|
Hmm, thanks guys. The weird thing is, the date-time stamp on the script is from when I did this last, and I was going over 500,000 files, so I must have figured out a way to get that data without changing the actual script. After doing a bit of reading it makes sense that this won't work since write-host is meant for screen only. I guess my memory was playing tricks on me, which is probably the worst thing to rely on. You probably spend more time trying to do something "because I remembered it was easy last time" than you do trying it the right way.
|
# ? Aug 21, 2014 21:49 |
|
I have never used powershell before and I would like to unzip a file. What is a good way to do that? I found this function: code:
code:
Is my powershell not the right version or something? How would I even know? edit: also I ran a command with a lot of output and it was taking FOREVER to print to the screen. Is this a general problem or is it because I'm accessing the machine over rdp from linux? Dren fucked around with this message at 23:10 on Sep 8, 2014 |
# ? Sep 8, 2014 22:57 |
|
Do you have the option of using the 7zip command line utility? I think it works way better and is way easier, I also recall some restrictions with using the built-in method like you are, like it doesn't work on zip files with subfolders, etc.
|
# ? Sep 8, 2014 23:12 |
|
CLAM DOWN posted:Do you have the option of using the 7zip command line utility? I think it works way better and is way easier, I also recall some restrictions with using the built-in method like you are, like it doesn't work on zip files with subfolders, etc. Yeah I could do that. I was going to try to avoid it to minimize dependencies but if the thing to do is 7zip cmdline utility I'll do that. I looked at the OP a bit and now I see that $shell in that script is holding a com object. I saw that I can do code:
edit: Is there a convention for where to put stuff like 7zip? I could toss it in C:\7zip and throw that in the path I guess. Dren fucked around with this message at 23:25 on Sep 8, 2014 |
# ? Sep 8, 2014 23:19 |
|
Any suggestions on a book for someone who has PS experience but wants to round out their knowledge? I've been writing scripts for about 9~ months now, with past Python experience, but I know I'm missing some stuff. I was looking at Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell, but I'm open to other suggestions. Work is reimbursing me so cost isn't an issue as long as it isn't ridiculous.
|
# ? Sep 9, 2014 00:03 |
|
|
# ? May 16, 2024 00:02 |
|
Spazz posted:Any suggestions on a book for someone who has PS experience but wants to round out their knowledge? I've been writing scripts for about 9~ months now, with past Python experience, but I know I'm missing some stuff. I think there's a toolmaking in a month of lunches book that might be up your alley.
|
# ? Sep 9, 2014 01:18 |