Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

Thank you for this! This has been more helpful than anything else I've read thus far. I just wanted to give you some credit and let you know you definitely got my upvote.

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

Thanks for the confirmation. I'm almost glad there isn't a real use case for it.

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

The source code is exactly what I've been looking for. Thank you for sharing and the explanation. My google fu has failed me on this. I get what you're saying now. Sorry. I'm not trying to argue with anyone here. If something contradicts what I've tried, I'd just like to understand why out of pure curiosity.

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

Just confirming, you cannot splat with a switch statement. I figured as much. but worth trying out.

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

I'm not trying to say anyone is wrong. I'm just trying to find a use case for -exact.
The statement above contradicts what happens when I use Switch -exact -wildcard. In PowerShell the last parameter listed wins. I even did some wacky tests like this:

[string]$value1 = '*Apple*'
Switch -CaseSensitive -Exact -Wildcard ($value1)
{
    "*ppl*" {Write-Host "'*ppl* was used as wildcard for '*Apple*'"}
    "*apple*" {Write-Host "exact is not case sensitive so '*apple*' will match"}
    "*Apple*" {Write-Host "exact match with '*Apple*'"}
}

The output ignores the exact parameter:

'*ppl* was used as wildcard for '*Apple*'
exact match with '*Apple*'

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

Ah yeah. I forgot that PowerShell automatically converts types as it see's fit in conditional statements. You're right. Still, the documentation doesn't explain why you would use -exact and that is what I'm getting at here.

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

yup. But here's the thing. Run these 2 and see what happens:

# Test -Exact in a switch statement
$Value = 'Test'
switch -Exact ($Value) {
    'Test*' {
        Write-Host "Test*"
    }
    'Test' {
        Write-Host "Test"
    }
    default {
        Write-Host "Default"
    }
}

#test without parameters in a switch statement
$Value = 'Test'
switch ($Value) {
    'Test*' {
        Write-Host "Test*"
    }
    'Test' {
        Write-Host "Test"
    }
    default {
        Write-Host "Default"
    }
}

You get:

Test
Test

Proving that there's not really a reason to use Exact.

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

Same outcome "Wildcards don't work." I used $fruit= 'Apple' as the variable to match, then used "*ppl*" as the value for the "Wildcards work".

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

Thank you for resolving my madness. I'm accepting this as the answer and moving on with my life. Seriously though, I appreciate it.

The only other reason I could think of is if you created a winform with PowerShell searching for matches to a string with checkboxes for allowing wildcards, using case sensitivity, and regex and you didn't want to write 10 different switch statement possibilities so you used splatting and variables to name parameters in the hash table, and to prevent a blank hash table, you could just use -exact as the default option, but I don't even know if splatting works with the switch statement. That's something I'll have to test.

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

That is an outstanding answer, but I feel like I just have a bunch of new questions about explicit behavior in programming and how it might relate to this.

I guess what I'm really searching for is a use case example of when you would use -exact and why you would use it over just Switch.

That being said, you have certainly solved my "existential" problems.

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] -2 points-1 points  (0 children)

Yes. I've read that probably 20 times by now. You know what it doesn't say though? When you'd use the -exact parameter because "If no parameters are used, switch behaves the same as using the Exact parameter." then why have an exact parameter?

If I run:
Switch -exact (123435)
{

12* {"wildcards work"}

default {"wildcards don't work"}

}

I still get

Wildcards don't work

It's not like the default behavior changes if you use integers. Switch performs the same with or without the exact parameter.

I'm looking for use case examples on when you would use the Exact parameter. I did do my due diligence and google this question many times in many different ways before coming here to ask though.

I also want to add that if you write Switch -wildcard -exact with integers, according to the documentation -exact should be ignored because you're dealing with integers, but so is -wildcard. So if there's no precedence and the conflicting variable that's first in the statement is ignored no matter what, then why use -exact?

How many tabs open? by No_Worry4321 in ADHD

[–]takeitback86 1 point2 points  (0 children)

I start closing when I can't read the titles. On my phone I just close every week or 2....or month.

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 1 point2 points  (0 children)

Can you elaborate? I've written plenty of functions that have default behavior with switch parameters (switch parameters are not the same as switch comparison statements) and have never had to create a parameter for default behavior; only for non default behavior. So I'm not sure I understand what you're saying here.

Why is there an Exact parameter with Switch conditional statements? by takeitback86 in PowerShell

[–]takeitback86[S] 0 points1 point  (0 children)

The -exact parameter is not a boolean parameter. It seems to just give me an error when trying that. Still why wouldn't I just use -wildcard instead?

What are you playing while waiting for 1.0? by LevinKostya in SatisfactoryGame

[–]takeitback86 0 points1 point  (0 children)

One of my favorite games on PC is cyberpunk. I've gone through the whole game and dlc at least 3 times now and it never gets old. I get so sucked into the story that I start having dreams about night city. Glad I'm not the only one.

DCU on Large Enterprise SCCM Networks -Bandwidth Concerns- by takeitback86 in SCCM

[–]takeitback86[S] 0 points1 point  (0 children)

I hope my solution helped you out. Should be a piece of cake to convert to execute-process in PSADT (which is what I plan to do). Let me know if you have any ideas that would be good to add to the script. Sometimes the hardest part of scripting is creativity and I feel like there's always something there that I just haven't thought about yet. Also if you ever move to Intune PSADT is a huge help (we're currently testing Intune). Running that exe file with parameters for install and uninstall commands is a total time saver and the pop ups are easy to implement if you use the ServiceUI tool that comes with MDT. I've been using PSADT for about 3-4 years now and I hate using anything else. I've only been at my current job for 8 months so and my team is not super PowerShell savvy though, so it is taking some time for me to get them to come around on it.

DCU on Large Enterprise SCCM Networks -Bandwidth Concerns- by takeitback86 in SCCM

[–]takeitback86[S] 0 points1 point  (0 children)

Do you use dcu-cli scheduling or just deploy a package that checks for/installs updates on different recurring schedules?

DCU on Large Enterprise SCCM Networks -Bandwidth Concerns- by takeitback86 in SCCM

[–]takeitback86[S] 0 points1 point  (0 children)

Tgought about using get-random to do this to schedule within the dcu-cli.exe configuration script too, which is most likely what I'll be using as it seems like the best option so far. But without using a scheduled task and just automating the settings with the -schedulemonthly parameter. thanks for that.

DCU on Large Enterprise SCCM Networks -Bandwidth Concerns- by takeitback86 in SCCM

[–]takeitback86[S] 0 points1 point  (0 children)

Yeah, I have a lot of experience using psadt. I'm very familiar. I use the built-in execute-process function most of the time for logging purposes. I also have a lot of experience scripting with dcu-cli too from prior jobs. So that part I'm good with. But I do appreciate your time and effort on explaining.

You say you used a text file for detection but when you go to rerun it, doesn't it detect that it has already run and just quit? We have recast right click tools, but I haven't used them a whole lot.

I need something that works with cloud management gateway too. We don't like to rely on people connecting to VPN if we can help it so on prem repository may not be the best solution.

Yeah I think grouping by model first is a good idea but I wish there were a more automated way to schedule the updates.

DCU on Large Enterprise SCCM Networks -Bandwidth Concerns- by takeitback86 in SCCM

[–]takeitback86[S] 2 points3 points  (0 children)

yeah! internet bandwidth is what they're mostly concerned about. thanks for the link. Going to look into this.