|
Jelmylicious posted:Wicaeed posted:Wow, holy crap, thanks a lot you guys. I'll definitely look into this and get it written. Now I have something to do at work, haha. fake edit: page snyped. Hoo boy.
|
# ? Feb 2, 2012 17:16 |
|
|
# ? May 17, 2024 18:57 |
|
adaz posted:Ridiculously awesome stuff Holy poo poo, so much useful information there Wait, I thought that variables not defined outside of a function can't exist outside it? e.g. the difference between $global:variable and $variable, etc...
|
# ? Feb 2, 2012 18:32 |
|
Wicaeed posted:Holy poo poo, so much useful information there The private scope can always (well with rare exceptions that aren't worth talking about) access a higher scope's variables. So inside your private foreach loop you can access the script variables, you don't have to set them over and over again. Get-Variable -scope is a nifty way of playing around with how this works or again checking out that link. adaz fucked around with this message at 19:54 on Feb 2, 2012 |
# ? Feb 2, 2012 19:50 |
|
Cool. Another question: In the email I am getting with the results, the formatting is crapping everything out on a single line, like so: code:
code:
|
# ? Feb 2, 2012 19:55 |
|
I forgot about that particular little annoyance. You need to change one line in the Send-Email command, set isBodyHTML to falsecode:
|
# ? Feb 2, 2012 20:07 |
|
Mmmm, I don't think that's it. I have another script I use to send a separate email, however it uses two variables that only ever output a single line of text. I had to edit the body of the email to add some breaking code:
|
# ? Feb 2, 2012 21:31 |
|
Just about there. I now have my HTML completely stripped away to just the dates and values! (Thanks Adaz & Co.) What is left is a simple string that has a date followed by five or so values, then a new date and more values, etc. Ex: code:
I think I'm just misunderstanding how people are using the square brackets after variables. $splitVal[10] for instance, what is this doing? Or would I use the System.String.Substring() method somehow? (Sorry in advance for being so bad at string parsing. Haven't ever really had to do it in scripting before now!) edit: Script complete! Thanks again everyone! Siets fucked around with this message at 02:40 on Feb 7, 2012 |
# ? Feb 3, 2012 23:33 |
|
Wicaeed, Well I know it works and is inserting a line terminator I just verified it. It's probably some quirk with whatever email client you're using that it is ignoring that character for some reason. If you check the $email.body before sending it the text should show up there with line breaks. Siets, $splitVal[10] is the 11th position in the array as array's are 0 based. So let's do this example. WE have the following values: 10,20,30,40,50,60 I want them into an array, so I'll call split(",") to put the individual elements into an array. The square brackets [number] are just how you access the different elements inside the array. Here is an example: adaz fucked around with this message at 19:08 on Feb 5, 2012 |
# ? Feb 5, 2012 19:01 |
|
I'm trying to improve the way we're doing some things with Powershell on a project I'm working on, particularly working with credentials. I've been doing some experimentation with the PSCredential object type, more or less using the method described here. Everything seems to work pretty well. The script I want to use this in gets executed from a variety of machines, but always as the same domain user. I copied the encrypted password file I created to a different server, but when I executed code:
|
# ? Feb 14, 2012 22:23 |
|
Correct, the key it generates is machine specific. If you need to run the script on multiple machines this is a decent enough workaround (to be honest, I've forgotten how I have worked around this in the past): http://powertoe.wordpress.com/2011/06/05/storing-passwords-to-disk-in-powershell-with-machine-based-encryption/
|
# ? Feb 14, 2012 23:07 |
|
adaz posted:Correct, the key it generates is machine specific. If you need to run the script on multiple machines this is a decent enough workaround (to be honest, I've forgotten how I have worked around this in the past): http://powertoe.wordpress.com/2011/06/05/storing-passwords-to-disk-in-powershell-with-machine-based-encryption/ Thanks for the link, that's an interesting approach. I only have a few different servers to work with, so having to create a separate password file is more annoying than anything else. I think I'll just do it that way, I was really just wanting done confirmation before I wasted any more time trying to figure out why it wasn't working.
|
# ? Feb 14, 2012 23:40 |
|
To be honest the last time I ran into this I think I just used schtask command line tool to remotely schedule the script and save the credentials that way.
|
# ? Feb 15, 2012 06:59 |
|
Is this a place to ask for help with stitching code segments together? I just need to do something small, but I'm new at this. How would I connect a dumb foreach loop that just makes folders code:
code:
|
# ? Feb 23, 2012 04:26 |
|
code:
|
# ? Feb 23, 2012 06:08 |
|
Just in case you are really new, what Adaz did was put your second chunk of code inside the code block of the first chunk of code you posted. A code block is just essentially "do all of the stuff inside of the { and } brackets." That code block is then run every time a new $folder is found inside of $folders- so if you have 10 folders, it will run the code block 10 times.
|
# ? Feb 23, 2012 06:31 |
|
Siets posted:Just in case you are really new, what Adaz did was put your second chunk of code inside the code block of the first chunk of code you posted. A code block is just essentially "do all of the stuff inside of the { and } brackets." That code block is then run every time a new $folder is found inside of $folders- so if you have 10 folders, it will run the code block 10 times. Yeah I understand this, and I appreciate it, because what I was doing wrong beforewas trying to breaking the md command and the get-acl segment into two blocks of curley braces, which obviously doesn't work. This makes sense and is simpler than what I was trying to do. Thanks guys Dreadite fucked around with this message at 16:03 on Feb 23, 2012 |
# ? Feb 23, 2012 15:58 |
|
Another thing I am having trouble doing is removing all of the access rules on the directories I create. I would like to be able to strip all the access rules and then specifically add the users permissions that I would like afterwards- I tried this but it throws errors like code:
code:
|
# ? Feb 24, 2012 18:58 |
|
RemoveAccessRuleAll just removes a single ACE, see this pretty good article for more details: http://technet.microsoft.com/en-us/library/ff730951.aspx What I've usually found helpful when working with ACLs is to do something like this code:
There are also some scripting guys articles on Get-ACL(http://blogs.technet.com/b/heyscriptingguy/archive/2009/09/14/hey-scripting-guy-september-14-2009.aspx) and Set-ACL (http://blogs.technet.com/b/heyscriptingguy/archive/2009/09/16/hey-scripting-guy-september-16-2009.aspx), which actually explains what I'm doing above in more detail.
|
# ? Feb 24, 2012 19:23 |
|
Also, if you remove all access rights first, you won't have any rights yourself. Which means you don't have rights to set accessrights.
|
# ? Feb 24, 2012 19:54 |
|
Deeper into the rabbit hole! Am I using the wrong class to set these permissions, since they show up only as "special" permissions? I'm using code:
http://imgur.com/a/VElWl
|
# ? Feb 24, 2012 22:13 |
|
For the Exchange Management Shell people out there on Exchange 2010, I worked up a custom function to parse all the Role Groups for individual commands per group membership. It's handy if you're trying to determine exactly what commands people get access to when they're a member of certain groups. You can specify a role group if you only want to see the commands that group gets. If you don't it will list all the commands available to all the groups, and of course you can sort/parse on the new properties.code:
|
# ? Feb 24, 2012 22:19 |
|
Dreadite posted:Deeper into the rabbit hole! Whoops, missed this -- did you ever figure it out? At a casual glance it looks like everything is right but what type of right are you setting? deny? modify? allow? or something more esoteric?
|
# ? Feb 28, 2012 21:26 |
|
What's the easiest way to break out of a scriptblock in Powershell? I have a script that will generate quite a few errors if a variable is not set, which can happen if it is a certain date. Can I add a simple If/Else statement to say something like: code:
I've got two variables, one is a folder path, the other is a filename variable. I would like to combine the two to test the existence of the destination file. Code snippet follows: code:
code:
Wicaeed fucked around with this message at 17:26 on Feb 29, 2012 |
# ? Feb 29, 2012 17:03 |
|
You can append strings with a simple + so: $Destinationfolder + $item.name should work.
|
# ? Feb 29, 2012 17:57 |
|
You can also use subexpression syntaxcode:
|
# ? Feb 29, 2012 19:06 |
|
Does anyone know of any good Powershell scripts to parse IIS logs? Basically we get requests every once in a while to look for specific logon information in IIS based on a user's logon alias, but our IIS logs span several severs and I was wondering if there's a way to parse those logs from on location through a Powershell command?
|
# ? Mar 1, 2012 04:49 |
|
Wicaeed posted:What's the easiest way to break out of a scriptblock in Powershell? I have a script that will generate quite a few errors if a variable is not set, which can happen if it is a certain date. It's purely a matter of style, but I find it cleaner to do something like code:
|
# ? Mar 1, 2012 10:28 |
|
Is there a way to delete a row out of a CSV and then be able to export it out? I know that $null will kill the row if you do something like $var[$i]=$null, but then Export-Csv throws an error about null values in a row when trying to export it out.
|
# ? Mar 1, 2012 21:08 |
|
Phone posted:Is there a way to delete a row out of a CSV and then be able to export it out? yes! There probably is a non-ghetto way but this is what i've done. code:
|
# ? Mar 2, 2012 00:49 |
|
So earlier I was asking for a script to parse IIS logs, and while I found a few on the internet, most were overly complex and didn't really meet my needs, so I made it myself.code:
|
# ? Mar 5, 2012 15:57 |
|
I made another log parsing script since I got my IIS one working so well. This one is designed to parse SMTP protocol logs on your Hub transport server. There's a bit more logic involved here, and you need to know if the SMTP event is a Receive or a Send event, as that affects where the script will search. Once again, you may need to modify the $Files parameter if you don't store your logs in the same location.code:
|
# ? Mar 5, 2012 16:02 |
|
So recently I've noticed some strange behavior in Powershell ISE and scheduled tasks. I can load up/edit a script in ISE, and when it comes time to run it, I hit F5. This loads the script but nothing really happens. I have to manually type the function that is calling each scriptblock in to the powershell CLI to get it to run properly. This is affecting scheduled tasks as well. I did install Powershell 3.0 beta on my workstation and have been using it to remote powershell tab to my servers, but I still have 2.0 installed on my servers, however it happens on the servers as well if I am using Powershell ISE in an RDP session. Any ideas, as I'm completely befuddled by this behavior.
|
# ? Mar 5, 2012 17:02 |
|
So does Powershell just lack shortcuts to jump around text, or do I just not know them, or what? Like in bash you have a ton of shortcuts like ^a for the beginning of the line, alt-f to go forward one word, ^w to delete a word, etc, but apparently you just have to hold down the arrow button forever to do this kind of stuff with Powershell which is annoying.
|
# ? Mar 6, 2012 01:30 |
|
RICHUNCLEPENNYBAGS posted:So does Powershell just lack shortcuts to jump around text, or do I just not know them, or what? Like in bash you have a ton of shortcuts like ^a for the beginning of the line, alt-f to go forward one word, ^w to delete a word, etc, but apparently you just have to hold down the arrow button forever to do this kind of stuff with Powershell which is annoying. Try home and end. Ctrl -> and ctrl <- will go one word at a time. That's not just powershell though, that's standard Windows behavior.
|
# ? Mar 6, 2012 03:24 |
|
stubblyhead posted:Try home and end. Ctrl -> and ctrl <- will go one word at a time. That's not just powershell though, that's standard Windows behavior. I guess Unix has warped my thought process because I knew those were standard Windows behaviors and did not think to try them in Powershell. Point taken.
|
# ? Mar 6, 2012 03:27 |
|
Wicaeed posted:So recently I've noticed some strange behavior in Powershell ISE and scheduled tasks. My guess is a DLL that got hosed up, I mean does it happen on other workstations that didn't have 3.0 beta installed? And Korlac thanks for those IIS log parsers, I started to write something then got bogged down at work. adaz fucked around with this message at 05:35 on Mar 6, 2012 |
# ? Mar 6, 2012 05:31 |
|
So I've been tasked with automating some auditing because the previous method was some lengthy and involved process that included Access databases. I'm pretty much done with all of this due to Powershell. God drat I loving love the Import-Csv cmdlet. I'm horrible at programming, but I am apparently a programming god to my coworkers because I know about for loops and know about objects/arrays.
|
# ? Mar 6, 2012 17:46 |
|
Probably my favorite part of Powershell 2.0 is the remoting using PSSession. I built a utility at work for dealing with print servers. It creates multiple records, not only in the print servers, but also in DHCP and NPS. Without remoting, it would take much longer to pull the data to the local machine and then send the replies back up. And, Phone, Import-CSV and Get-Content were brought to us by $deity itself.
|
# ? Mar 7, 2012 05:22 |
|
Seriously, I've quite thoroughly enjoyed my time with Powershell thus far, I just wish I had more excuses to use it at work
|
# ? Mar 7, 2012 15:50 |
|
|
# ? May 17, 2024 18:57 |
|
Wicaeed posted:Seriously, I've quite thoroughly enjoyed my time with Powershell thus far, I just wish I had more excuses to use it at work Is there anything you do semi-regularly that could be automated? Go on! Script yourself out of a job!
|
# ? Mar 7, 2012 16:23 |