首页 > 解决方案 > 通过 Intune 使用 PScript 删除-VpnConnection

问题描述

我正在努力从 Endpoint Managed Windows 10 机器中删除未知的 VPN 配置。

最终用户没有本地管理员凭据。当我在登录用户上下文中运行脚本时,它会失败,因为他们无权删除 VPN 配置。当我将它作为系统运行时,脚本找不到任何配置。

是否可以像您很久以前那样以具有提升权限的用户身份临时运行脚本?

如果 UAC 是原因并且无法做到这一点,如何从没有本地管理员权限的用户远程删除未知 VPN 配置,而不将它们添加到本地管理员组,运行脚本,然后删除他们的权限?

这是脚本。

# Check to see what VPN connections exist on the computer, compare the names to a desired list of connections, and remove those not on the list
################################
# VARIABLES
$tempA = Get-VpnConnection -AllUserConnection # Retrieve all VPN Connections
$tempB = Get-VpnConnection # Retrieve all VPN Connections
$VPNConfigs = ("VPN_CONFIG_1","VPN_CONFIG_1","VPN_CONFIG_1","VPN_CONFIG_1") # The Configs that should stay
################################
foreach ($item in $tempA) {
    If (!$VPNConfigs.Contains($item.Name))
    {
        Remove-VPNConnection -Name $item.Name -AllUserConnection -AsJob -Force
    }
    Else
    {   
        End
    }
}
foreach ($item in $tempB) {
    If (!$VPNConfigs.Contains($item.Name))
    {
        Remove-VPNConnection -Name $item.Name -AsJob -Force
    }
    Else
    {   
        Exit
    }
}

谢谢

标签: powershellwindows-10vpnintune

解决方案


推荐阅读