Powershell version

Comments

2 comments

  • Colby Bouma

    Not directly. PDQ Deploy and Inventory are built with .NET Framework, which can't tie into .NET Core things like PowerShell Core. PDQ would have to do a lot of work to add a native PS Core option.

    However, you can create a PowerShell Scanner that runs pwsh.exe. It's a bit of a kludge, but it seems to work. It would probably break if your script returns something that exists in PS Core, but not Windows PowerShell though. I created a proof of concept:

    Here's the contents of my Script field:

    pwsh -File '.\PS Core Test.ps1'
    [PSCustomObject](Import-CliXml -Path '.\Output.xml')

    Here's the contents of "PS Core Test.ps1":

    #Requires -Version 7
    $PSVersionTable | Export-Clixml -Path '.\Output.xml'

    0
    Comment actions Permalink
  • Colby Bouma

    I did some more experimentation and found a potentially cleaner way to do it.

    Execute PS Core.ps1

    param (
    [Parameter(Mandatory = "True")]
    [String]$FileName
    )

    $Contents = Get-Content -Path $FileName -Raw
    $ScriptBlock = [ScriptBlock]::Create($Contents)

    # "pwsh -File" outputs an array of strings. Boo!
    # "pwsh -Command [String]" outputs an array of strings too. Boo!
    # "pwsh -Command [ScriptBlock]" outputs the actual object(s) that pwsh returned. I have no idea why it's this way, but yay!
    pwsh -Command $ScriptBlock

    PS Core Test 3.ps1

    #Requires -Version 7
    [PSCustomObject]$PSVersionTable

    0
    Comment actions Permalink

Please sign in to leave a comment.