Friday, September 7, 2012

VBScript to rename Program Neighborhood Paths

The client I was working at had a multi-farm XenApp environment so I ended up needing a script that would run on XA 4.5 as well. This is essentially the same script I wrote in powershell translated to vbscript, edit appropriately as you need for your environment.


option explicit
Const MetaFrameWinAppObject = 3
Const MetaFrameWinFarmObject = 1
Dim aMFApp, hMFAppTemp, aMFTemp
Dim MFFarm : Set MFFarm = WScript.CreateObject ("MetaFrameCOM.MetaFrameFarm")
MFFarm.Initialize(MetaFrameWinFarmObject)
Dim mode, count, strReplace
mode = "Debug"
count = 0
Dim objECA, objAPAC, objAGLNG
Set objECA = New RegExp
Set objAPAC = New RegExp
Set objAGLNG = New RegExp
With objECA
                .Pattern = "ECA\\"
                .IgnoreCase = True
End With
With objAGLNG
                .Pattern = "AGLNG\\"
                .IgnoreCase = True
End With
With objAPAC
                .Pattern = "APAC\\"
                .IgnoreCase = True
End With
For Each aMFApp in MFFarm.Applications
Set hMFAppTemp = CreateObject("MetaFrameCOM.MetaFrameApplication")
hMFAppTemp.Initialize MetaFrameWinAppObject,aMFApp.DistinguishedName
hMFAppTemp.LoadData(True)
Set aMFTemp = hMFAppTemp.WinAppObject2
                If objAGLNG.Test(aMFTemp.PNFolder) = True Then
                                count = count + 1
                                strReplace = Replace(aMFTemp.PNFolder,"AGLNG\","")
                                If mode = "Debug" Then
                                                Wscript.Echo aMFTemp.AppName & " - old: " & aMFTemp.PNFolder & " new: " & strReplace
                                Elseif mode = "Real" Then
                                                aMFTemp.PNFolder = strReplace
                                                aMFTemp.SaveData()
                                End If   
                ElseIf objAPAC.Test(aMFTemp.PNFolder) = True Then
                                count = count + 1
                                strReplace = Replace(aMFTemp.PNFolder,"APAC\","")
                                If mode = "Debug" Then
                                                               
                                                Wscript.Echo aMFTemp.AppName & " - old: " & aMFTemp.PNFolder & " new: " & strReplace
                                Elseif mode = "Real" Then
                                                aMFTemp.PNFolder = strReplace
                                                aMFTemp.SaveData()
                                End If   
                ElseIf objECA.Test(aMFTemp.PNFolder) = True Then
                                count = count + 1
                                strReplace = Replace(aMFTemp.PNFolder,"ECA\","")
                                If mode = "Debug" Then
                                                Wscript.Echo aMFTemp.AppName & " - old: " & aMFTemp.PNFolder & " new: " & strReplace
                                Elseif mode = "Real" Then
                                                aMFTemp.PNFolder = strReplace
                                                aMFTemp.SaveData()
                                End If   
                End If
Set aMFTemp = Nothing
Set hMFAppTemp = Nothing
Next
Wscript.Echo "Total applications updated : " & count

No comments:

Post a Comment