# Test-NetConnection "Cannot connect to CIM server. Access denied "

**URL:** <https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828>\
**Category:** PowerShell Help\
**Created:** [October 3, 2024, 9:37am UTC](https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828 "2024-10-03T09:37:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pj483](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@pj483](https://forums.powershell.org/u/pj483)\
**Post date:** [October 3, 2024, 9:37am UTC](https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828/1 "2024-10-03T09:37:19Z")

</div>

I have a script that includes “Test-NetConnection” to see if a server is responding. For some users I’m getting the error:

```auto
PS>TerminatingError(Find-NetRoute): "Cannot connect to CIM server. Access denied "

```

When this occurs, the result returned from “Test-NetConnection” is of the form:

```auto
ComputerName : ***
RemoteAddress : xxx.xxx.xxx.xxx
InterfaceAlias :
SourceAddress :
PingSucceeded : True
PingReplyDetails (RTT) : 3 ms

```

Note that the “InterfaceAlias” and “SourceAddress” are empty. When the “Test-NetConnection” is successful, these are populated:

```auto
ComputerName : ***
RemoteAddress : xxx.xxx.xxx.xxx
InterfaceAlias : Ethernet
SourceAddress : xxx.xxx.xxx.xxx
PingSucceeded : True
PingReplyDetails (RTT) : 3 ms

```

Any ideas on this error or how can I suppress it, given that I’m only interested in the “PingSucceeded” value? I’ve tried:

```auto
-ErrorAction SilentlyContinue -WarningAction SilentlyContinue

```

as well as including the call in a “try{} catch{}”. Neither of these work and the error still gets displayed.

Thanks.

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [October 3, 2024, 2:42pm UTC](https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828/2 "2024-10-03T14:42:38Z")

</div>

Can you provide your code or at least the failing code? Make sure to format with the ‘\</\>’ button

---

<div class="post-metadata">

**Author:** ![pj483](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@pj483](https://forums.powershell.org/u/pj483)\
**Post date:** [October 3, 2024, 2:54pm UTC](https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828/3 "2024-10-03T14:54:28Z")

</div>

It’s pretty much as per the extracts above, but specifically:

```auto
$up = Test-NetConnection -ComputerName *** -ErrorAction SilentlyContinue -WarningAction SilentlyContinue

```

---

<div class="post-metadata">

**Author:** ![psdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/psdarwin/32/2063_2.png) [@psdarwin](https://forums.powershell.org/u/psdarwin)\
**Post date:** [October 3, 2024, 3:17pm UTC](https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828/4 "2024-10-03T15:17:32Z")

</div>

If you are only looking for ICMP (ping) response, you might consider using test-connection instead of test-netconnection.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [October 3, 2024, 3:38pm UTC](https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828/5 "2024-10-03T15:38:16Z")

</div>

Since the error shows `Find-NetRoute`, it’s probably not being thrown by `Test-NetConnection`. I’d set the `$ErrorActionPreference` for the session to Stop and put it in a try/catch.

```auto
$ErrorActionPreference = 'Stop'

try{
    $up = Test-NetConnection -ComputerName ***
}
catch{
    # Write-Warning $_.Exception.Message
}

```

---

<div class="post-metadata">

**Author:** ![pj483](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@pj483](https://forums.powershell.org/u/pj483)\
**Post date:** [October 4, 2024, 10:08am UTC](https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828/6 "2024-10-04T10:08:47Z")

</div>

I gave this a try and now I get:

```auto
At script.ps1:251 char:8
+ $up = Test-Connection -ComputerName $controllers -Quiet
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [Test-Connection], ManagementException
    + FullyQualifiedErrorId : TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand

```

The “controllers” variable is defined as:

```auto
[string[]]$controllers = @("xxx")

```

Works fine when **I** run it but doesn’t work for the account that’s running the script.

---

<div class="post-metadata">

**Author:** ![pj483](https://avatars.discourse-cdn.com/v4/letter/p/7feea3/32.png) [@pj483](https://forums.powershell.org/u/pj483)\
**Post date:** [October 4, 2024, 10:09am UTC](https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828/7 "2024-10-04T10:09:12Z")

</div>

Gave this a try and still get the same error.

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [October 4, 2024, 12:13pm UTC](https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828/8 "2024-10-04T12:13:47Z")

</div>

Sounds like you have some security control in place that prevents execution on the other account. Can the other account just run the command from a prompt but not a script?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 3, 2024, 12:14pm UTC](https://forums.powershell.org/t/test-netconnection-cannot-connect-to-cim-server-access-denied/24828/9 "2024-11-03T12:14:33Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
