I want to port an existing PowerShell script written in PowerShell 5.1 to PowerShell 7.1. However it seems I can't create objects of type [Windows.Security.Credentials.PasswordCredential] as the type can not be found.
Having a look at the registry tells me this class is stored at the following locations:
- C:\Windows\System32\vaultcli.dll
- C:\Windows\SysWOW64\vaultcli.dll
But adding these DLLs to my script in PS 7.1 fails:
PS C:\Users\xxx> Add-Type -Path "C:\Windows\System32\vaultcli.dll"
Add-Type: Bad IL format. The format of the file 'C:\Windows\System32\vaultcli.dll' is invalid.
PS C:\Users\xxx> Add-Type -Path "C:\Windows\SysWOW64\vaultcli.dll"
Add-Type: Bad IL format. The format of the file 'C:\Windows\SysWOW64\vaultcli.dll' is invalid.
Checking the related codebase parameter in PowerShell 5.1 returns the following:
PS C:\Users\xxx> [Windows.Security.Credentials.PasswordVault].Assembly.CodeBase
file:///C:/WINDOWS/system32/WinMetadata/Windows.Security.winmd
How can I correctly add a reference to this type?