Skip to content

CertificatePolicy obsolete in PowerShell 7.1 #4

@oleahy

Description

@oleahy

Thank you for this useful module.

We have been using it successfully with PowerShell version 5.1, but it appears that the switch -SkipCertificateCheck on the cmdlet Connect-VIMobServer does not work with powershell version 7.1

Searching online I see that ICertificatePolicy and CertificatePolicy are obsolete, https://docs.microsoft.com/en-us/dotnet/api/system.net.servicepointmanager.certificatepolicy?view=netframework-4.7.2

Is there a work around or an alternative way of using this module?

This is the error we get:

    PS /scripts> Import-Module -Name "VIPerms"
    PS /scripts> [securestring]$secStringPassword = ConvertTo-SecureString "*******" -AsPlainText -Force
    PS /scripts> [pscredential]$credObject = New-Object System.Management.Automation.PSCredential ("*****", $secStringPassword)
    PS /scripts> Connect-VIMobServer -Server "10.0.0.10" -Credential $credObject -SkipCertificateCheck
    Add-Type: /home/host/.local/share/powershell/Modules/VIPerms/0.0.6/Private/Set-CertPolicy.ps1:24
    Line |
      24 |                      Add-Type -TypeDefinition  @"
         |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | (3,56): error CS0246: The type or namespace name 'ICertificatePolicy' could not be found (are you
         | missing a using directive or an assembly reference?)                     public class
         | TrustAllCertsPolicy : ICertificatePolicy {                                                        ^

    Add-Type: /home/host/.local/share/powershell/Modules/VIPerms/0.0.6/Private/Set-CertPolicy.ps1:24
    Line |
      24 |                      Add-Type -TypeDefinition  @"
          |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          | Cannot add type. Compilation errors occurred.

The version of Powershell that fails is 7.1.0

    PS /scripts> $PSVersionTable.PSVersion
    Major  Minor  Patch  PreReleaseLabel BuildLabel
    -----  -----  -----  --------------- ----------
    7      1      0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions