Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

PENDING Error When Running PS Script Through SCCM but Not When Running Locally

  • Thread starter Thread starter vargatron
  • Start date Start date
  • Replies Replies 3
  • Views Views 3K

vargatron

New Member
Messages
2
Reaction score
0
Points
1
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
 
Thanks for the response.
Yes. I have actually tried running it as a package. The original deployment of the AOVPN connection was as a package and I used the System account for that. So when I tried to deploy the Remove AOVPN connection I originally tried it as a package but I get the same results as when i run it as a script. Also, when I run it locally I run it under the context of my personal admin account and it works fine.
 
But have you manually run your script as local system to see what errors are listed?
 

Forum statistics

Threads
7,171
Messages
27,990
Members
18,297
Latest member
Kahnrym

Trending content

Back
Top