Getting error while checking network shared connection state RRS feed

  • Question

  • Hello

    I am using following code to checking the connection state of network shared drive. I tested in workoline, workoffline and without network.

    It is always showing as "Offline - Net disconnected" with following error. Please let me know what I am missing

    Get-WmiObject :
    At C:\Scripts\testConnection.ps1:10 char:13
    +     $root = Get-WmiObject Win32_OfflineFilesItem -Filter "ItemType =  ...
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-WmiObject], FileNotFoundE
        + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerS

    Function Get-DfsRootConnectionState {
        PARAM (
            [string] $rootName,
            [switch] $asText
        $ConnectStates = @("Unknown", "Offline", "Online")
        $OfflineReasons = @("Unknown", "Not applicable", "Working offline", "Slow connection", "Net disconnected", "Need to sync item", "Item suspended")
        $rootName = $rootName.Replace("\", "\\")
        $root = Get-WmiObject Win32_OfflineFilesItem -Filter "ItemType = 2 AND ItemPath = '$($rootName)'"
        $stateAsText = "$($ConnectStates[$root.ConnectionInfo.ConnectState]) - $($OfflineReasons[$root.ConnectionInfo.OfflineReason])"
        Write-Verbose $stateAsText
        If ($asText) {
            Return $stateAsText
        } else {
            Return $root.ConnectionInfo.ConnectState
    $state=Get-DfsRootConnectionState -rootName \\fserver1\username$\home -asText
    Write-Host $state

    • Edited by Avian123 Tuesday, March 21, 2017 9:30 AM
    Tuesday, March 21, 2017 8:01 AM


All replies

  • It is working if I test for root level folder as \\fserver1\username$, but if I test for \\fserver1\username$\home, it throws the error.

    It seems there is no other way to check offline subfolders or is there any other way to check if subfolder is online or offline?

    As per my understanding, if folders or shared folders offline, it will be online for all subfolders and underneath contents. Please correct if I am wrong, if that is the way then we should only check if root level folder state, if it is offline then everything will be offline.


    • Edited by Avian123 Tuesday, March 21, 2017 9:33 AM
    Tuesday, March 21, 2017 9:29 AM
  • You would need to use the DFS utilities to do this.


    • Marked as answer by Avian123 Tuesday, March 21, 2017 2:03 PM
    Tuesday, March 21, 2017 10:03 AM
  • Thanks jrv.
    Tuesday, March 21, 2017 2:03 PM
  • Muhammad,

    Don't understand what you are trying to say?


    Tuesday, March 21, 2017 2:05 PM