Every DPM administrator, ever tried to perform a regular maintenance onto a set of SCDPM servers (monthly updates, for example), knows that the only one way to do it correctly, i.e. without interruption of backup jobs, is to gracefully shutdown the server. To achieve this, you need to disable active SCDPM agents, connected to this server, and wait till every running job will be completed.
The only problem is — there is no quick way to get a list of every computer with an active agent connected to a SCDPM server. One may say, I’m wrong here and there IS a quick way — just use Get-DPMProductionServer cmdlet with “ServerProtectionState -eq ‘HasDatasourcesProtected'” filter. But you forgot about cluster nodes: If we protect clustered resource, but not cluster nodes themselves, we will not see them in an output of Get-DPMProductionServer (with abovementioned filter applied, of course). In addition, the output will contain clustered resources, which are useless in our task to stop every active protection agent.
That’s why I want to present you with a solution to quickly get a list of only real computers with an active SCDPM-agent installed. Just pass names of your SCDPM-servers to it (or don’t pass anything for localhost) and you’ll receive a collection of ProtectedServers in response. You may then pass that collection directly to Enable/Disable-DPMProductionServer cmdlets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
<# MIT License Copyright (c) 2015 Kirill Nikolaev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #> <# .SYNOPSIS Returns active protected agents connected to an SCDPM server. .DESCRIPTION Returns every computer with installed SCDPM agent, connected to the chosen SCDPM server and having protected any datasource at this SCDPM server. .PARAMETER DPMServerName A single name (FQDN ot NetBIOS) of an SCDPM server or a collection of such. .EXAMPLE C:\PS> .\Get-DPMProtectedAgents.ps1 -DPMServerName bckpsrv1.example.com WARNING: Connecting to DPM server: bckpsrv1.example.com ServerName ClusterName Domain ServerProtectionState ---------- ----------- ------ --------------------- SRV1 example.net HasDatasourcesProtected SRV2 CL1.example.com example.com HasDatasourcesProtected .EXAMPLE C:\PS> 'bckpsrv1.example.com','bckpsrv2.example.com' | .\Get-DPMProtectedAgents.ps1 WARNING: Connecting to DPM server: bckpsrv1.example.com ServerName ClusterName Domain ServerProtectionState ---------- ----------- ------ --------------------- SRV1 example.net HasDatasourcesProtected SRV2 CL1.example.com example.com HasDatasourcesProtected WARNING: Connecting to DPM server: bckpsrv2.example.com SRV3 example.net HasDatasourcesProtected SRV4 CL2.example.com example.com HasDatasourcesProtected SRV5 CL2.example.com example.com HasDatasourcesProtected .EXAMPLE C:\PS> .\Get-DPMProtectedAgents.ps1 | %{ Disable-DPMProductionServer $_ -Confirm:$false } C:\PS> .INPUTS System.String[]. An array of names of SCDPM servers. .OUTPUTS System.Object[]. A collection of Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.OMCommon.ProductionServer #> [CmdletBinding()] [OutputType([System.Object[]])] Param( [Parameter(Mandatory=$false, ValueFromPipeline=$true)] [string[]]$DPMServerName = 'localhost' #We need something in $DPMServerName for the cycle to work. ) PROCESS { foreach ($Name in $DPMServerName) { Disconnect-DPMServer if ($Name -eq '' -or $Name -eq 'localhost') { $ProductionServers = Get-DPMProductionServer #Execution of DPM cmdlets with given server name doesn't work in PSSessions. So, we have to use two branches of code here. } else { $ProductionServers = Get-DPMProductionServer -DPMServerName $Name } $ProtectedServers = $ProductionServers | where {$_.ServerProtectionState -eq 'HasDatasourcesProtected'} Write-Debug "ProtectedServers at $Name" if ($ProtectedServers) { Write-Debug ([string]$ProtectedServers) } else { Write-Debug 'No ProtectedServers found' } $ProtectedServersStandAlone = $ProtectedServers | where {$_.ClusterName -eq ''} Write-Debug "ProtectedServersStandAlone at $Name" if ($ProtectedServersStandAlone) { Write-Debug ([string]$ProtectedServersStandAlone) } else { Write-Debug 'No ProtectedServersStandAlone found' } $ProtectedServersClustered = $ProtectedServers | where {$_.ClusterName -ne ''} #Need to split clustered resources and cluster nodes from stand-alone servers, because if we don't protect cluster node itself, it will not shows up in $ProtectedServers and we'll find it through properties of the clustered resource. Write-Debug "ProtectedServersClustered at $Name" if ($ProtectedServersClustered) { Write-Debug ([string]$ProtectedServersClustered) } else { Write-Debug 'No ProtectedServersClustered found' } $ClusteredResouces = $ProtectedServersClustered | where {$_.PossibleOwners} #Select only clustered resources, not nodes itself. Write-Debug "ClusteredResouces at $Name" if ($ClusteredResouces) { Write-Debug ([string]$ClusteredResouces) } else { Write-Debug 'No ClusteredResouces found' } $ClusterNodesDNSNames = @() $ClusteredResouces | %{$ClusterNodesDNSNames += $_.PossibleOwners} Write-Debug "ClusterNodesDNSNames at $Name" if ($ClusterNodesDNSNames) { Write-Debug ([string]$ClusterNodesDNSNames) } else { Write-Debug 'No ClusterNodesDNSNames found' } $ClusterNodesDNSNames = $ClusterNodesDNSNames | Select-Object -Unique Write-Debug "Unique ClusterNodesDNSNames at $Name" if ($ClusterNodesDNSNames) { Write-Debug ([string]$ClusterNodesDNSNames) } else { Write-Debug 'No ClusterNodesDNSNames found' } $ClusterNodesNames = @() $ClusterNodesDNSNames | %{$_ -match '(.+?)\..+' | Out-Null; $ClusterNodesNames += $Matches[1]} #Extract hostnames from DNS names to pass them to SCDPM cmdlets. Write-Debug "ClusterNodesNames at $Name" if ($ClusterNodesNames) { Write-Debug ([string]$ClusterNodesNames) } else { Write-Debug 'No ClusterNodesNames found' } $ClusterNodes = @() $ClusterNodes += $ProtectedServersClustered | where {$_ -notin $ClusteredResouces} #Select only clustered nodes. foreach ($NodeName in $ClusterNodesNames) { $ClusterNodes += $ProductionServers | where {$_.ServerName -eq $NodeName} } Write-Debug "ClusterNodes at $Name" if ($ClusterNodes) { Write-Debug ([string]$ClusterNodes) } else { Write-Debug 'No ClusterNodes found' } $ProtectedAgents = $ProtectedServersStandAlone + $ClusterNodes | Select-Object -Unique Write-Debug "ProtectedAgents at $Name" if ($ProtectedAgents) { Write-Debug ([string]$ProtectedAgents) } else { Write-Debug 'No ProtectedAgents found' } Write-Output $ProtectedAgents } } |