|
Hadlock posted:5 is supposed to support linux-style package management system(s), like apt-get and yum, replacing the need for stuff like ninite. Do you know if Chocolately is changing to this or going away? I use it now and it works great for some of our quick lite touch deployments, we just install Chocolately and then give it the list of apps to install.
|
# ? Jul 23, 2015 13:39 |
|
|
# ? Apr 25, 2024 21:05 |
|
I'm familiarizing myself more and more with powershell. But uhm how do i create a log? I'm sending the list of inactive users accounts (who are going to be deleted) to the company mail But that's the lazy way. I wanna be able to say. This is what happened. This is what is going to happen in a log file and send that as an attachment. I want to put in. If $users are deleted. write-output or something like that. I wanna be able to list the users that are deleted and their homedrive. I wanna know how i can do that. so i can know how to log further powershell scripts i'm making Can you guys help? code:
|
# ? Jul 23, 2015 13:51 |
|
There are two things that come to mind. The first is that you should be able to use the Start-Transcript cmdlet to keep a log of any thing done by powershell and have it write to a text file. More info here: https://technet.microsoft.com/en-us/magazine/ff687007.aspx I use it as part of my Powershell profile so that it loads whenever I start it up, it definitely helps to be able to go back and look and see what I was trying to do. code:
|
# ? Jul 23, 2015 14:48 |
|
BaseballPCHiker posted:There are two things that come to mind. The first is that you should be able to use the Start-Transcript cmdlet to keep a log of any thing done by powershell and have it write to a text file. More info here: Your timestamp is faulty. If you do alpha sorting, 7 comes up as greater than 10. Replace that whole mess with this: get-date -Format MM-dd-yyyy-hh-mm-ss I think that's also susceptible to repeating timestamps, potentially. You get the current date/time on every call to get-date, so if you run it on the cusp of a minute/hour/day/month/etc change, you could end up with this: Get-Date = 12:59:00 -> get minute = 59 Get-Date = 12:59:01 -> get second = 01 Full timestamp: 12:59.01 then, later: Get-Date = 12:59:59 -> get minute = 59 Get-Date = 13:00:01 -> get second = 01 Full timestamp: 12.59.01 New Yorp New Yorp fucked around with this message at 15:12 on Jul 23, 2015 |
# ? Jul 23, 2015 15:07 |
|
Ithaqua posted:
Wow much better, thank you! I did that and changed this part to: code:
|
# ? Jul 23, 2015 16:19 |
|
Dr. Arbitrary posted:I'm working on a project to verify firewall settings. I know this is from last page, but I have this function I use as part of a larger project. It's not really written in my style so either this was a long time ago or I stole half the code from somewhere else: code:
|
# ? Jul 23, 2015 17:45 |
|
Sefal posted:I'm familiarizing myself more and more with powershell. If you want a .txt version rather than the CSV, then you can just put $user | Out-File .\log.txt -Append in the foreach block. Or if you want a timestamp in there: "$(Get-Date): Deleted user $user" | Out-File .\log.txt
|
# ? Jul 23, 2015 22:40 |
|
Thank you. the transcript command was what I needed
|
# ? Jul 24, 2015 10:04 |
|
Sefal posted:Thank you. the transcript command was what I needed Note that transcripts don't work when you're running the script in the ISE. Or at least they didn't last time I tried to use it. It made it essentially worthless.
|
# ? Jul 24, 2015 14:34 |
|
Ithaqua posted:Note that transcripts don't work when you're running the script in the ISE. Or at least they didn't last time I tried to use it. It made it essentially worthless. Oh yeah i got that error the 1st time. "This host does not support transcription" but after some quick goolging, found it didnt work in the ISE. It supposedly does work in the ISE of powershell v5
|
# ? Jul 24, 2015 14:46 |
|
Sefal posted:Oh yeah i got that error the 1st time. "This host does not support transcription" but after some quick goolging, found it didnt work in the ISE. It supposedly does work in the ISE of powershell v5 Transcript also won't capture any output from shell commands or external .exe files. Not sure if that changed in 5 or not.
|
# ? Jul 24, 2015 19:09 |
|
Anyone have recommendations for intermediate level Powershell books. I've already read month of lunches (although I might order toolmaking in a month of lunches).
|
# ? Jul 24, 2015 20:04 |
|
BaseballPCHiker posted:Do you know if Chocolately is changing to this or going away? I use it now and it works great for some of our quick lite touch deployments, we just install Chocolately and then give it the list of apps to install. I only played around with it when it was first announced last fall, and never actually got it to work. From what I understand, the system ps5 is using is engineered so that it will work with multiple package suppliers and is modeled after chocolatey and you can set up chocolatey as your primary package supplier... Or whatever. I haven't played around with it yet.
|
# ? Jul 24, 2015 20:45 |
|
Ithaqua posted:Note that transcripts don't work when you're running the script in the ISE. Or at least they didn't last time I tried to use it. It made it essentially worthless. EDIT: Also, while trying to find the KB value of the update rollup, I found this page, which is a pretty neat list of all the stuff they've added in v5. Venusy fucked around with this message at 21:37 on Jul 24, 2015 |
# ? Jul 24, 2015 21:20 |
|
I have an idea for a script but I'm not sure if it's crazy or already been done. The basic idea is that it validates a list of requirements. Easy enough to start, a bunch of if/else statements contingent on wmi queries etc. But what if I made a script that let you specify a series of checks and then exported that as an XML object, and then turned the validator script into a function that accepted the XML file as a parameter. You could have a standardized thing for prerequisites that would work the same way every time. Or is this reinventing the wheel or crazy or dumb?
|
# ? Jul 24, 2015 22:54 |
|
I think that's basically DSC, or Chef's windows plugin, or Ansible running over wmic. If I'm understanding you correctly, anyway.
|
# ? Jul 25, 2015 02:34 |
|
There's a product called Guardrail that I'm getting ready to roll out at my company next month that basically does that. It's cross-platform but the windows side of things runs powershell scripts and compares the output to what's expected and let you know what's gone awry. It's compatible with Chef, Puppet etc but is better designed to get your infrastructure under control so that you can some day propose going full chef/puppet and actually expect it to be completed reasonably on time. You should code it anyways, the company that makes Guardrail just got a second, ~$10 million round of venture capital funding. Apparently there's a large market for that kind of thing.
|
# ? Jul 25, 2015 07:19 |
|
Hadlock posted:You should code it anyways I think I will. Worst case, it sucks and maybe I learn something.
|
# ? Jul 25, 2015 08:20 |
|
I know that Win32_Product is dangerous. Are there any others to look out for or they all mostly safe?
|
# ? Jul 27, 2015 21:07 |
|
Dr. Arbitrary posted:I know that Win32_Product is dangerous. Are there any others to look out for or they all mostly safe?
|
# ? Jul 27, 2015 22:10 |
|
Dr. Arbitrary posted:I have an idea for a script but I'm not sure if it's crazy or already been done. Doesn't SCCM do exactly this? I guess I'd query WMI.. the comparing it to what a value should be shouldn't be too hard. Your own custom script looking at exactly what you need and producing a sexy report is going to be superior to wrestling out of a tool like SCCM anyway. As long as you put the time into your reporting and don't point to jumbled CSVs like lots of lazy scripters do (I had to understand it, so why can't you?) It's not job security in the sense you're producing custom stuff no-one else can support, it's job security in that's is a cool accomplishment to talk about. You can answer the now ubiquitous 'how is your Powershell?' interview question with examples like this
|
# ? Jul 28, 2015 02:05 |
|
Oh my god I totally just learned you can do this code:
|
# ? Jul 30, 2015 23:41 |
|
CLAM DOWN posted:Oh my god I totally just learned you can do this You can also do this for modules No more complicated functions to check if the ActiveDirectory module is active, just code:
|
# ? Jul 31, 2015 07:05 |
|
Jeoh posted:You can also do this for modules No more complicated functions to check if the ActiveDirectory module is active, just omg
|
# ? Jul 31, 2015 07:21 |
|
I'm working on a script to automate password resets/account lockouts. The way it works right now is: -Cell phone numbers stored in AD for each user -User sends text to email address -Script looks for emails in the service box At first I was just taking all information before the @ in the email address as the phone number but then I found out there could be some variance in that piece because some providers may or may not include + and 1 in the phone number. Now I'm trying to manipulate the string such that I take the first 10 digits before the @ as phone number. That way any leading information that may or may not be included won't be part of the look up. It seems I've messed something up in the string manipulation though because my tests are setting the variable as xxxxxxxxxx@x . So it's getting the phone number and disregarding the extraneous information but for some reason now it's pulling the @ and the first character after the @ as part of the string. What am I missing? Here's the snippet for the string manipulation: $Phone = $item.From.address.substring(($Phone.IndexOf("@")-10), $Phone.IndexOf("@"))
|
# ? Aug 3, 2015 14:43 |
|
Given the input of "2223334444@provider.net", if you do a substring() for @-10,@, yeah you will pull just the phone number. If you try "+12223334444@provider.net", you'll get the number, the @ symbol, and the character after it. The reason for this is that the arguments to Substring() are "where to start" and "how far to go". It's not array index selection, so when you call what is essentially Substring(0,10) you say "start at the first character and go forwards 10 characters". When you call Substring(2,12) (as is the case when your input contains +1, because @ is 2 indexes further into the string), you say "start at the second and go forwards 12 characters". You may need to do some more intelligent handling -- for example you could try doing a $string.Replace() to trim the string to what you want. You can match "at the beginning of a string" with the ^ symbol in regex (not really sure on the specifics of this in powershell though), and then it would be trivial to trim "everything after, and including, the first @-symbol". I would prefer this to Substring or index manipulation personally but I guess it's a style choice at that point. Additionally, you could replace your Substring() method with index selection, for example: code:
12 rats tied together fucked around with this message at 15:33 on Aug 3, 2015 |
# ? Aug 3, 2015 15:21 |
|
Reiz posted:Given the input of "2223334444@provider.net", if you do a substring() for @-10,@, yeah you will pull just the phone number. If you try "+12223334444@provider.net", you'll get the number, the @ symbol, and the character after it. Hm, well that makes sense why my solution isn't working. I'm fairly new to powershell so I'm trying to work out in your response what I can use to solve the problem. Index selection seems to make the most sense to me, so I tried: code:
|
# ? Aug 3, 2015 15:43 |
|
Oh, yeah, sorry about that. There's definitely a way better way to do this, but, quick fix:code:
But, to zoom out a second here, I'd probably do something like: code:
The second part just takes your phone number, splits it on the @ sign, and returns the first half. In either case you should be left with just the phone number. edit: Actually, it would probably better to just do this: code:
12 rats tied together fucked around with this message at 16:22 on Aug 3, 2015 |
# ? Aug 3, 2015 16:18 |
|
Reiz posted:edit: Actually, it would probably better to just do this: Two notes: First, the quick fix is doing something weird. If I leave off the pipe into ForEach-Object loop, I get the correct values for the 10 digit phone number with new line characters. If I add in the FE-O loop, it concatenates the digits, but for some reason the string now has a 1 at the beginning. I'm really struggling to understand how that "1" character gets added. So instead of trying to bang my head against that for much longer, I tried the second approach. I also added in a line about "if $phone starts with 1 trim 1" just in case there are providers that send the 1 without the plus. It looks like that's doing the job. Thanks!
|
# ? Aug 3, 2015 17:32 |
|
Reiz posted:Given the input of "2223334444@provider.net", if you do a substring() for @-10,@, yeah you will pull just the phone number. If you try "+12223334444@provider.net", you'll get the number, the @ symbol, and the character after it. This is easy with a regex unless I missed something: code:
$Matches[1] is the phone number $Matches[2] is the domain New Yorp New Yorp fucked around with this message at 17:59 on Aug 3, 2015 |
# ? Aug 3, 2015 17:44 |
|
CLAM DOWN posted:Oh my god I totally just learned you can do this Jeoh posted:You can also do this for modules No more complicated functions to check if the ActiveDirectory module is active, just code:
|
# ? Aug 3, 2015 19:50 |
|
That moment when you realize the script you just spent half an hour debugging, is not working because you're using if($a = $b){stuff} instead of if($a -eq $b){stuff}
|
# ? Aug 4, 2015 23:33 |
|
It would have worked in VB
|
# ? Aug 5, 2015 00:32 |
|
Hadlock posted:That moment when you realize the script you just spent half an hour debugging, is not working because you're using if($a = $b){stuff} instead of if($a -eq $b){stuff}
|
# ? Aug 5, 2015 02:19 |
|
I've wasted hours on that same thing.
|
# ? Aug 5, 2015 03:52 |
|
http://blogs.msdn.com/b/powershell/archive/2015/08/06/windows-management-framework-wmf-5-0-roadmap.aspx The Windows Management Framework 5 Roadmap has been posted! They're doing an interesting thing here, releasing a "production preview" version sometime this month, and then the RTM version in Q4. Production Preview sounds like some beta poo poo but it's "fully supported" and has no experimental features. I'm happy to be able to get 5.0 on production machines without waiting for Server 2016 to come out.
|
# ? Aug 7, 2015 19:16 |
|
This is an embarrassing post to make but I'm in a serious time hole and don't have time to think. If I've got a file called 0072.png, how can I make 71 copies of it (0001.png through 0071)?
|
# ? Aug 8, 2015 04:19 |
|
Newf posted:This is an embarrassing post to make but I'm in a serious time hole and don't have time to think. code:
Edit: OK I kinda tested and fixed an issue. Should pretty much work. Try a whatif first to make sure. Zaepho fucked around with this message at 04:28 on Aug 8, 2015 |
# ? Aug 8, 2015 04:26 |
|
Newf posted:This is an embarrassing post to make but I'm in a serious time hole and don't have time to think. code:
poo poo, not only was I beaten by about six minutes, I wrote crappier code. Dr. Arbitrary fucked around with this message at 04:37 on Aug 8, 2015 |
# ? Aug 8, 2015 04:32 |
|
|
# ? Apr 25, 2024 21:05 |
|
Thanks both. Worked like a charm.
|
# ? Aug 8, 2015 04:42 |