<# .SYNOPSIS Lets the MigraTier agent reach Backup Exec on this server over PowerShell remoting. .DESCRIPTION Run this on the Backup Exec server, as an administrator, before installing the MigraTier agent. It: 1. turns on PowerShell remoting (WinRM over HTTP, TCP 5985); 2. adds the agent's account to the local "Remote Management Users" group; 3. allows TCP 5985 in from the agent's server only; 4. checks that the Backup Exec PowerShell module (BEMCLI) is installed. The account must also be a Backup Exec administrator (Backup Exec console: Configuration and Settings > Logon Accounts), because BEMCLI runs as that account. Run it again with -Remove when the migration is over: it removes the firewall rule and the group membership. Remoting itself stays on, because other tools may use it. .PARAMETER AgentAddress The IP address (or addresses) of the server where the MigraTier agent runs. .PARAMETER Account The account the agent logs in to Backup Exec with, for example CORP\svc-migratier. .EXAMPLE .\enable-backupexec-remoting.ps1 -AgentAddress 10.0.0.15 -Account CORP\svc-migratier .EXAMPLE .\enable-backupexec-remoting.ps1 -AgentAddress 10.0.0.15 -Account CORP\svc-migratier -Remove .NOTES MigraTier. See the user guide, sections 13 and 25. #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string[]] $AgentAddress, [Parameter(Mandatory = $true)] [string] $Account, [switch] $Remove ) $ErrorActionPreference = 'Stop' $RuleName = 'MigraTier agent (WinRM)' $Group = 'Remote Management Users' $identity = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object Security.Principal.WindowsPrincipal($identity) if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Error 'Run this script as an administrator.' } function Test-Member { $name = $Account.ToLowerInvariant() foreach ($member in Get-LocalGroupMember -Group $Group) { if ($member.Name.ToLowerInvariant() -eq $name) { return $true } } return $false } if ($Remove) { Get-NetFirewallRule -DisplayName $RuleName -ErrorAction SilentlyContinue | Remove-NetFirewallRule Write-Host "Firewall rule '$RuleName' removed (if it existed)." if (Test-Member) { Remove-LocalGroupMember -Group $Group -Member $Account Write-Host "$Account removed from '$Group'." } Write-Host 'Done. PowerShell remoting is left on.' return } Write-Host '[1/4] Turning on PowerShell remoting (WinRM, TCP 5985)' Enable-PSRemoting -Force -SkipNetworkProfileCheck | Out-Null Test-WSMan -ComputerName localhost | Out-Null Write-Host "[2/4] Adding $Account to '$Group'" if (Test-Member) { Write-Host ' already a member' } else { Add-LocalGroupMember -Group $Group -Member $Account } Write-Host "[3/4] Allowing TCP 5985 in from $($AgentAddress -join ', ') only" Get-NetFirewallRule -DisplayName $RuleName -ErrorAction SilentlyContinue | Remove-NetFirewallRule New-NetFirewallRule -DisplayName $RuleName -Direction Inbound -Protocol TCP -LocalPort 5985 ` -RemoteAddress $AgentAddress -Action Allow -Profile Any | Out-Null Write-Host '[4/4] Checking the Backup Exec PowerShell module (BEMCLI)' if (Get-Module -ListAvailable -Name BEMCLI) { Write-Host ' BEMCLI is installed' } else { Write-Warning 'BEMCLI was not found. Install the Backup Exec console (it includes BEMCLI) on this server.' } Write-Host '' Write-Host "Done. Make sure $Account is a Backup Exec administrator, then install the agent and" Write-Host "run 'migratier-agent preflight': the Backup Exec checks should pass."