PowerShell Script para crear una conexión VPN para todos los usuarios

PowerShell Script para crear una conexión VPN para todos los usuarios

Tengo el siguiente script de PowerShell que crea una conexión VPN y un acceso directo en el escritorio a Rasphone.

#
# Powershell script to create a client VPN connection to a Meraki MX.
#
# Configuration Parameters
$ProfileName = 'P*** VPN'
$DnsSuffix = 'int.nomoist.net'
$ServerAddress = 'cisco-******-*****rdvvm.dynamic-m.com'
$L2tpPsk = 'Mypassword'

#
# Build client VPN profile
# https://docs.microsoft.com/en-us/windows/client-management/mdm/vpnv2-csp
#

# Define VPN Profile XML
$ProfileNameEscaped = $ProfileName -replace ' ', '%20'
$ProfileXML =
    '<VPNProfile>
        <RememberCredentials>false</RememberCredentials>
        <DnsSuffix>'+$dnsSuffix+'</DnsSuffix>
        <NativeProfile>
            <Servers>' + $ServerAddress + '</Servers>
            <RoutingPolicyType>SplitTunnel</RoutingPolicyType>
            <NativeProtocolType>l2tp</NativeProtocolType>
            <L2tpPsk>'+$L2tpPsk+'</L2tpPsk>
        </NativeProfile>
'

# Routes to include in the VPN
$ProfileXML += "  <Route><Address>10.69.11.0</Address><PrefixSize>24</PrefixSize><ExclusionRoute>false</ExclusionRoute></Route>`n"

$ProfileXML += '</VPNProfile>'

# Convert ProfileXML to Escaped Format
$ProfileXML = $ProfileXML -replace '<', '&lt;'
$ProfileXML = $ProfileXML -replace '>', '&gt;'
$ProfileXML = $ProfileXML -replace '"', '&quot;'

# Define WMI-to-CSP Bridge Properties
$nodeCSPURI = './Vendor/MSFT/VPNv2'
$namespaceName = 'root\cimv2\mdm\dmmap'
$className = 'MDM_VPNv2_01'

# Define WMI Session
$session = New-CimSession

# Detect and Delete Previous VPN Profile
try
{
    $deleteInstances = $session.EnumerateInstances($namespaceName, $className, $options)
    foreach ($deleteInstance in $deleteInstances)
    {
        $InstanceId = $deleteInstance.InstanceID
        if ("$InstanceId" -eq "$ProfileNameEscaped")
        {           $session.DeleteInstance($namespaceName, $deleteInstance, $options)
            Write-Host "Removed '$ProfileName' profile"
        }
    }
}
catch [Exception]
{
    Write-Host "Unable to remove existing outdated instance(s) of $ProfileName profile: $_"
    exit
}

#
# Create VPN Profile
#

try
{
    $newInstance = New-Object Microsoft.Management.Infrastructure.CimInstance $className, $namespaceName
    $property = [Microsoft.Management.Infrastructure.CimProperty]::Create('ParentID', "$nodeCSPURI", 'String', 'Key')
    $newInstance.CimInstanceProperties.Add($property)
    $property = [Microsoft.Management.Infrastructure.CimProperty]::Create('InstanceID', "$ProfileNameEscaped", 'String', 'Key')
    $newInstance.CimInstanceProperties.Add($property)
    $property = [Microsoft.Management.Infrastructure.CimProperty]::Create('ProfileXML', "$ProfileXML", 'String', 'Property')
    $newInstance.CimInstanceProperties.Add($property)

    $session.CreateInstance($namespaceName, $newInstance, $options) | Out-Null
    Write-Host "Created '$ProfileName' profile."
}
catch [Exception]
{
    Write-Host "Unable to create $ProfileName profile: $_"
    exit
}

# Create a desktop shortcut
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut("$env:Public\Desktop\Polygon VPN.lnk")
$ShortCut.IconLocation = "C:\WINDOWS\system32\SHELL32.dll, 135"
$Shortcut.TargetPath = "rasphone.exe"
$Shortcut.Save()

El problema es que cuando lo ejecuto, crea el acceso directo para todos los usuarios, pero el perfil de VPN sólo se crea para la sesión actual. Me gustaría que se creara este perfil de VPN para todos los usuarios.

Gracias.

información relacionada