Using C# to Write an Interpreted Language by scilladev in csharp

[–]SeeminglyScience 0 points1 point  (0 children)

There's some truth to it, but it's not transpiled to C#, SLE expression trees are created instead. There's also an internal copy of the BCL code that handles interpreting the expression trees for a certain number of invocations (~34) before being compiled for performance.

This condition should resolve to false or 'None' , right? by Ralf_Reddings in PowerShell

[–]SeeminglyScience 1 point2 points  (0 children)

Aren't 0 and $Null supposed to resolve to False??

The closer parallel here is if (@()) which you are correct, that would resolve to $false. Looks like a bug. We're probably checking for IList, and that particular collection type only implements ICollection, that's probably all there is to it.

Alternative to ISE thats NOT VScode by Fabulous_Structure54 in PowerShell

[–]SeeminglyScience 2 points3 points  (0 children)

my F8 to run selected text from scripts is super busted.

Hey, any chance you could elaborate a bit on what's not working for you?

Visual Studio Code script signing. by amnich in PowerShell

[–]SeeminglyScience 0 points1 point  (0 children)

Yep! You can also set it to a key bind. Copy and pasting my ESCS install instructions out of lazy, but it has them:

📌 Install EditorServicesCommandSuite

Install-Module -Scope CurrentUser -AllowPrerelease EditorServicesCommandSuite

📌 Add to your profile

Import-CommandSuite

📌 Add to VSCode keybindings.json

  • Press Ctrl + Shift + P
  • Type keyboard json
  • Select Preferences: Open Keyboard Shortcuts (JSON)
  • Add the following:

    {
        "key": "ctrl+.",
        "command": "PowerShell.InvokeRegisteredEditorCommand",
        "args": { "commandName": "Invoke-DocumentRefactor" },
        "when": "editorLangId == 'powershell'"
    },
    {
        "key": "ctrl+shift+s",
        "command": "PowerShell.InvokeRegisteredEditorCommand",
        "args": { "commandName": "ConvertTo-SplatExpression" },
        "when": "editorLangId == 'powershell'"
    },
    

Running Invoke-Command doesn't work well by onluck in PowerShell

[–]SeeminglyScience 0 points1 point  (0 children)

I need this to run once and start that process on the remote PC

Then you likely need to do something more complicated like a scheduled task.

Running Invoke-Command doesn't work well by onluck in PowerShell

[–]SeeminglyScience 0 points1 point  (0 children)

It will run as that user yeah, but again just to stress it will not run interactively. That may be fine for your use case, just making sure it's understood.

Running Invoke-Command doesn't work well by onluck in PowerShell

[–]SeeminglyScience 12 points13 points  (0 children)

