Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    PowerShell Connect
    @PoshConnect_twitter
    chrisdent (discord) obviously your runspace disagrees with this assessment
    PowerShell Connect
    @PoshConnect_twitter
    Carl (discord) What is the difference between InitialSessionState.CreateDefault2(); and InitialSessionState.CreateDefault(); ?
    Carl (discord) the latter is able to import "Microsoft.PowerShell.Utility". Next it is able to run the import-module statement against your module, but it does not yield the imported module given -passthru
    chrisdent (discord) CreateDefault2 has less clutter in it. It's generally better for more modern things
    PowerShell Connect
    @PoshConnect_twitter
    PowerShell Connect
    @PoshConnect_twitter
    Carl (discord) var posh = PowerShell.Create();
    var result = posh.AddScript(@"import-module ""...\Documents\PowerShell\Modules\Indented.ScriptAnalyzerRules\1.1.0\Indented.ScriptAnalyzerRules.psm1"" -PassThru").Invoke();
    works (edited)
    Carl (discord) and var posh = PowerShell.Create(InitialSessionState.CreateDefault2());
    var result = posh.AddScript(@"import-module ""...\Documents\PowerShell\Modules\Indented.ScriptAnalyzerRules\1.1.0\Indented.ScriptAnalyzerRules.psm1"" -PassThru").Invoke();
    works. (edited)
    PowerShell Connect
    @PoshConnect_twitter
    Carl (discord) So the issue is with the AddCommand method? I am using the master branch. Maybe there is some incompatibility. Don't know which PowerShell version gets loaded.
    Carl (discord) o no...... Now suddenly AddCommand also just works
    PowerShell Connect
    @PoshConnect_twitter
    Carl (discord) So maybe there is some additional runspace context that I have permanently set to unrestricted?
    Carl (discord) there you go........ where is this execution policy setting living?
    PowerShell Connect
    @PoshConnect_twitter

    Carl (discord) cmd> C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

    powershell32-bit> Get-ExecutionPolicy -list

        Scope ExecutionPolicy
        ----- ---------------

    MachinePolicy Undefined
    UserPolicy Undefined
    Process Undefined
    CurrentUser Undefined
    LocalMachine Unrestricted

    Carl (discord) got it.......
    PowerShell Connect
    @PoshConnect_twitter
    Carl (discord) how can I enforce loading the 64-bit version of PowerShell?
    PowerShell Connect
    @PoshConnect_twitter
    seeminglyscience (discord) vscode? or just normal terminal? if the former the easiest is to make sure you have the 64bit version of vscode installed and check that the settings aren't explicitly calling the 32bit version. If the latter, you can't really other than just making sure you open the right one
    PowerShell Connect
    @PoshConnect_twitter
    Carl (discord) @seeminglyscience I am using PowerShell.Create() from a 64-bit .NET app and still it is picking the 32-bit powerShell.
    PowerShell Connect
    @PoshConnect_twitter
    seeminglyscience (discord) PowerShell.Create doesn't call powershell.exe. It doesn't launch a new process at all, it's the bitness that it is in your app. Check your environment variables, that's more likely the issue
    PowerShell Connect
    @PoshConnect_twitter
    Carl (discord) Yeah I was wrong. I see now that the PowerShell process is 64-bit. But where is it taking the execution policy from? I see that the PowerShell version is equal to the nuget package I am using, i.e. 7.0.6 (the latest with netcore 3.1 support).
    seeminglyscience (discord) just to be 100% clear, there's no PowerShell process involved. It's load the libraries directly into the same process. But you can just do ps.AddCommand("Set-ExecutionPolicy").AddParameter(etc)
    seeminglyscience (discord) just set the scope to process
    PowerShell Connect
    @PoshConnect_twitter
    Carl (discord) Any clue where the local machine scoped execution policy gets persisted? I discovered that there are at least for different "local machine" locations: PowerShell 64-bit 5.1, PowerShell 7+, PowerShell 32-bit 5.1 and... At least one for the .NET app hosted PowerShell runspace. In the registry I see maybe all of them. The latter would then be "ScriptedDiagnostics" (when I am at my laptop I will check the exact name); have to play with it.
    PowerShell Connect
    @PoshConnect_twitter
    Carl (discord) Ok just checked the source code, it is stored into powershell.config.json for the systemwide install. but where are the settings for the dotnet app hosted version? Answer: ConsoleApp1\bin\Debug\netcoreapp3.1\runtimes\win\lib\netcoreapp3.1 (edited)
    PowerShell Connect
    @PoshConnect_twitter
    PowerShell Connect
    @PoshConnect_twitter
    Carl (discord) I guess so. This initial session state gets deserialized from this powershell.config.json file for the local machine scoped setting.
    PowerShell Connect
    @PoshConnect_twitter
    jkavanagh58 (slack) splatting it does not work for me, still throws system.exception on the customrulepath😡
    PowerShell Connect
    @PoshConnect_twitter
    Jaykul (discord) Does anyone have a script analyzer rule that forces language keywords to be lowercase? (edited)
    PowerShell Connect
    @PoshConnect_twitter
    PowerShell Connect
    @PoshConnect_twitter
    Jaykul (discord) Hmm, that would have helped, yea.
    Jaykul (discord) I half wrote a C# version to submit to the ScriptAnalyzer repo
    Jaykul (discord) I'm trying to decide if I should get carried away and do variable case too (edited)
    PowerShell Connect
    @PoshConnect_twitter
    pwshaddict (discord) Anyone know of a way to use script analyzer on inline code within a YML file?
    PowerShell Connect
    @PoshConnect_twitter
    chrisdent (discord) you'd have to extract it from the yaml doc. It needs to be possible to parse it using AST, that's impossible as long as it has yaml around it
    PowerShell Connect
    @PoshConnect_twitter
    pwshdoodUK (slack) this is 1 if many reasons why I will not use inline script tasks in any of my pipelines, you loose too much functionality in tooling no matter how simple the inline script is
    PowerShell Connect
    @PoshConnect_twitter
    pwshaddict (discord) I'm trying to talk the team into not using inline scripts.
    PowerShell Connect
    @PoshConnect_twitter
    PowerShell Connect
    @PoshConnect_twitter
    seeminglyscience (discord) you'd first need a yaml language service that can tell when a string is a powershell script
    PowerShell Connect
    @PoshConnect_twitter

    pwshaddict (discord) So next question would be how to run tests against the code? Sounds more complicated than it needs to be.

    I really wanna push for only using inline code for very basic stuff. If more than X number of lines, maybe we should make it a script or part of a custom module. (edited)

    PowerShell Connect
    @PoshConnect_twitter
    pwshaddict (discord) I'd also need this to run in a pipeline. 😦
    PowerShell Connect
    @PoshConnect_twitter
    chrisdent (discord) Get a yaml parser; Extract the script block from the yaml doc; use Invoke-ScriptAnalyzer -ScriptDefinition.
    chrisdent (discord) you've got to get it out of the yaml doc. ScriptAnalyzer cannot do that part for you.
    PowerShell Connect
    @PoshConnect_twitter
    pwshdoodUK (slack) but that's extra pain that you can get rid of by not using them in the first place
    PowerShell Connect
    @PoshConnect_twitter
    pwshaddict (discord) I like trying to not over complicate things. I cannot find a valid reason why you MUST use inline pwsh.
    chrisdent (discord) for all my inline PS I have it run minimal commands which install / use modules I've written. Those, ofc, can be properly tested
    PowerShell Connect
    @PoshConnect_twitter
    jkavanagh58 (slack) 1.20 is out, customrule path still throws a system.exception
    PowerShell Connect
    @PoshConnect_twitter
    c.bergmeister (slack) Can you point me to the github issue please?
    PowerShell Connect
    @PoshConnect_twitter
    jkavanagh58 (slack) Will do sir. I will submit one sir.
    mcgurdan
    @mcgurdan
    Hi just wondering if there is a good way to test the performance of new rules? I write quite a few and would love to know a way I can stress test the performance impact in VSCode along with some potential best practices to keep utilisation to a minimum. Thanks!
    PowerShell Connect
    @PoshConnect_twitter
    ninmonkey (discord) You could try this module https://github.com/StartAutomating/Benchpress
    PowerShell Connect
    @PoshConnect_twitter
    c.bergmeister (slack) running just that rule will isolate any noise, you will only be left with some overhead to initialize PSSA (which always takes longer the first time). custom rules are run serially so no multi-threading complexity. I suggest to test it how the rule scales with the size of the script. I myself like to use PowerShell's build module as a realistic test case:
    https://github.com/PowerShell/PowerShell/blob/master/build.psm1