Tagged: DFS

Your Online/Offline state for a offline files enabled share

Want to know the online/offline state of a DFS-share that is in your offline files?

There is a WMI class called Win32_OfflineFilesConnectionInfo that you can use. Of course it’s not as easy as just querying that one…

You can do it one one compressed line…

((Get-WmiObject Win32_OfflineFilesItem -Filter "ItemType = 2 AND ItemPath = '\\\\SNOWLAND.SE\\MyRoot'").ConnectionInfo).ConnectState

Or a bit more elegant with a function…

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
	}
}

Get-DfsRootConnectionState -rootName "\\SNOWLAND.SE\MyRoot" -asText