|
Welp, the head of AppDev at our company realized we've written over 5000 lines of powershell in the last year which has a linear relation to the amount of billable hours they didn't get from us last year for internal C# projects, so we're not allowed to write any large powershell projects anymore, they have to go through AppDev now.
|
# ? Feb 6, 2015 05:45 |
|
|
# ? May 15, 2024 04:46 |
|
myron cope posted:I think python (or something that isn't powershell, at least) is ultimately a better option, but I need to, you know, learn some python first. Would something like this work? code:
|
# ? Feb 6, 2015 06:32 |
|
I'm trying to use a powershell script to retrieve all empty groups. But it also lists domain computers Which has 2000+ members. to work around that i made the script count how many members there are in each group. That works and is good enough to use. but I am curious as to why it keeps seeing Domain Computers as an empty group. This is the script i'm using. code:
|
# ? Feb 6, 2015 10:26 |
|
Sefal posted:I'm trying to use a powershell script to retrieve all empty groups. But it also lists domain computers Which has 2000+ members. With the one from MS I'd do it like this: code:
|
# ? Feb 7, 2015 03:09 |
|
You all know that powershell has a multi line mode that's like perl.net right And a debugger that's nicer than pythons at leasts Please don't create long rear end pipeline one liners are they are unmaintainable Lol@5k of ps not being billable though just charge it like any other .net language
|
# ? Feb 8, 2015 18:02 |
|
Microsoft is doing a couple of live events later this month covering DSC if anyone is interested. These tend to be recorded and can be watched at a later date as well http://www.microsoftvirtualacademy.com/liveevents/getting-started-with-powershell-desired-state-configuration-dsc http://www.microsoftvirtualacademy.com/liveevents/advanced-powershell-desired-state-configuration-dsc-and-custom-resources
|
# ? Feb 12, 2015 18:47 |
|
Feel like I am doing this all wrong, but need some help on how to break out of an area of the code. I am basically writing a script with a GUI that will do certain things to a database via a SQL connection. The GUI itself takes inputs (servername, database, username, password) and I have added buttons that will trigger particular events. So button1 might update a particular column on the database, button2 might dump data into an XML, etc. Pseudo-written like this:code:
Edit: Nevermind I figured it out! Instead of calling variables, I just changed it to a function definition. Then, I just put in a "return" after the Connection Is Invalid line. It throws the appropriate SQL errors and goes back to the GUI as expected. Weaponized Autism fucked around with this message at 15:32 on Feb 13, 2015 |
# ? Feb 13, 2015 02:08 |
|
Tailored Sauce posted:Edit: Nevermind I figured it out! Instead of calling variables, I just changed it to a function definition. Then, I just put in a "return" after the Connection Is Invalid line. It throws the appropriate SQL errors and goes back to the GUI as expected.
|
# ? Feb 14, 2015 04:23 |
|
I posted this over the Working in IT thread, and they kindly directed me here, any suggestions? I have a project at work to help cull some of the decade plus data sitting on our Windows file servers that hasn't been accessed in a decent amount of time. Googling has indicated that a Powershell script would probably be best. The problem is that I know next to nothing about Powershell. It is on my to-learn list, but I'm currently enrolled in WGU, so my brain's in depth learning bandwidth is maxed by my current courses. I found a script that works pretty well: code:
|
# ? Feb 24, 2015 16:53 |
|
Have you tried invoking the \\?\ prefix? That should get you up to 32k. I haven't tried this in a while, but read this article: http://blogs.msdn.com/b/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx
|
# ? Feb 24, 2015 17:04 |
|
CapMoron posted:I posted this over the Working in IT thread, and they kindly directed me here, any suggestions? There's a janky workaround that might work but you would have to run the script on the file server itself (you can't use UNC paths for this). Basically, you could create directory junctions that are short, but lead into the deep paths. It would be a bit of a pain in the rear end, since you would constantly have to be using the junction path to traverse the share, and create new junction paths deeper inside as needed. To create the junctions, you can use mklink, which does support the \\?\ prefix: code:
code:
It's really just the logistics of creating and deleting the junctions as needed that will be really annoying. To delete, use rmdir (or rd): code:
Briantist fucked around with this message at 22:09 on Feb 25, 2015 |
# ? Feb 25, 2015 21:20 |
|
Briantist posted:It's unlikely you'll be able to directly use the \\?\ prefix within PowerShell since PowerShell relies on the .Net objects behind the scenes. Vulture Culture fucked around with this message at 00:06 on Feb 26, 2015 |
# ? Feb 26, 2015 00:02 |
|
Misogynist posted:One other option I absolutely have not tested, but should at least work locally, would be to handle your own recursion and change into each enumerated child directory using Push-Location and Pop-Location instead of bookkeeping junctions. Since you're dealing with relative paths instead of absolute paths at that point, you're very unlikely to hit PATH_MAX issues. I thought about that, but looking at the articles that Jeoh posted, part of what the Win32 APIs do (if they aren't processing a long path pre-ceded with \\?\) is to normalize the path, which includes among other things "converting relative paths into full paths" so I thought that that would not end up working.
|
# ? Feb 26, 2015 00:39 |
|
So I'm having a bizarre issue with remove-item that maybe the brain trust here can shed some light on. The goal of this script is to on a daily basis pull specfic files from a inactive archive directory. These archive folders are created one for each day by an application and the folder names are always in the format of yyyyMMdd_1_Some random string of numbers. When I run the script below I get zero files found for removal.code:
code:
|
# ? Feb 26, 2015 04:42 |
|
Powershell on my work machine seems unable to save any configuration / installations. For example, if I install PsGet with the command (new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex , I'm able to use it, but after I exit powershell and restart it PsGet isn't there anymore. What's broken here? How do I fix it?
|
# ? Feb 27, 2015 15:29 |
|
Harry Lime posted:So I'm having a bizarre issue with remove-item that maybe the brain trust here can shed some light on. The goal of this script is to on a daily basis pull specfic files from a inactive archive directory. These archive folders are created one for each day by an application and the folder names are always in the format of yyyyMMdd_1_Some random string of numbers. When I run the script below I get zero files found for removal. In any case, while it's not exactly the powershell way, I would probably circumvent the parameters with something like this: code:
|
# ? Feb 27, 2015 17:19 |
|
Newf posted:Powershell on my work machine seems unable to save any configuration / installations. For example, if I install PsGet with the command (new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex , I'm able to use it, but after I exit powershell and restart it PsGet isn't there anymore.
|
# ? Feb 27, 2015 17:21 |
|
Briantist posted:I'm not 100% certain why you're seeing this behavior. When you say that you replace $Date with the exact name, are you still using the wildcards? -Include and -Exclude require wildcards to be used in the Path, so if you aren't doing that, then Include might actually be taking the place of Path. quote:In any case, while it's not exactly the powershell way, I would probably circumvent the parameters with something like this: I've been working with a coworker on this problem and a script very similar to yours is the only way we have been able to get it to work so far.
|
# ? Feb 27, 2015 17:37 |
|
For beginners like me I found this series immensely helpful: http://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-3-0-jump-start Not sure if it's been posted here before.
|
# ? Feb 28, 2015 01:59 |
|
Can Compare-Object be used to compare more than just two objects/references? Would I have to break things down into multiple comparisons so I can compare four directories of similar filenames?
|
# ? Mar 3, 2015 20:12 |
|
Jake Blues posted:Can Compare-Object be used to compare more than just two objects/references? I'm still a powershell nincompoop but something close to this answer from above would probably work? Bluffoon posted:Would something like this work?
|
# ? Mar 4, 2015 23:16 |
|
Dang, that's actually really close to what I was hoping to do. I'm going to steal that and modify it to suit my needs. I'll definitely paste my finished piece when it's working but I'm just glad I don't need to feed results into more comparisons. Thanks!
|
# ? Mar 5, 2015 16:46 |
|
Briantist posted:
Honestly I've run into something like this before, and I'm about 99% sure I was able to successfully use: code:
In any case, I would strongly recommend that you try to use -like and -notlike whenever possible (no matter how kludgey), because I've never had good luck with -include or -exclude. This also seems like a great use case for regular expressions, but I have this problem where I always try to justify problems as a use case for regular expressions.
|
# ? Mar 6, 2015 17:51 |
|
I am trying to create a GUI that will display all output triggered by PowerShell. I have a Start-Transcript writing to transcript.log, and I was able to display it successfully in a RichTextBox via: $outputBox.Text = Get-Content ./transcript.log | Out-String However, the problem is Get-Content. From what I am reading online, this just won't work because it basically locks the file it reads. This leads to the transcript.log not writing in new data, and also I don't even know if I refreshed the GUI form it would show. So I think the alternative is to set up some sort of filestream into the GUI. I tried tail, but that actually prevents the GUI from appearing. Any ideas? My end goal is to create a "Live Log Viewer" at the bottom of all my programs so I (and others) can see all PowerShell activity without viewing it in a shell window. code:
|
# ? Mar 10, 2015 19:59 |
|
Why not output it to a log file and use something like CMTrace for live updates?
|
# ? Mar 10, 2015 20:05 |
|
Jeoh posted:Why not output it to a log file and use something like CMTrace for live updates? Oh I absolutely could, but I wanted to figure out a way to do this solely through PowerShell and not rely on other applications.
|
# ? Mar 10, 2015 22:17 |
|
I'm fighting badly with a script to scan a list of machines for installed KBs. I create a remote WindowsUpdate Session and everything goes pretty good until I start trying to filter the data. I was never able to get the Search method of IUpdateSearcher to return anything meaningful, so I used some methodology I found in a TechNet article to walk the collection. The line where everything goes sideways is the loop to iterate across the results. It gives me exactly what I'm looking for, but it spins up a ton of network activity and takes about 20 seconds to process. That feels like an awful long time to iterate across a completed query (like, 300 lines of text). While it only takes about 20 seconds, that's fairly unwieldy when you multiply that by 100 or 1000 machines. I'm not anything approaching a PS expert, but is there a way to just pull the entire collection over locally once so that I can run all my comparisons against that?code:
|
# ? Mar 13, 2015 21:29 |
|
Toshimo posted:I'm fighting badly with a script to scan a list of machines for installed KBs. I create a remote WindowsUpdate Session and everything goes pretty good until I start trying to filter the data. I was never able to get the Search method of IUpdateSearcher to return anything meaningful, so I used some methodology I found in a TechNet article to walk the collection. The line where everything goes sideways is the loop to iterate across the results. It gives me exactly what I'm looking for, but it spins up a ton of network activity and takes about 20 seconds to process. That feels like an awful long time to iterate across a completed query (like, 300 lines of text). While it only takes about 20 seconds, that's fairly unwieldy when you multiply that by 100 or 1000 machines. I'm not anything approaching a PS expert, but is there a way to just pull the entire collection over locally once so that I can run all my comparisons against that? But there are 2 ways to mitigate this: 1. Parallelize the process by using PowerShell Jobs. Then the 20 second pauses run in parallel (not perfectly, it will probably take more than 20 seconds just to set up all the jobs). Be a bit careful with this; jobs are not threads. You spawn at least one new process with each background job. If you have 1000 servers, then consider whether the machine you're running this on can handle 1001+ PowerShell sessions and the associated DCOM (?) traffic from the Update Searcher concurrently. 2. Don't use a remote searcher. Instead use a PowerShell remoting session so that your code is running on the remote machine, then just use the local searcher. This requires having PowerShell remoting setup and configured on your servers. If you don't have this already, then you should; it's incredibly useful. I have an article about configuring it through Group Policy. Then, you can use: code:
I highly recommend option 2, whether you use jobs or not. Here's a good article on running jobs out of a queue, in case you have enough servers that jobs will wreak havoc on the local machine.
|
# ? Mar 14, 2015 01:54 |
|
Briantist posted:But there are 2 ways to mitigate this: I'll take a look when I get back in on Monday, but I'm pretty sure PowerShell remoting is not enabled and I don't have the pull to get the GPO changed. I'm running my scripts from a Win7x86 box with 4 gig of RAM and about a billion layers of cruft. I've done the parallelization both through jobs and through just good old "for-each -parallel". Either one helps, but I don't get too many concurrent jobs. Thanks for the links, though. I'll give them a read.
|
# ? Mar 14, 2015 02:13 |
|
If you need better performance than background jobs can give you for tasks that are embarrassingly parallel, you can also consider runspaces, or workflows if you need more control over the way results are aggregated and returned. Workflows might be really helpful here just for the built-in checkpointing capabilities.
|
# ? Mar 14, 2015 16:51 |
|
Microsoft just posted the Advanced PowerShell Desired State Configuration (DSC) and Custom Resources Jump Start session video. Available at: http://www.microsoftvirtualacademy.com/training-courses/advanced-powershell-desired-state-configuration-dsc-and-custom-resources I guess I know what I'll be watching tonight.
|
# ? Mar 17, 2015 00:34 |
|
Toshimo posted:I'm fighting badly with a script to scan a list of machines for installed KBs. I know this is a PowerShell thread, but isn't this better handled by SCCM?
|
# ? Mar 17, 2015 01:37 |
|
AreWeDrunkYet posted:I know this is a PowerShell thread, but isn't this better handled by SCCM? You would think so. But in the last month of listening to our conference calls with Microsoft, I've begun to suspect that SCCM reporting is currently held together with baling wire and bubble gum. There's some goofy stuff going on like machines reporting as compliant immediately on release of a SUS package based on the fact that the machines are unreachable so the SUS server defaults to the last known catalog, which of course doesn't have the current package in it. Also, I don't have access to enough DBA time to write anything big and custom to get just this sort of info (which would be an arseload of work). In regards to the other suggestions, I have verified that we don't have Powershell remoting enabled, and every variant of parallelization I've tried has capped out rather low because as soon as it tries to do a significant number of simultaneous connections, it causes the networking on the box to break down (it was dropping my RDP session at some points).
|
# ? Mar 17, 2015 02:55 |
|
Toshimo posted:like machines reporting as compliant immediately on release of a SUS package based on the fact that the machines are unreachable so the SUS server defaults to the last known catalog, which of course doesn't have the current package in it. OK that's really goofy and something I haven't seen. I'll have to see if I can reproduce this. Can you elaborate further? As I understand it a machine only reports compliance/requirement with each individual update. From there the SCCM reporting summarizes that into compliance with the entire update group. WSUS itself has very little to do with it and should be completely ignored 99% of the time. I'm really interested in what you're seeing and understanding it better so i can answer any questions about it that customers might have. I'd hate to be caught with my pants down.
|
# ? Mar 17, 2015 04:25 |
|
I'd like to define a macro to clear everything from a directory. I tried code:
code:
|
# ? Mar 19, 2015 15:03 |
|
I'd start here: http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/07/weekend-scripter-cmdletbinding-attribute-simplifies-powershell-functions.aspx If you're going to be using powershell a lot, you shoud also look into creating a module. I created and maintained a module full of useful niche commands for my previous employer and it was quite enjoyable and useful. You might want to wait until you have more custom scripts though because you can probably just do "del *" inside powershell and it will clear out the directory you are in.
|
# ? Mar 19, 2015 17:29 |
|
I once had a shell script in ubuntu that I could call to watch apache logs. Behold, logwatch.sh: pre:tailf $1 | awk '{if ($7 !~ /favicon.ico && $7 !~ /robots.txt) print $1 " " $4 $5 $6 " " $7 " " $8 " " $9}' I would just run logwatch.sh /path/to/logfile.txt which would tailf the file and pipe it to awk and bam, magic. Now I'm streaming log files from azure with azure site log tail mywebsite. How do I do this in powershell? I want to pipe the lines output from one program into another, filter out the ones I don't want, and print the parts of the line I want to see. I've been googling in circles for half an hour just to figure out how to read from stdin in a loop and I'm still not sure how to do it. Edit: I figured this would be a good start, just echo the lines on [Console]::In, but it sits there waiting for user input. (If I type 'hello' and press enter, I get 'hello' back.) pre:while (($line = [Console]::In.ReadLine()) -ne '') { write-host $line } C:\> azure site log tail mywebsite | thescript.ps1 epswing fucked around with this message at 05:01 on Mar 31, 2015 |
# ? Mar 31, 2015 04:51 |
|
epalm posted:I once had a shell script in ubuntu that I could call to watch apache logs. Typically if you're piping into powershell like that, you can just use the $input variable in your script and it will contain everything you piped. Note that powershell reads all of the input before your script starts executing.
|
# ? Apr 1, 2015 22:16 |
|
While I do have a modest amount of programming background, I've never done much in Windows and I'm basically a novice with PowerShell. We've started using Microsoft's Group Chat, the thing that's part of Office Communications Server 2007 R2; before you ask, yes I know that Lync replaced this and has it's own "persistant chat" that replaces the Group Chat functionality, but we're part of a woefully sluggish corporate environment that can't be bothered to get up to speed with that, and no idea how long it might be before they get their act together. What I'd like is a PowerShell script that can send a message to one of the groups I'm a part of in my existing/running instance of Group Chat, and I'm having a hell of a time either finding either examples or much in the way of documentation on how to go about it. On the contrary, I do have Lync 2010 running as well, and found a nice and simple example of how to start a Lync "conversation" with members of a Lync group, which I'll paste below in case anyone finds that interesting. If anyone knows of or can help create something similar for Group Chat, I'd very much appreciate it. (the below assumes you have the Lync SDK installed in the standard location, change the first line if that isn't true for you) code:
|
# ? Apr 2, 2015 19:03 |
|
|
# ? May 15, 2024 04:46 |
|
I want to do something in windows 7 which should be trivially simple, I don't have powershell, but it looks like it is the right tool for the job, so installing it now. All I want to do is get every subfolder in a specific folder and overwrite the modified date with the created date, is this the sort of thing powershell does?
|
# ? Apr 5, 2015 20:29 |