I have part of the script here:
$DotNET6_Installed = ((Get-Package -Name 'Microsoft .NET SDK 6*' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty 'Name').Replace('Microsoft .NET SDK ', '')).Replace(' (x64)', '')
$DotNET8_Installed = ((Get-Package -Name 'Microsoft .NET SDK 8*' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty 'Name').Replace('Microsoft .NET SDK ', '')).Replace(' (x64)', '')
I wish to add -ErrorAction SilentlyContinue so that I won’t get the following errors:
You cannot call a method on a null-valued expression.
At line:20 char:1
+ $DotNET6_Installed = ((Get-Package -Name 'Microsoft .NET SDK 6*' -Err ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:22 char:1
+ $DotNET8_Installed = ((Get-Package -Name 'Microsoft .NET SDK 8*' -Err ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
But I have no idea where to add the -ErrorAction to…
I just want to hide those errors.