Open ImportTaste opened 1 year ago
@damienvanrobaeys Should this be closed too?
As a note from my side: I think it would be smarter not to block powershell 7 but rather adjust the scripts to use both. For get-wmitobject the get-ciminstance cmdlet could be used instead, they are quite interchangeable. Regarding the checkpoint-computer cmdlet maybe check if the script is run in powershell >=7 or >=5
if($IsCoreCLR) {
# im running in pwsh
}
else {
# running in windows powershell
}
should do the trick for cases where there is no equivalent cmdlet for newer versions of powershell and then give a notification to the user
I mean, sure, but this would be a good stopgap until that's sorted out.
@damienvanrobaeys How about running Checkpoint-Computer by directly calling powershell.exe
and then checking the error code? That would give it compatibility with pwsh.
Imo this is quite a smart idea, could you implement that?
Unfortunately it wont change the fact, that get-wmiobject is not available in pwsh, so we would still need a workaround for that, but i could try to implement that and make a separate pr for it
I'm working on it to run checkpoint-computer using powershell if currently running in pwsh
Solved this with this:
$Checkpoint_Command = 'Checkpoint-Computer -Description "Windows_Sandbox_Context_menus" -RestorePointType "MODIFY_SETTINGS" -ErrorAction Stop'
$retValue = Start-Process powershell -WindowStyle Hidden -ArgumentList $Checkpoint_Command -wait -PassThru
If($retValue.ExitCode -eq 0)
{
Write_Log -Message_Type "SUCCESS" -Message "Creation of restore point "Add Windows Sandbox Context menus
""
}
Else
{
Write_Log -Message_Type "ERROR" -Message "Creation of restore point "Add Windows Sandbox Context menus
""
}
Why the hassle with if/else? Just use try/catch and you dont need a separate variable for the whole command
Imo this is quite a smart idea, could you implement that?
Unfortunately it wont change the fact, that get-wmiobject is not available in pwsh, so we would still need a workaround for that, but i could try to implement that and make a separate pr for it
There shouldn't be anything that Get-WmiObject can do that Get-CIMInstance can't, to my knowledge, and Get-CIMInstance is compatible with both.
Ye, that is true. So i guess try/catch for checkpoint-computer and get-ciminstance should make this compatible with pwsh and remain it with powershell
I updated add_structure.ps1 with checkpoint-computer running with start-process powershell for al versions
I ran Add-Structures.ps1 on PowerShell 7 without knowing any better, which doesn't offer the
Get-WmiObject
orCheckpoint-Computer
commands.#Requires -PSEdition Desktop
will prevent PowerShell 7 from running these scripts since it will require the Windows-specific version of PowerShell: 5.1