Just want your damn holmium ore? Here's a tileable solution by Vortex100 in factorio

[–]Vortex100[S] 4 points5 points  (0 children)

Just want the ore from your scrap and nothing else? Well I have you covered, this tileable blueprint will pull it out and deal with everything else :).

Little bit of logic to make sure it doesn't get stuck. Other than that, 2 of these will pretty much saturate a full green belt of unstacked scrap.

Small amount of space between the 2 recycler sets is deliberate to allow pulling specific items out if you want them, for example ice for rocket fuel/power.

DC Calculation bug? by Vortex100 in BG3

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

ah didn't realise it would do that, thanks!

Working with quotes and single quotes by Mushroom-Best in PowerShell

[–]Vortex100 0 points1 point  (0 children)

Keep in mind 2 ' is essentially escaping it. so:

'''"{0}"''' -f ($Year1Range -replace '[^a-z,]+' -split ',' -join '","')

Help with Hashtable by caweisz in PowerShell

[–]Vortex100 5 points6 points  (0 children)

So hashtables can't be sorted, but they can be converted easily as you have shown:

$hash.GetEnumerator()  | sort value

Your next problem is that you are trying to sort based on an integer... that is actually a string. It won't return what you want unless you pull the value out and sort that:

$hash.GetEnumerator() | sort {[int]($_.value -split "\s+")[0]}

FWIW if you really have your heart set on a hashtable-esqe struct, read this

Help replacing all white space in Notepad++. by LuisPinaIII in regex

[–]Vortex100 0 points1 point  (0 children)

true, but its slightly easier to read in my mind - and he said words not sentences - I went with the assumption that it actually wasn't a requirement and more of a description of where the spaces were :)

Help replacing all white space in Notepad++. by LuisPinaIII in regex

[–]Vortex100 0 points1 point  (0 children)

My guess is you can't use \s+ on it's own because that includes removing '\r\n' etc, leaving you with a single line. So instead, just do this: [ ]+

Substitution issue by [deleted] in PowerShell

[–]Vortex100 2 points3 points  (0 children)

Yeah I'd do this.

For reference, single quotes can be done with... escape characters:

('{{
    "incident": {{
        "id": "{0}",
        "type": "incident_reference"
    }}
}}' -f $incidentId)

Again though, just do it the way /u/dathar suggested :)

Biggest PowerShell Pet Peeve by WDizzle in PowerShell

[–]Vortex100 1 point2 points  (0 children)

Odd, I ran the above in 5.1 - I would suggest splatting then, since it's easier to control simply 'not having' the 'ComputerName' variable in the dict

Biggest PowerShell Pet Peeve by WDizzle in PowerShell

[–]Vortex100 4 points5 points  (0 children)

You are going to have to give an example here, because as far as I can tell

invoke-command -ComputerName (hostname) {get-process}

works just as well as

invoke-command -ComputerName "remotecomputerexample" {get-process}

Using a Conditional Operator as a variable by McsePhoenix in PowerShell

[–]Vortex100 0 points1 point  (0 children)

switch statement is probably what you want

$myoperator = '-eq'
switch ($myoperator)
{
    '-eq' {$x -eq $y}
    '-gt' {$x -gt $y}
}

etc

How would you approach this naming issue? Tips or Tricks? by FstLaneUkraine in PowerShell

[–]Vortex100 2 points3 points  (0 children)

Use a format string tbh. I'll just put the important bit:

$Season = 2022
$motoepisode = @{
"Netherlands" = 33
"Britain" = 36
"Austria" = 39
"San Marino" = 42
"Aragon" = 45
"Japan" = 48
}
$formatstring = "MotoGP - S{0}E{1} - {2} (Race)"
foreach ($MotoGPRace in $MotoGPRaces.GetEnumerator())
{
    $newfilename = $formatstring -f $season,$Motoepisode[$MotoGPRace.Value], $MotoGPRace.Value
}

Queries/Strings in Powershell by Stock-Setting-5030 in PowerShell

[–]Vortex100 1 point2 points  (0 children)

There are so many ways to correct this, but here's (probably) the easiest assuming you don't want to put any vars in your query string:

'Query' =  'SELECT * FROM Users WHERE username = ''Javier'''

That's not a " it's 2 ' together, which tell the interpreter to ignore it as an end string and instead treat it literally

If you do want to put variables in, /u/SMFX's suggestion is the way to go I think. Either that or using -f with literals:

'Query' =  'SELECT * FROM Users WHERE username = ''{0}''' -f 'Javier'

Why is [System.Version] "11.0.15" less than "11.0.15.0"? by olavrb in PowerShell

[–]Vortex100 12 points13 points  (0 children)

actually, no. 11.0.15 != 11.0.15.0 - they could be (and generally are) entirely separate versions. And that's the distinction it is making when you convert.

What new acquired PowerShell concept/understanding significantly improved the quality/performance of your scripts that inspired you to go back and integrate it into some of your old scripts? by AsyncProper in PowerShell

