Add-VpnConnection script works on co-worker's PC but not mine

Hello all! I’m fairly new to PowerShell and a co-worker of mine has been working on automating VPN setup. He created a few commands that work like a charm on every machine they are run on except mine. I did some research and based on the error I am getting I rebuilt my WMI index but that didn’t help. Really lost and would love any help you can give me! Code and errors are below. Thank you!

Troublesome code:

add-vpnconnection -Name TestVPN -ServerAddress 10.10.10.10 -Tunneltype “L2tp” -L2tpPsk ‘t3stk3y’ -AuthenticationMethod “PAP” -AllUserConnection -Force

Error I keep getting:

add-vpnconnection : Invalid class
At line:1 char:1

  • add-vpnconnection -Name TestVPN -ServerAddress 10.10.10.10 -Tunneltyp …
  •   + CategoryInfo          : MetadataError: (PS_VpnConnection:root/Microsoft/...S_VpnConnection) [Add-VpnConnection],
      CimException
      + FullyQualifiedErrorId : HRESULT 0x80041010,Add-VpnConnection

Hi, welcome to the forum :wave:

This doesn’t sound like a PowerShell problem and I think you’re right about it being a problem with the WMI database.

You can use your favourite search engine to find various techniques for fixing the WMI database but in my experience, particularly in a corporate environment, it will be quicker and easier (and in the long run, more reliable) to re-image your machine.

1 Like

What version is your operating system?