What's the best way to terminate a script not using throw or exit?
|
|
# ? Nov 30, 2018 22:59 |
|
|
# ? Jun 13, 2024 04:19 |
|
Submarine Sandpaper posted:What's the best way to terminate a script not using throw or exit? break or return should do it
|
# ? Nov 30, 2018 23:12 |
Submarine Sandpaper posted:What's the best way to terminate a script not using throw or exit? Restart-Computer
|
|
# ? Nov 30, 2018 23:22 |
|
Zaepho posted:break or return should do it Using return is the best practice. break exits "Foreach, For, While, Do, or Switch statements" and return exits a "function, script, or script block." nielsm posted:Stop-Computer -Confirm:$false -Force ftfy
|
# ? Dec 1, 2018 07:49 |
|
Learn Windows PowerShell in a Month of Lunches is this still the go to for learning powershell? Is there anything else out there that would be better?
|
# ? Dec 3, 2018 15:37 |
|
Flaggy posted:Learn Windows PowerShell in a Month of Lunches Month of Lunches is still widely used. I've sent it to a number of people at my company within the last year who asked to learn PS. If you'd like something a little more interactive, though, I'd recommend you also check out PSKoans, which is a little bit like a text-based adventure game that incrementally teaches you PS.
|
# ? Dec 3, 2018 17:14 |
|
slartibartfast posted:Month of Lunches is still widely used. I've sent it to a number of people at my company within the last year who asked to learn PS. If you'd like something a little more interactive, though, I'd recommend you also check out PSKoans, which is a little bit like a text-based adventure game that incrementally teaches you PS. Awesome, thank you!
|
# ? Dec 3, 2018 18:55 |
|
Flaggy posted:Awesome, thank you! Don Jones (author of that book) also has a fantastic course on CBT nuggets, if you can find a way to access that. There's probably a dozen coworkers of mine who've learned intermediate to expert level powershell from that course alone.
|
# ? Dec 3, 2018 19:02 |
|
xsf421 posted:Don Jones (author of that book) also has a fantastic course on CBT nuggets, if you can find a way to access that. There's probably a dozen coworkers of mine who've learned intermediate to expert level powershell from that course alone. Dang, that looks nice but is kind of spendy. 840 per year. That is bonkers.
|
# ? Dec 3, 2018 19:09 |
|
slartibartfast posted:Month of Lunches is still widely used. I've sent it to a number of people at my company within the last year who asked to learn PS. If you'd like something a little more interactive, though, I'd recommend you also check out PSKoans, which is a little bit like a text-based adventure game that incrementally teaches you PS. That PSKoans thing appears to be nothing more than an interactive version of the PowerShell core about_* topics. It's implemented in Pester so zero guarantee that it will operate correctly in your environment and it doesn't allow real experimentation within the learning environment. And god help you if you're just learning and decide to take a look at the code in the underlying module. IDK maybe I'm too cynical but this kind of stuff just doesn't seem useful. IMO a better approach is regular learning stuff peppered with problem solving (This script is hosed, fix it using concepts learned) and open design (Make a script that returns "thing" using the concepts you've learned) activities in a sandbox environment. That's the good poo poo but I don't know what provides that though so gently caress me in advance.
|
# ? Dec 3, 2018 19:21 |
|
If you want to get some practice in, Advent of Code is up and is fun.
|
# ? Dec 3, 2018 19:55 |
|
The Fool posted:If you want to get some practice in, Advent of Code is up and is fun. Thanks for posting this. These puzzles are indeed a lot of fun and educational.
|
# ? Dec 5, 2018 00:23 |
|
Yeah it's awesome, I have found out how little I know about powershell very quickly...
|
# ? Dec 5, 2018 02:25 |
|
I am basically brand spanking new to Powershell and am trying to edit the DNS settings of a NIC that I might not know the name of. This script will run on different AWS EC2 instance types and the adapter name and driver type can vary. Right now I have : code:
But when I run line 1 on its own the output is "Name : Ethernet0" Somehow line 2 is picking up a bunch of different stuff that I don't see in "normal" output. Before I get too deep into an X-Y problem here, am I even going about this the right way? Is there a better way to accomplish the task of setting DNS entries for the only active ethernet adapter?
|
# ? Dec 30, 2018 23:29 |
|
Agrikk posted:I am basically brand spanking new to Powershell and am trying to edit the DNS settings of a NIC that I might not know the name of. This script will run on different AWS EC2 instance types and the adapter name and driver type can vary. Try: code:
|
# ? Dec 30, 2018 23:34 |
|
xsf421 posted:Try: This worked. Thank you!
|
# ? Dec 31, 2018 00:41 |
|
I'm not 100% but I'm pretty sure you only ever want to use "Format-List" to make something human readable rather than when you're trying to pipe the value around.
|
# ? Dec 31, 2018 01:00 |
Agrikk posted:Format-List -Property "Name" code:
code:
code:
|
|
# ? Dec 31, 2018 08:51 |
|
How do you properly define JSON with nested/bracketed values in PowerShell? I have a number of processes that are using curl right now to make some REST calls, but I'd be happy to swap them over to Invoke-RestMethod and avoid using a third-part application. Here's a payload formatted for CURL in PowerShell (using automation variables as well as PS variables): code:
|
# ? Jan 10, 2019 19:41 |
|
Is there a reason that ConvertTo-JSON and ConvertFrom-JSON wouldn't work for you?
|
# ? Jan 10, 2019 19:45 |
|
I'll echo The Fool, that's what I would do. I will mention a weird finnicky thing:code:
|
# ? Jan 10, 2019 20:03 |
|
Also don't curl, use Invoke-RestMethod or Invoke-WebRequest if you can't use Invoke-RestMethod. And Powershell can be weird with nested JSON, by default ConverTo-Json assumes 2 levels of bojects, but there is a depth flag to the cmdlet if your JSON is more nested than that.
|
# ? Jan 10, 2019 21:42 |
|
ConvertTo-JSON worked just fine, the issue was just formatting the line properly.code:
Edit: If anyone have experience with Keycloak calls I’d appreciate being shown where I’m wrong. I can get an auth token but my POST call using the token gets rejected. The same info works fine using curl, so it’s especially frustrating. PierreTheMime fucked around with this message at 22:36 on Jan 10, 2019 |
# ? Jan 10, 2019 22:11 |
|
Remember when they said that json formatting was poo poo but it doesn’t matter because no human would ever be editing it or interacting with it in any way?
|
# ? Jan 11, 2019 06:28 |
|
Agrikk posted:Remember when they said that json formatting was poo poo but it doesn’t matter because no human would ever be editing it or interacting with it in any way? the problem is that there's a paradox between "human readable" and "human editable" - JSON was touted as human readable, but you're really not supposed to be creating JSON through string concatenation because there are edge cases that will break the parser (and it becomes more likely to hit those the more complicated the object gets) - but people do it anyway and it mostly works until it doesn't, even though just creating an object and serializing it is easier code to write and will always generate valid JSON.
|
# ? Jan 12, 2019 09:25 |
|
json is more readable than yaml. fight me
|
# ? Jan 12, 2019 09:41 |
|
They're both shite, use whatever has a convenient conversion library for your language. Or use XML
|
# ? Jan 12, 2019 16:02 |
|
PierreTheMime posted:ConvertTo-JSON worked just fine, the issue was just formatting the line properly. You are hurting yourself by writing JSON by doing string concatenation. Use an associative array and convert it to JSON. code:
@() is a regular array @{} is an associative array (hash table, key/value pair)
|
# ? Jan 12, 2019 22:51 |
|
New Yorp New Yorp posted:You are hurting yourself by writing JSON by doing string concatenation. Use an associative array and convert it to JSON. Thanks for this, this was the first way I tried it (as it’s obviously more human-friendly) but I’d screwed up the arrays and figured I’d do it in a more literal way to prove the call worked and come back to it later. Your example showed me where I made the mistake, so problem solved, at least in terms of the body content.
|
# ? Jan 12, 2019 23:01 |
|
Methanar posted:json is more readable than yaml. i guess maybe depending on what you’re doing? for “never needs to be human edited” usecases, ok maybe. for like, configuration files that are always human edited though json loses because of comments
|
# ? Jan 13, 2019 16:21 |
|
Haha, one of my co-workers was struggling with pulling data out of a JSON return, and I was like, "Hold my beer, someone on the forums has the answer."
|
# ? Jan 14, 2019 22:09 |
|
Jowj posted:i guess maybe depending on what you’re doing? Why not have a json key of 'comment' for anything worth editing?
|
# ? Jan 15, 2019 02:51 |
|
Strict checkers of json data / proximity to the thing you actually wanna comment IMO. For instance: If you want to do something like configure an IAM policy in AWS through JSON, you can't just add a json key called "comment"; aws only allows certain keys within the thing. Which is a real pain if something is counter-intuitive and you want to comment it for posterity! You just! Can't! loving json.
|
# ? Jan 16, 2019 18:03 |
|
How does one capture a dynamic image source as a local file? While it's deprecated and I can generate the chart using PS, I do like the ease and simplicity of the Google Chart API. That said, while the API call renders in a browser properly using the <img src=""> tag, I get a 400 error if I try to use a webclient call to retrieve it. I'm downloading the image file to add it as an inline-attachment to emails, as the render gets blocked by our email filter. Example chart: code:
|
# ? Jan 18, 2019 19:39 |
|
I wouldn't do it in Powershell, but maybe either C# or Python using something like Selenium
|
# ? Jan 18, 2019 19:51 |
|
The Fool posted:I wouldn't do it in Powershell, but maybe either C# or Python using something like Selenium Yeah, I considered other code but I've already got the rest of the script driven in shell and would prefer not to bounce around to different languages if I can help it. My current version that creates the chart through System.Windows.Forms.DataVisualization.Charting.Chart works fine, it's just not as polished and takes more code upfront.
|
# ? Jan 18, 2019 20:03 |
|
PierreTheMime posted:How does one capture a dynamic image source as a local file? While it's deprecated and I can generate the chart using PS, I do like the ease and simplicity of the Google Chart API. That said, while the API call renders in a browser properly using the <img src=""> tag, I get a 400 error if I try to use a webclient call to retrieve it. I'm downloading the image file to add it as an inline-attachment to emails, as the render gets blocked by our email filter. The Fool posted:I wouldn't do it in Powershell, but maybe either C# or Python using something like Selenium mystes fucked around with this message at 20:08 on Jan 18, 2019 |
# ? Jan 18, 2019 20:04 |
|
mystes posted:It looks like your url is double escaped. Replacing "&" with "&" I can use wget on this url and it works fine. I don't know if this is the problem you were having specifically, but you may want to check for some sort of escaping problem.
|
# ? Jan 18, 2019 20:13 |
|
I need to find out how many AD users in a certain OU have extensionAttribute7 populated, and export this to a .csv file. I'm sure it'll start with Get-ADuser, but as a newb to this I'm having trouble fleshing out the rest. Can anyone help? EDIT: The following gave me what I wanted, except from all of AD. Now trying to figure out how to get from just one OU code:
TITTIEKISSER69 fucked around with this message at 19:19 on Jan 22, 2019 |
# ? Jan 22, 2019 19:06 |
|
|
# ? Jun 13, 2024 04:19 |
|
TITTIEKISSER69 posted:I need to find out how many AD users in a certain OU have extensionAttribute7 populated, and export this to a .csv file. I'm sure it'll start with Get-ADuser, but as a newb to this I'm having trouble fleshing out the rest. Can anyone help? code:
EDIT: to answer the question of how to search in a specific OU, use the -SearchBase flag in Get-ADUser with the distinguished name of the OU.
|
# ? Jan 22, 2019 19:19 |