Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FUNCTION DfsrInfo
- {
- PARAM(
- [Parameter(Mandatory = $true, Position = 0)]
- [string]$ComputerName
- )
- BEGIN
- {
- # Test if we can connect to the machine
- $ComputerName = $ComputerName.ToUpper()
- $ConnectionResult = Test-Connection -ComputerName $ComputerName -Count 2 -ErrorVariable ConnectionError -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
- IF($ConnectionError){ Write-Error "Unable to communicate with $ComputerName" }
- IF(-not $ConnectionError){
- # If we can talk to it, test to see if it has DFS on it
- $DfsExists = Get-WmiObject -ComputerName $ComputerName -Namespace 'root\MicrosoftDFS' -Query 'SELECT * FROM DfsrReplicationGroupConfig' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
- # Set variables accordingly
- IF (-not $DfsExists){ Write-Error "Unable to locate WMI Namespace 'root\MicrosoftDFS' on $ComputerName" }
- IF ($DfsExists){ $GoAhead = $true }
- }
- }
- PROCESS
- {
- # If we can talk to the machine and it has DFS on it, begin here
- IF ($GoAhead -eq $true)
- {
- $Groups = Get-WmiObject -ComputerName $ComputerName -Namespace 'root\MicrosoftDFS' -Query 'SELECT * FROM DfsrReplicationGroupConfig'
- $Folders = Get-WmiObject -ComputerName $ComputerName -Namespace 'root\MicrosoftDFS' -Query 'SELECT * FROM DfsrReplicatedFolderConfig'
- $Connections = Get-WmiObject -ComputerName $ComputerName -Namespace 'root\MicrosoftDFS' -Query 'SELECT * FROM DfsrConnectionConfig'
- FOREACH($ReplicationGroup in $Groups)
- {
- ##
- # Create object for replication group
- $PropertiesToLocate = @(
- 'To'
- 'From'
- 'ReplicationGroupName'
- 'ReplicatedFolderName'
- 'DfsrState'
- 'DfsrBacklog'
- 'DfsrBacklogFiles'
- )
- ##
- ## Create Empty Properties, for each of the Properties above
- $OutObj = New-Object PsObject
- FOREACH ($p in $PropertiesToLocate){ $OutObj | Add-Member -MemberType NoteProperty -Name $p -Value 'nullvalue' }
- ##
- FOREACH($ReplicatedFolder in $Folders)
- {
- FOREACH($ReplicationConnection in $Connections)
- {
- IF (($ReplicationGroup.ReplicationGroupGuid -eq $ReplicatedFolder.ReplicationGroupGuid) -and ($ReplicationGroup.ReplicationGroupGuid -eq $ReplicationConnection.ReplicationGroupGuid))
- {
- IF(($ReplicatedFolder.Enabled) -and ($ReplicationConnection.Enabled))
- {
- $TheQuery = ("SELECT * FROM DfsrReplicatedFolderInfo WHERE ReplicationGroupGUID = '" + $ReplicationGroup.ReplicationGroupGuid + "' AND ReplicatedFolderName = '" + $ReplicatedFolder.ReplicatedFolderName + "'")
- $ErrorActionPreference = 'SilentlyContinue'
- IF($ReplicationConnection.Inbound)
- {
- $ToMem = $ComputerName
- $FromMem = $ReplicationConnection.PartnerDns.Trim()
- $InbWmi = Get-WmiObject -ComputerName $ToMem -Namespace 'root\MicrosoftDFS' -Query $TheQuery
- $OutObj.To = $ToMem
- $OutObj.From = $FromMem
- $OutObj.ReplicationGroupName = $ReplicationGroup.ReplicationGroupName
- $OutObj.ReplicatedFolderName = $ReplicatedFolder.ReplicatedFolderName
- IF ($InbWmi){
- SWITCH($InbWmi.State)
- {
- '0' { $TheState = "Uninitialized" }
- '1' { $TheState = "Initialized" }
- '2' { $TheState = "Initial Sync" }
- '3' { $TheState = "Auto Recovery" }
- '4' { $TheState = "Normal" }
- '5' { $TheState = "In Error" }
- }
- $OutObj.DfsrBacklog = $InbWmi.GetOutboundBacklogFileCount($($InbWmi.GetVersionVector().VersionVector)).BacklogFileCount
- $OutObj.DfsrState = $TheState
- IF($OutObj.DfsrBacklog -gt 0){
- $BackLogFiles = @()
- $InbWmi.GetOutboundBacklogFileIdRecords($($InbWmi.GetVersionVector().VersionVector)).BacklogIdRecords.FullPathName | ForEach-Object {
- $BackLogFiles += "$($_); "
- }
- $OutObj.DfsrBacklogFiles = $BackLogFiles
- } IF($OutObj.DfsrBacklog -le 0){
- $OutObj.DfsrBacklogfiles = '0'
- }
- } IF(-not $InbWmi){
- $OutObj.DfsrBacklog = "Unable to query $ToMem"
- $OutObj.DfsrState = "Unable to query $ToMem"
- }
- }
- IF(-not ($ReplicationConnection.Inbound))
- {
- $ToMem = $ReplicationConnection.PartnerDns.Trim()
- $FromMem = $ComputerName
- $OutWmi = Get-WmiObject -ComputerName $ToMem -Namespace 'root\MicrosoftDFS' -Query $TheQuery
- $OutObj.To = $ToMem
- $OutObj.From = $FromMem
- $OutObj.ReplicationGroupName = $ReplicationGroup.ReplicationGroupName
- $OutObj.ReplicatedFolderName = $ReplicatedFolder.ReplicatedFolderName
- IF ($OutWmi){
- SWITCH($OutWmi.State)
- {
- '0' { $TheState = "Uninitialized" }
- '1' { $TheState = "Initialized" }
- '2' { $TheState = "Initial Sync" }
- '3' { $TheState = "Auto Recovery" }
- '4' { $TheState = "Normal" }
- '5' { $TheState = "In Error" }
- }
- $OutObj.DfsrBacklog = $OutWmi.GetOutboundBacklogFileCount($($OutWmi.GetVersionVector().VersionVector)).BacklogFileCount
- $OutObj.DfsrState = $TheState
- IF($OutObj.DfsrBacklog -gt 0){
- $BackLogFiles = @()
- $InbWmi.GetOutboundBacklogFileIdRecords($($InbWmi.GetVersionVector().VersionVector)).BacklogIdRecords.FullPathName | ForEach-Object {
- $BackLogFiles += "$($_); "
- }
- $OutObj.DfsrBacklogFiles = $BackLogFiles
- } IF($OutObj.DfsrBacklog -le 0){
- $OutObj.DfsrBacklogfiles = '0'
- }
- } IF(-not $OutWmi){
- $OutObj.DfsrBacklog = "Unable to query $ToMem"
- $OutObj.DfsrState = "Unable to query $ToMem"
- }
- }
- $OutObj
- }
- }
- }
- }
- }
- }
- }
- END
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement