Powershell version
Is it possible to specify what version of Powershell the scanners use? iow, Can I specify that client systems run the scanner using Powershell Core (7.x) as opposed to the built-in powershell 5.x?
-
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' -
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 $ScriptBlockPS Core Test 3.ps1
#Requires -Version 7
[PSCustomObject]$PSVersionTable
Please sign in to leave a comment.
Comments
2 comments