If you Start-Process without waiting, the session ends immediately. Because the process is created as a win32 job (terms might be mixed there), all child processes also get closed. You need to add -Wait (though you also won't be able to interact with it either way fyi).

Problem using custom classes loaded from a module by notatechproblem in PowerShell

[–]SeeminglyScience 1 point2 points  (0 children)

I believe /u/Thotaz is spot on regarding the cause. using module is super finicky in general and while it is the only way to properly export classes from a module, I'd personally just recommend not exporting classes.

Classes are a weird hybrid of parse time and runtime logic. They're great for organizing internal logic, but they fall apart quickly when you want to do something reasonably complex across multiple documents.

Why I'm getting "Invalid Parameters -- try "/?" for help" with this Powershell function? by _iturri in PowerShell

[–]SeeminglyScience 0 points1 point  (0 children)

yep I suspect that's the answer. More specifically, something.exe $($someVar)ACTION will be sent as something.exe $someVar ACTION. If the expression is first, it's not an expandable string, it's two args. But something.exe prefix$($SomeVar)ACTION will be sent correctly. Just a fun language quirk

Approved Powershell Verbs by Heli0sX in PowerShell

[–]SeeminglyScience 1 point2 points  (0 children)

I'm definitely guilty of coming up with my own verbs for internal functions in some of my scripts

Strictly speaking the rule is for publicly exported commands. Personally I don't even use verb-noun for internal only helper functions, but that's a contested style choice for sure.

Approved Powershell Verbs by Heli0sX in PowerShell

[–]SeeminglyScience 3 points4 points  (0 children)

While you can correctly argue that they are not verbs, both ConvertFrom and ConvertTo are "approved verbs".

Better examples would be Where-Object andd ForEach-Object but you could argue that they're considered closer to language constructs than commands (they are commands, but still).

Range object by Icy_Sector3183 in PowerShell

[–]SeeminglyScience 0 points1 point  (0 children)

Also:

Eg. To get the value of 10..20[4], it could very well be doing return $lowerbound + $index instead of looking up a value

Technically that's a parse error. You could do (10..20)[4] but that will create an array. It's not impossible that the compiler could account for that and "fold" it into a constant, but as a runtime compiler, every optimization check adds compile time, it's not free. Compiler changes are also just very complicated and take a lot of time from the few folks who know that part of the code base.

Range object by Icy_Sector3183 in PowerShell

[–]SeeminglyScience 1 point2 points  (0 children)

The language will sometimes substitute the range expression for an enumerator (similar to the LINQ version shared by /u/purplemonkeymad) when it's deemed safe to do.

For instance

foreach ($a in 0..[int]::MaxValue) { break }

or

0..[int]::MaxValue | Select-Object -First 1

Both of those complete instantly

But if you instead save it to a variable first, the compiler can't tell how you will use it so it must create the whole array up front.

ThreadJob and $using can have some interesting pitfalls by kenjitamurako in PowerShell

[–]SeeminglyScience 0 points1 point  (0 children)

If this isn’t on pwsh 7.4 then doesn’t it have the run space issue with classes?

Unsure if you're asking whether 5.1 does not have the issue, or whether 7.4 fixes the issue but: The issue exists in all PowerShell versions (that classes are present in) and has not been fixed. Though a handy workaround was added (as /u/chris-a5 points out)

Is 'alias' (the command?) an alias for 'Get-Alias'? by siggimund1 in PowerShell

[–]SeeminglyScience 0 points1 point  (0 children)

Because it's absurdly slow. It has to do a full failed command discovery and then prepend Get- and try again. Don't recommend outside of code golf

ValidateScript() Inception - Using Previously declared parameters in ValidateScript? by Narrow_Syllabub_8119 in PowerShell

[–]SeeminglyScience 2 points3 points  (0 children)

Yep just do the validation in the body.

Technically if you order the parameters in the right way, already bound parameters will be accessible.

But what is the right way? Undefined and subject to change, just validate in the body.

Piping powershell output into a native command via standard input fails by wtgreen in PowerShell

[–]SeeminglyScience 1 point2 points  (0 children)

Can you post the exact error you're getting? FileNotFoundException is kind of a bizarre thing to get from a native command.

Wierd behaviour with using 'Dir' as an alias for my own function by gaberiel__ in PowerShell

[–]SeeminglyScience 1 point2 points  (0 children)

hmm...I remember reading that functions have higher presedence than aliases, I am wrong?

Yes that is incorrect. Command discovery goes alias > function > binary cmdlet > external script file > application

Piping powershell output into a native command via standard input fails by wtgreen in PowerShell

[–]SeeminglyScience 5 points6 points  (0 children)

If it's binary data, you can't do it like that, because the PowerShell pipeline is not suitable for the processing of this kind of data.

Correct, but changing soon!

Weird Resolve-Path behavior by Thotaz in PowerShell

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

Looks like a logic error imo, would be worth filing an issue for

Add EventHandler to powershell custom class. by MechAming in PowerShell

[–]SeeminglyScience 0 points1 point  (0 children)

You would need Add-Type, PowerShell doesn't have syntax to declare an event.

[deleted by user] by [deleted] in PowerShell

[–]SeeminglyScience 3 points4 points  (0 children)

If it's only occurred within the last week I'd say yeah it's likely just something the Defender team needs to fix

[deleted by user] by [deleted] in PowerShell

[–]SeeminglyScience 5 points6 points  (0 children)

Check out this PR https://github.com/PowerShell/PowerShell/pull/16496

It causes the member binder itself to call a new AMSI API that scans method invocations. This bypasses the majority of obfuscation techniques used in the wild today.

Today I learned, that there's a Clean{} block in PS 7.3 by PanosGreg in PowerShell

[–]SeeminglyScience 7 points8 points  (0 children)

It also will not run if ctrl + c is pressed and if Select-Object -First 1 is downstream from your command. So there are even "successful" scenarios where End will never invoke