System Center Configuration Manager remote tools side-by-side

At work, I’m currently running a side-by-side migration from the System Center Configuration 2007 (aka SCCM 2007) to System Center Configuration Manager 2012 (aka ConfigMgr 2012). The helpdesk team have been accustomed to launch a rsms.bat file that I wrote years ago, to launch directly the remote tools. It had a great advantage, as the support operator doesn’t need to launch the Admin Console, expand the collection, search the target computer and right-click the computer to launch the remote tools. This old nifty script allowed the helpdesk operator to gain precious seconds while answering phone calls.

Here’s the content of my brave old rsms.bat file:

@echo off

set _HERE=%0\..
set _HERE=%_HERE:"=%
set _TIP=

for /f  "tokens=4,*" %%i in ('%systemroot%\system32\reg.exe query "HKLM\SOFTWARE\Microsoft\ConfigMgr\Setup" /v "UI Installation Directory" ^| find /i "REG_SZ"') do @ set _REXEPATH=%%j
set _REXE=%_REXEPATH%\bin\i386\rc.exe
if not exist "%_REXE%" echo ERROR: "%_REXE%" not found & goto finish

set _target=%1

:: Sanity check
if "%_target%"=="" echo ERROR: Target Computer not specified as first argument&  goto finish

:: Try to see if machine is up and get its IP address
ping %_TARGET% -n 1 | find /i "TTL" >NUL 2>&1
if not "%errorlevel%"=="1" goto _ok
echo %1: not available& goto finish

:_ok
:: Get the target IP Address
for /F "tokens=1-3 delims=: " %%i in ('ping %_TARGET% -n 1 ^| findstr /i /c:"Reply from"') do set _TIP=%%k

if "%_TIP%"=="" echo.& echo Unable to get the IP address & echo. & echo Use the following command: rsms.bat IPaddress where IPaddress is the following IP & echo. & ping %_TARGET% & goto finish

echo Connecting to %_TARGET% = %_TIP%

:: Expands %i to a full path name with short names only
for /F "tokens=*"  %%i in ( "%_REXEPATH%" ) do @ start %%~fsi\bin\i386\rc.exe 1 %_TIP% \\NameOfSCCM2007Server\

:finish

To support both plateforms side-by-side, I’ve replaced its content and actually moved the master piece into a powershell script as follows 🙂

@echo off
if "%1"=="" echo Target is missing & goto finish
if not exist %systemroot%\rsms.ps1 echo The file "rsms.ps1" is missing & goto finish
if not exist %systemroot%\system32\WindowsPowershell\v1.0\powershell.exe echo Powershell not found & goto finish
"%systemroot%\system32\WindowsPowershell\v1.0\powershell.exe" -ExecutionPolicy RemoteSigned -File %systemroot%\rsms.ps1 %1
:finish
# Requires -Version 2.0            
[CmdletBinding()]            
Param(            
    [Parameter(Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]                        
    [Alias("CN","__SERVER","IPAddress")]                        
    [String]$ComputerName            
)            
Begin {            
    # Step 1: Check if we can find locally the admin console for:            
    # SCCM 2007            
    try {            
        $ConfigMgr2007ConsolePath = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\ConfigMgr\Setup" -Name "UI Installation Directory" -ErrorAction Stop)."UI Installation Directory"            
    } catch {            
        Write-Verbose -Message "Failed to find the registry key for SCCM 2007 Admin console"            
    }            
    # SCCM 2012            
    try {            
        $ConfigMgr2012ConsolePath = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\ConfigMgr10\Setup" -Name "UI Installation Directory" -ErrorAction Stop)."UI Installation Directory"            
    } catch {            
        Write-Verbose -Message "Failed to find the registry key for SCCM 2012 Admin console"            
    }            
}             
Process {            
    # Step 2: Test the remote computer using WMI to figure out what ConfigMgr client it has installed            
    try {            
        $SCCMClient = Get-WmiObject -Namespace root/CCM -Class SMS_Client -ComputerName $ComputerName -ErrorAction Stop            
    } catch {            
        # WMI was unable to retrieve the information            
        Switch ($_) {            
            { $_.Exception.ErrorCode -eq 0x800706ba } {            
                $reason =  "Unavailable (offline, firewall)"            
            }            
            { $_.CategoryInfo.Reason -eq 'UnauthorizedAccessException' } {            
                $reason = "Access denied"            
            }            
            default {             
                $reason  = $_.Exception.Message            
            }            
        }            
        Write-Warning -Message "Failed to connect to $($Computername) because: $reason"            
        break            
    }            
    # Step 3: Based on the SCCM client version launch the remote tools with the appropriate Admin Console            
    if ($SCCMClient) {            
        Write-Verbose -Message "SCCM Client version $($SCCMClient.ClientVersion) found on $($ComputerName)" -Verbose            
        Switch -regex (($SCCMClient.ClientVersion)) {            
            "4\.00\.\d{4}\.\d{4}" {            
                if (Test-Path "$($ConfigMgr2007ConsolePath)\bin\i386\rc.exe") {            
                    #             
                    & (Get-Command "$($ConfigMgr2007ConsolePath)\bin\i386\rc.exe") @("1",$ComputerName)            
                } else {            
                    Write-Warning -Message "SCCM 2007 Remote tools not found to target the SCCM Client $ComputerName"            
                }            
                break            
            }            
            "5\.00\.7804.\d{4}" {            
                if (Test-Path "$($ConfigMgr2012ConsolePath)\bin\i386\CmRcViewer.exe") {            
                    #             
                    & (Get-Command "$($ConfigMgr2012ConsolePath)\bin\i386\CmRcViewer.exe") @($ComputerName)            
                } else {            
                    Write-Warning -Message "SCCM 2012 Remote tools not found to target the SCCM Client $ComputerName"            
                }            
                            
                break            
            }            
            default {            
                Write-Warning "The Client version of SCCM $($_) is unexpected"            
            }            
        }            
    }            
            
}            
End {}

Here’s what the operator can see when he targets different computers. Of course, he has previously installed both SCCM 2007 and ConfigMgr Admin consoles and been granted the ‘remote tools’ privilege on both System Center Configuration Manager servers…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s