Error with Set-VpnConnection

I’m working on a script for a client to modify a VPN connection so that it times out after 30 minutes. I can get the name of the VPN and modify it with the following.

$NAME = Get-VpnConnection | Select Name
Set-VpnConnection -Name $Name -IdleDisconnectSeconds "1800"

But I’m getting an error message, “The configuration cannot be applied to the local user VPN connection @{Name=REDACTED VPN}. : The system could not find the phone book entry for this connection.” Yet running the variable code alone DOES show the correct connection name. I’m not finding anything with a Google search.

Anyone encountered this? Any suggestions?

Chane $Name to $($name.name)

Or add an -expandproperty to your select. It is expecting a string for a name but getting a hashtable instead

The other thing you could do is add -AllUserConnection to the get.

you’re destroying you rich object and making you life harder, try

$NAME = Get-VpnConnection

you can access the sub properties using

$NAME .name
$NAME .IdleDisconnectSeconds

then you can use your rich object to configure it

$NAME | Set-VpnConnection -IdleDisconnectSeconds '1800'

what happens?

note: please check you’re not getting multiple connections, validate your input/output before setting a value

That did it! Thank you!!!

I think that part is working so the all user isnt needed (cause they get @{Name=REDACTED VPN}. as a response, their issue is the select-object that’s completely unneeded

additionally for -AllUserConnection they’d have to run it elevated (er.. for the set part)

Yeah, it all depends on how the initial connection was created if it was defined for all users or not. But a -RunAs would help the elevation, if needed.