|
I made some modifications to this code that allows a powershell script to trigger a uac prompt. Specifically, I've modified it so it can run as a function, and can run from a mapped network drive. Call this function in a script that needs admin privileges, it will trigger a uac prompt, and the re-launch the script with the credentials you entered in the UAC prompt. I don't know how useful this is to other people, but I'm getting some mileage out of it. code:
|
# ¿ Oct 28, 2016 01:04 |
|
|
# ¿ Apr 28, 2024 20:21 |
|
MC Fruit Stripe posted:I didn't even know Win+X was a thing - I'm more excited about learning that than this change! It can also be accessed by right clicking on the start button.
|
# ¿ Nov 18, 2016 04:51 |
|
I've kinda felt that you shouldn't be doing anything with powershell that would require a GUI anyway. Your scripts should be written to be able to be ran headless, and if you need a GUI launcher type thing, do that in a different language.
|
# ¿ Dec 20, 2016 23:57 |
|
I have a powershell script that has been giving me a headache today. The script queries a subsidiaries ad for user information, then updates the users account in our ad. If the account doesn't exist, it creates it. This script works flawlessly if the account already exists, however, if the script has to create a new account, it does so, but all of the subsequent "Set-ADUser" commands fail. If I run the script a second time, it updates everything. Hell, if I even tell the function to run twice in a row, it spits out a bunch of errors on the first pass, then works fine on the second pass. I have no idea what the gently caress to do at this point.
|
# ¿ Jan 10, 2017 02:18 |
|
oh god sanitizing variable names This function is called from Main. If I call it twice, I don't get errors. code:
code:
code:
|
# ¿ Jan 10, 2017 02:52 |
|
Walked posted:Gut shot from my phone, what happens if you sleep for 10 sec before calling the problematic function? Tried Sleeps up to 30 seconds and they didn't help.
|
# ¿ Jan 10, 2017 02:56 |
|
So, when I was sanitizing the variable names I noticed a Write-Output that should have been a Write-Error. I fixed that in the source script, and now it's working correctly. Thanks virtual rubber ducks.
|
# ¿ Jan 10, 2017 03:12 |
|
Ugato posted:Alright I'm a bit stumped with my current project. I'm trying to automate a lot of the daily repetitive tasks my team and I face. I've actually done so pretty successfully so far but now I'm looking to automate things related to spreadsheet data. I don't have any specific solutions for you, but my general approach would be to use the Excel module here to import your spreadsheet into powershell objects, do whatever processing I need, then export back to excel.
|
# ¿ Jan 26, 2017 22:39 |
|
I have a list of users pulled from one AD Server using this code:code:
code:
code:
Typing issue? If so how do I fix it? If not, what is going on? Edit: More frustration, the following works fine. code:
edit3: it is a typing issue. The following produced the desired results. code:
The Fool fucked around with this message at 03:01 on Jan 31, 2017 |
# ¿ Jan 31, 2017 02:32 |
|
Walked posted:AWS Free Tier dude. Is free tier still only available for the first x number of months after account creation, or did they do away with that limitation?
|
# ¿ Feb 2, 2017 22:05 |
|
Because Reasons I wrote this:code:
|
# ¿ Feb 10, 2017 22:01 |
|
beepsandboops posted:A developer's asked me to write a script that takes a look at a file on our IIS servers, checks the modified date, then sends an email to the developers Have service accounts with identical credentials on all of the machines, store non-sensitive connection info in a csv. Iterate over the csv, do your thing. If you want to fully automate, you can store the credentials as a secure string.
|
# ¿ Feb 11, 2017 06:00 |
|
Inspector_666 posted:When you do stuff like this, is the best way to get it into your workflow to add a Set-Alias line to your profile.ps1 file? That's what I've been doing with my scripts but it seems hack-y. Make your own modules.
|
# ¿ Feb 16, 2017 00:34 |
|
thebigcow posted:I also have zero experience with the AD cmdlets. Is the information you need available from Get-ADUser? If so you can probably pipe the Get-ADGroupMember results into either Get-ADUser directly, or into a ForEach-Object with a scriptblock that grabs what you need. Piping works. Ex: code:
|
# ¿ Mar 30, 2017 18:22 |
|
Avenging_Mikon posted:I piped to get-aduser and did the -properties * because it's for an audit and gently caress auditors (mostly not really). Hilariously it generates a 2MB xls file for the first group. If they come back annoyed, then I'll actually put effort in to get just the properties they wanted. What I really should have done is also find a way to make the command run against all 9 groups at once instead of modifying the script for each vpn group. I guess that will be my next lesson. Create a list of the groups, then ForEach through it.
|
# ¿ Mar 30, 2017 20:56 |
|
Roargasm posted:yeah my only real problem right now is this logic: Why is $_.Name surrounded by "'s? edit: quite test seems to indicate that it doesn't matter, still looks weird. The Fool fucked around with this message at 17:30 on Apr 27, 2017 |
# ¿ Apr 27, 2017 17:27 |
|
I'm wrong and dumb.
The Fool fucked around with this message at 00:12 on Apr 29, 2017 |
# ¿ Apr 28, 2017 21:20 |
|
Just going to leave this here as a monument to my stupidity. It took me entirely too long to figure this out. edit: vvv- The actual code does stuff, those are just watch expressions in the VS Code debugger. The Fool fucked around with this message at 23:29 on May 1, 2017 |
# ¿ May 1, 2017 23:08 |
|
Tried wrapping it in a try/catch?
|
# ¿ Jul 24, 2017 21:35 |
|
I'm doing some work with CSOM and needed to take a break to mention how awesome VS Code and the Powershell extension are. Really starting to flex the VS Code debugger with this project.
|
# ¿ Aug 2, 2017 01:12 |
|
code:
|
# ¿ Aug 3, 2017 01:53 |
|
anthonypants posted:I want to run an updater on an application, but it's for Mozilla Firefox so the steps involved are incredibly convoluted and stupid and I hate it. It pushes the status of the updater process to a file, which is just a single word, like "applying" or "failed" or "succeeded". I also don't know how long it's going to take. Would something like do {Start-Sleep -s 60} until (Get-Content "\\path\to\update.status" = "succeeded") in a script do what I think it will? ((get-content "\\path\to\update.status") -eq "succeeded")
|
# ¿ Sep 23, 2017 00:29 |
|
anthonypants posted:What I would like is for the script to hold up and not perform any of the post-install junk. I don't think that's going to do that. It will if you put use the do..until as you wrote it, I just corrected your conditional. code:
Works as you would expect The Fool fucked around with this message at 00:38 on Sep 23, 2017 |
# ¿ Sep 23, 2017 00:36 |
|
PowerShell Unplugged with Jeffrey Snover and Don Jones https://www.youtube.com/watch?v=D15vh-ryJGk This is a fun video. The Fool fucked around with this message at 20:11 on Sep 29, 2017 |
# ¿ Sep 29, 2017 20:02 |
|
Briantist posted:NYC PowerShell Meetup tonight. Serverless PowerShell using Azure functions, pretty cool stuff. I am not in NY, otherwise I'd consider going. I'm working on a project where one of the components is some logic done in Powershell, hosted as an Azure function, to manipulate a Sharepoint List via CSOM. It was really fun putting that together.
|
# ¿ Oct 9, 2017 20:51 |
|
https://github.com/powershell edit: lol, anthonypants already submitted it: https://github.com/PowerShell/PowerShell/issues/5136 edit2: because I'm bored code:
The Fool fucked around with this message at 17:48 on Oct 17, 2017 |
# ¿ Oct 17, 2017 17:40 |
|
Try ConEmu
|
# ¿ Nov 26, 2017 20:48 |
|
Use backtick ` not caret ^
|
# ¿ Dec 29, 2017 22:23 |
|
Sefal posted:I'm leaving the office now, But I just wanna say. You should give the book "Powershell in a month of lunches" a read. I’m phone posting so it’s not easy to post some sample code, but this is the right direction. You need to convert your date strings into date-time objects, subtract 7 days from the current date, then you can do direct comparisons and filter using where-object. https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-date The Iron Rose posted:One other thing to note - I don't know poo poo about powershell and I'm mostly just learning by doing, well, things like this at work. Any pointers would be greatly appreciated. One liners are only good for e-penis competitions and copy-pasting. If you are writing scripts to be saved and reused, be as verbose as is practical so that it is easier to go back and maintain your poo poo afterwards. The Fool fucked around with this message at 18:18 on Jan 15, 2018 |
# ¿ Jan 15, 2018 18:13 |
|
code:
|
# ¿ Jan 15, 2018 18:35 |
|
Yeah, I mess up the curly braces all the loving time and did nothing to valid the snippet I posted.
|
# ¿ Jan 15, 2018 18:48 |
|
Eschatos posted:Originally the requirement was to run the backup every 15 minutes, and I'm half expecting it to revert to that. Shadow Copies can be run as often as you want, and they are the solution you should be using instead of kludging together a script that will break when you need it most.
|
# ¿ Feb 26, 2018 18:48 |
|
You should be able to specify the module namespace by typing ModuleName\CmdLetName ie, "ActiveDirectory\Get-Aduser" and "Get-AdUser" are the same The other option may be to pass session objects around. I don't have the vmware modules to be able to verify your specific use case though.
|
# ¿ Mar 27, 2018 20:28 |
|
Is anyone aware of a better way to put a GUI wrapper around a powershell script? Even with poshgui.com, WinForms is a total loving nightmare.
|
# ¿ Mar 28, 2018 21:55 |
|
I had already started the project using https://www.poshgui.com so I just finished it up with what I had. Thankfully I was just adding a GUI wrapper to a pre-existing script and only needed to do 1 form with a couple browse dialogs and go! button. It was still a total nightmare, and if I find myself needing to do this in the future I am for sure either redoing the entire thing in C#, or doing a GUI launcher in C#.
|
# ¿ Mar 29, 2018 17:00 |
|
Double posting because I have a question about improving the performance of a different project. We have a system that generates to separate CSV files. These CSV's are related, but contain different data. All of the data generated is tied to a vendor ID number. In order to eliminate some workload on the finance team, I wrote a script that merges these to files. The tricky part is that the source files can have multiple lines for the same vendor that contains different data and that data needs to be consolidated into one line for the final file. This all works, but it takes about 5 minutes to run on two files with 2500 records. The biggest bottleneck is where I check to see if a vendor already has data in the the array using Where-Object. The function: code:
I'm wondering if there isn't more efficient way to locate the object in the array that matches $vendor. Any ideas?
|
# ¿ Mar 29, 2018 17:11 |
|
cheese-cube posted:Without seeing the entire script plus some sample data it's difficult to advise but it sounds like your issue is further up the chain. You're probably iterating through too many things, use "Select-Object -Unique" to extract your vendor IDs and then if necessary iterate through them. Again, it's hard to advise without samples. I have two data files, they have more fields that contain data like contact names and addresses, and some other accounting codes that don't change. The first file is a list of vendor codes and invoice amounts: code:
code:
code:
The loops both look like this: code:
New-VoucherLine creates a custom object with the all of the fields, and sets the fields that don't change. Update-VoucherLine adds the deduction and invoice values to the existing line. e: Right after posting that I eliminated my second get-voucherline and that seemed to help a little bit, but not a huge amount. code:
|
# ¿ Mar 29, 2018 18:09 |
|
It took me more time to figure out how to export a hash table to csv than it did to convert my array to a hashtable. I've got a 5x performance boost using a hashtable keyed on the vendor ID. The export-csv statement looks like this now: code:
The Fool fucked around with this message at 19:55 on Mar 29, 2018 |
# ¿ Mar 29, 2018 19:52 |
|
Can you elaborate on what's strange about it?
|
# ¿ Mar 29, 2018 20:26 |
|
|
# ¿ Apr 28, 2024 20:21 |
|
Not the first time I've forgotten about -ExpandPropertycheese-cube posted:Then from there as per my other post if you're just spitting out a 1D array of strings then it's easier to use Out-File. It's actually a custom object with about 10 member properties. e: each property corresponds to a column in the csv following a format defined by the financial program that is importing this file.
|
# ¿ Mar 29, 2018 20:47 |