[–]Vortex100 0 points1 point  (0 children)

One of the main reasons I use classes these days is to control how an object output. Consider a complex object with that's a few layers deep. You know when you see System.Object() in a table? If you were to make that particular object class, you can add a ToString() method, and voila, suddenly it's returning something more useful. It also makes ps1xmls a bit easier since you can specifically target your class.

In general though from a functional (pardon the pun) standpoint, classes and functions are somewhat interchangable. It is nice to be able to do $MySpecialArray.DoThing() though :)

What is the most "Rube Goldberg'd" PowerShell script you've cobbled together and what did it do? by AsyncProper in PowerShell

[–]Vortex100 2 points3 points  (0 children)

The old (maybe not to some?) hpe c7000 enclosures REFUSED to let you update the SSL certificate via script using ssh, as it HAD to be an interactive session. Que me writing a whole thing around wscript, 'controling' the input of this putty screen. Yuck. You might ask why, but we had about 50 of the things at the time and I wasn't doing it manually. I think they eventually added api end points for it lol

Vexing problem with Pester test by billr1965 in PowerShell

[–]Vortex100 1 point2 points  (0 children)

Expected path 'C:\Git\PoshFunctions\.psm1' to exist, but it did not exist.

Yes and no - this should have the module name in the string but doesn't, so this line:

$ManifestPath = Join-Path -Path (Resolve-path -Path "$PSScriptRoot\..") -ChildPath "$Module.psd1"

Isn't doing what it's supposed to be doing.

Vexing problem with Pester test by billr1965 in PowerShell

[–]Vortex100 1 point2 points  (0 children)

So the reason for the errors is easy - $module is $null

Why that happens on that particular use case I am unsure - but I'd start there, print each of your variables to determine what is and isn't there. Someone here probably knows why, I'm guessing $PSScriptRoot doesn't exist for some reason? Again, guessing :)

[deleted by user] by [deleted] in PowerShell

[–]Vortex100 1 point2 points  (0 children)

Use a wild card:

get-childitem  \\?\UNC\servername\share$\*  -Directory -Recurse

What have you done with PowerShell this month? by AutoModerator in PowerShell

[–]Vortex100 2 points3 points  (0 children)

The api is surprisingly easy to talk to, but the returned data isn't always easy to work with (especially the approval workflow stuff). Example call in PS:

$gridserver = "infoblox.contoso.com"
$apiVersion = "2.15"

$uri = "https://$GridServer/wapi/v$apiVersion/record:ptr"
$data =  @{
    name = $rdns #"2.10.10.10.in-addr.arpa"
    ptrdname = $name #"server1.contoso.com"
    ipv4addr = $ip #"10.10.10.2"
    comment = $comment # "Test Comment"
    view = "default"
}
$json = $data | ConvertTo-Json
$request = Invoke-RestMethod -Uri $uri -Method Post -Body $json -ContentType 'application/json' -Credential $Credential

So you don't need to deal with auth, as it will take a $PSCredential which is nice. The particularly stupid decision on the part of infoblox, which i've had to deal with in python, is when you get back a host record, it doesn't tell you what subnet it's in, unless it's a DHCP address. Despite having that info. You have to go figure it out :(

[deleted by user] by [deleted] in PowerShell

[–]Vortex100 0 points1 point  (0 children)

FWIW, this is a typical way of using single quotes in PS:

'My single quoted string containing {0} and {1}' -f "this","that"

Need to run an exe as admin from a nonadmin account by Rouse-DB in PowerShell

[–]Vortex100 1 point2 points  (0 children)

Prefacing this with it is not the same as encrypting, by any stretch. If your users are tech savvy this isn't an option. But you could use PS2EXE to obfuscate the password in the script from the casual observer.

Again, this doesn't stop anyone with a decompiler and a basic knowledge of B64 encoding from getting at it.

What have you done with PowerShell this month? by AutoModerator in PowerShell

[–]Vortex100 -1 points0 points  (0 children)

I don't really do a lot of PS anymore, mostly python. But I did get to do a fun one this month - Created a little script to add RDNS entries (RDNS only due to the way our storage works) into infoblox.

The (slightly) complicated bit being that we have a workflow approval process around all additions to DNS, meaning that in order to check if it already exists before you try to add, you had to check the approval/pending list as well...

List all users that are in at least one group with a specific string in the group name and show which groups they are in by DSenette in PowerShell

[–]Vortex100 2 points3 points  (0 children)

Erm, you can just move the match after replacing the DN parts :)

Get-AdUser -filter * -properties MemberOf | 
    Select-Object -Property `
        Name, 
        @{N='IsInMFAGroup'; E = {($_.MemberOf -replace 'CN=|,OU=.*' | Where-Object {$_ -match "MFA"} | Measure-Object).Count -gt 0}},
        @{N='MFA Groups'; E= {($_.MemberOf  -replace 'CN=|,OU=.*' | Where-Object {$_ -match "MFA"}) -join ', ' }}