I am trying to execute a powershell script to remove an AlwaysOn VPN connection from our remote PCs. When I run this script locally on a client PC it works fine. When I try to push it through SCCM it fails with the Error:
PS>TerminatingError(Remove-CimInstance): "Cannot bind argument to parameter 'InputObject' because it is null."
Remove-CimInstance : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\WINDOWS\CCM\ScriptStore\0832E36A-1D14-4D93-86AC-3B460BE63DE0_E0892DBEC4B88BA44EA0013AC972535BDDF445FF0D6F543CC3ADD
67944C526B8.ps1:5 char:33
+ Remove-CimInstance -CimInstance $CimInstance
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidData:
) [Remove-CimInstance], ParameterBindingValidationException
+ FullyQualifiedErrorId :
ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Management.Infrastructure.CimCmdlets.RemoveCimInstanceCommand
Remove-CimInstance : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\WINDOWS\CCM\ScriptStore\0832E36A-1D14-4D93-86AC-3B460BE63DE0_E0892DBEC4B88BA44EA0013AC972535BDDF445FF0D6F543CC3AD
D67944C526B8.ps1:5 char:33
+ Remove-CimInstance -CimInstance $CimInstance
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidData:
) [Remove-CimInstance], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Management.Infrastructure.CimCm
dlets.RemoveCimInstanceCommand
The script that I'm trying to run is below, hoping someone in the SCCM community has some insight.
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\output.txt -append
$CimInstance = Get-CimInstance -Namespace 'root\cimv2\mdm\dmmap' -ClassName 'MDM_VPNv2_01' -Filter "ParentID='./Vendor/MSFT/VPNv2' and InstanceID='AlwaysOn%20VPN'"
Remove-CimInstance -CimInstance $CimInstance
$BasePath = "HKLM:\SOFTWARE\Microsoft\EnterpriseResourceManager\Tracked"
$Tracked = Get-ChildItem -Path $BasePath
ForEach ($Item in $Tracked) {
$Key = Get-ChildItem $Item.PsPath -Recurse | Where-Object { $_ | Get-ItemProperty -Include "Path*" }
$PathCount = ($Key.Property -Match "Path\d+").Count
ForEach ($K in $Key) {
$Path = $K.Property | Where-Object { $_ -Match "Path\d+" }
$Count = $Path.Count
ForEach ($P in $Path) {
$Value = $K.GetValue($P)
If ($Value -Match "$('AlwaysOn%20VPN')$") {
$K | Remove-ItemProperty -Name $P
$Count--
}
}
$K | Set-ItemProperty -Name Count -Value $Count
}
}
$Path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\'
$Key = Get-Childitem -Path $Path | Where-Object { (Get-ItemPropertyValue $_.PsPath -Name Description) -eq 'AlwaysOn VPN' }
If ($Key) {
$Key | Remove-Item
}
Else {
Write-Verbose "No profiles found matching AlwaysOn VPN in the network list."
}
$Path = 'HKLM:\System\CurrentControlSet\Services\RasMan\Config\'
$Name = 'AutoTriggerDisabledProfilesList'
Try {
[string[]]$Current = Get-ItemPropertyValue -Path $Path -Name $Name -ErrorAction Stop
}
Catch {
Write-Verbose "$Name does not exist under $Path. No action required."
}
If ($Current) {
$List = [Ordered]@{}
$Current | ForEach-Object { $List.Add("$($_.ToLower())", $_) }
If ($List.Contains("AlwaysOn VPN")) {
$List.Remove("AlwaysOn VPN")
Set-ItemProperty -Path $Path -Name $Name -Value $List.Values
}
}
Else {
Write-Verbose "No profiles found matching AlwaysOn VPN."
}
Stop-Transcript
PS>TerminatingError(Remove-CimInstance): "Cannot bind argument to parameter 'InputObject' because it is null."
Remove-CimInstance : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\WINDOWS\CCM\ScriptStore\0832E36A-1D14-4D93-86AC-3B460BE63DE0_E0892DBEC4B88BA44EA0013AC972535BDDF445FF0D6F543CC3ADD
67944C526B8.ps1:5 char:33
+ Remove-CimInstance -CimInstance $CimInstance
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidData:
+ FullyQualifiedErrorId :
ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Management.Infrastructure.CimCmdlets.RemoveCimInstanceCommand
Remove-CimInstance : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\WINDOWS\CCM\ScriptStore\0832E36A-1D14-4D93-86AC-3B460BE63DE0_E0892DBEC4B88BA44EA0013AC972535BDDF445FF0D6F543CC3AD
D67944C526B8.ps1:5 char:33
+ Remove-CimInstance -CimInstance $CimInstance
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidData:
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Management.Infrastructure.CimCm
dlets.RemoveCimInstanceCommand
The script that I'm trying to run is below, hoping someone in the SCCM community has some insight.
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\output.txt -append
$CimInstance = Get-CimInstance -Namespace 'root\cimv2\mdm\dmmap' -ClassName 'MDM_VPNv2_01' -Filter "ParentID='./Vendor/MSFT/VPNv2' and InstanceID='AlwaysOn%20VPN'"
Remove-CimInstance -CimInstance $CimInstance
$BasePath = "HKLM:\SOFTWARE\Microsoft\EnterpriseResourceManager\Tracked"
$Tracked = Get-ChildItem -Path $BasePath
ForEach ($Item in $Tracked) {
$Key = Get-ChildItem $Item.PsPath -Recurse | Where-Object { $_ | Get-ItemProperty -Include "Path*" }
$PathCount = ($Key.Property -Match "Path\d+").Count
ForEach ($K in $Key) {
$Path = $K.Property | Where-Object { $_ -Match "Path\d+" }
$Count = $Path.Count
ForEach ($P in $Path) {
$Value = $K.GetValue($P)
If ($Value -Match "$('AlwaysOn%20VPN')$") {
$K | Remove-ItemProperty -Name $P
$Count--
}
}
$K | Set-ItemProperty -Name Count -Value $Count
}
}
$Path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\'
$Key = Get-Childitem -Path $Path | Where-Object { (Get-ItemPropertyValue $_.PsPath -Name Description) -eq 'AlwaysOn VPN' }
If ($Key) {
$Key | Remove-Item
}
Else {
Write-Verbose "No profiles found matching AlwaysOn VPN in the network list."
}
$Path = 'HKLM:\System\CurrentControlSet\Services\RasMan\Config\'
$Name = 'AutoTriggerDisabledProfilesList'
Try {
[string[]]$Current = Get-ItemPropertyValue -Path $Path -Name $Name -ErrorAction Stop
}
Catch {
Write-Verbose "$Name does not exist under $Path. No action required."
}
If ($Current) {
$List = [Ordered]@{}
$Current | ForEach-Object { $List.Add("$($_.ToLower())", $_) }
If ($List.Contains("AlwaysOn VPN")) {
$List.Remove("AlwaysOn VPN")
Set-ItemProperty -Path $Path -Name $Name -Value $List.Values
}
}
Else {
Write-Verbose "No profiles found matching AlwaysOn VPN."
}
Stop-Transcript