let say I want to check if a specific os customization spec exist
if ((Get-OSCustomizationSpec –Name “Win2016 Spec”) -eq $null){
write-host "It does not exist"
}
Even though the logic work, everytime I run it, where the entry does not exist, it will also output the ugly error
Get-OSCustomizationSpec : 12/3/2020 8:49:40 PM Get-OSCustomizationSpec Could not find Customization Specification with name
'Win2016 Spec'.
At D:\VMware\WindowsVM.ps1:86 char:6
+ if ((Get-OSCustomizationSpec –Name “Win2016 Spec”) -eq $null){
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Win2016 Spec:String) [Get-OSCustomizationSpec], VimException
+ FullyQualifiedErrorId : Common_CommonUtil_FilterCollection_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.
GetOSCustomizationSpec
It does not exist
How do i rewrite the code so it does show the error output?
You can use the ErrorAction parameter for that.
if ((Get-OSCustomizationSpec –Name “Win2016 Spec” -ErrorAction SilentlyContinue) -eq $null){
write-host "It does not exist"
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can use the ErrorAction parameter for that.
if ((Get-OSCustomizationSpec –Name “Win2016 Spec” -ErrorAction SilentlyContinue) -eq $null){
write-host "It does not exist"
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you again. Worked like a champ