Brian Madden Logo
Your independent source for application and desktop virtualization.
advertisement

enable/disable icons...., in the Scripting / Automation forum on BrianMadden.com

rated by 0 users
This post has 14 Replies | 2 Followers

Not Ranked
Points 90
Harold Jenkins Posted: Tue, Jan 22 2008 1:11 PM
Does anyone have a script to enable/disable a bunch of icons at a time? And I am looking for one that will remove all published applications from a specific server.

Thanks
  • | Post Points: 65
Top 500 Contributor
Points 415
Brandon Shell replied on Wed, Jan 23 2008 10:09 AM
Below is a Powershell script to remove all applications from a server or from a group of servers. This can be found on my site at http://bsonposh.com/modules/wordpress/?p=49

Cut/past text into UnPublish-CitrixServer.ps1

Usage:
PS> . PathtoScript\UnPublish-CitrixServer.ps1
PS> UnPublish-CitrixServer Server1
or for a group of servers
PS> type ServerList.txt | UnPublish-CitrixServer

function UnPublish-CitrixServer{

Param([string]$server)
Begin{
function gcs{
Param($srv)
$type = [System.Type]::GetTypeFromProgID("MetaframeCOM.MetaframeServer",$Server)
$mfServer = [system.Activator]::CreateInstance($type)
$mfServer.Initialize(6,$Server)
$mfServer
}
function cUnPublish {
Param([string]$Srv)
$Srv = $Srv.toUpper()
$mfSrv = gcs $srv
If($mfSrv.Applications.Count -gt 0)
{
Write-Host "Removing All Published Applications from $Srv" -ForegroundColor Red
Write-Host "===================================================" -ForegroundColor Green
ForEach($a in $mfSrv.Applications)
{
$myApp = $a.AppName
Write-Host "Removing App [$myApp] from Server [$Srv]" -ForegroundColor White
$a.RemoveServer($Srv)
$a.SaveData()
}
}
else
{
Write-Host "No Published Applications for $Srv" -ForegroundColor Red
}
}
Write-Host
$process = @()
}
Process{
if($_){
if($_.ServerName)
{
$process += $_.ServerName
}
else
{
$process += $_
}
}
}
End{
if($Server){$Process += $Server}
foreach($s in $process){
cUnPublish $s
Write-Host
}
}
}
Brandon Shell [MVP]
a.k.a BSonPosh

Note: If you want help learning Powershell or your struggling with some concepts... feel free to contact me through a post or my blog. I spend what time I have helping you learn. I do think I should be clear... I want to help you LEARN... not do your job for you. I will NOT simply write scripts for you if I do not think you wish to learn. I will spend hours if I think I can help you learn... I will not waste 5mins if I think your just want an easy way out.
  • | Post Points: 35
Not Ranked
Points 265
PAU can do this;

To add/remove servers, have a look at this;
http://www.gourami.eu/files/downloads/pau_batch_server.wmv

To disable a bunch of apps;
http://www.gourami.eu/files/downloads/pau_disable_hide.wmv

Cheers
http://www.gourami.eu/ Citrix/VMWare/Microsoft tooling
  • | Post Points: 20
Not Ranked
Points 115
Here is good old MFCOM vb script to do it. Found on CDN site
Brandon you have very good Powershell skills. I appreciate you helping the Citrix community online.
Thanks

http://community.citrix.com/display/cdn/Remove+All+Applications+From+a+Server+in+a+Citrix+Farm









File: RemoveAllAppsFromAServer.wsf
Description: Exanmple of Remove App from a Server .
Requirements: WSH 5.5 or higher.





Remove All Applications from a Citrix server .


CScript //nologo RemoveAllAppsFromAServer.wsf SERVER1






Dim theFarm, ServerName

' If no parameters specified, quit and
' show the usage of the script
'
if WScript.Arguments.Count <> 1 Then
WScript.Echo "USAGE: RemoveAllAppsFromAServer.wsf ServerName"
WScript.Echo ""
WScript.Echo "Example: RemoveAllAppsFromAServer.wsf SERVER1"
WScript.Quit 0
End If

'
' Create MetaFrameFarm object
'

Set theFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
if Err.Number <> 0 Then
WScript.Echo "Can't create MetaFrameFarm object"
WScript.Echo "(" & Err.Number & ") " & Err.Description
WScript.Echo ""
WScript.Quit Err.Number
End if

'
' Initialize the farm object.
'

theFarm.Initialize(MetaFrameWinFarmObject)
if Err.Number <> 0 Then
WScript.Echo "Can't Initialize MetaFrameFarm object"
WScript.Echo "(" & Err.Number & ") " & Err.Description
WScript.Echo ""
WScript.Quit Err.Number
End if

'
' Are you Citrix Administrator?
'

if theFarm.WinFarmObject.IsCitrixAdministrator = 0 then
WScript.Echo "You must be a Citrix admin to run this script"
WScript.Echo ""
WScript.Quit 0
End If


For Each aServer in theFarm.Servers

If (aServer.ServerName = UCase(ServerName)) Then

For Each anApp In aServer.Applications

anApp.LoadData(1)
anApp.RemoveServer(ServerName)
anApp.SaveData
Next

End If

Next

if Err.Number <> 0 Then
WScript.Echo "Can't Remove app from server"
WScript.Echo "(" & Err.Number & ") " & Err.Description
WScript.Echo ""
WScript.Quit Err.Number
End if

WScript.Echo "Removed Apps successfully"






  • | Post Points: 5
Not Ranked
Points 70

I'm rather new to PoSh, and having a little trouble with a slightly reworked version of Brandon's script.  I'm hoping someone can help.

Here's what I've got:

Param([string]$Server)
   Write-Host
   $Server = $Server.toUpper()
   $MFSrv = New-Object -ComObject MetaFrameCOM.MetaFrameServer
   $MFSrv.Initialize(6,"$Server")
   If($MFSrv.Applications.Count -gt 0) {
      Write-Host "Removing All Published Applications from $Server"
      Write-Host "==================================================="
      ForEach($App in $MFSrv.Applications) {
         $PubApp = $App.BrowserName ; modified the MFCOM object for PS4.5
         Write-Host "Removing PUblished Application $PubApp from Server $Server"
         $App.RemoveServer($Server)
         $App.SaveData()
      }
   }
   else {
     Write-Host "No Published Applications for $Server"
   }

The script does manage to enumerate the applications, but throws an error when it gets to the RemoveServer action:

At P:\Server Administration\Scripting\PowerShell\RemoveAllApps.ps1:12 char:27
+          $App.RemoveServer( <<<< $Server)
Exception calling "SaveData" with "0" argument(s): "Exception from HRESULT: 0x820D0002"
At P:\Server Administration\Scripting\PowerShell\RemoveAllApps.ps1:13 char:23
+          $App.SaveData( <<<< )

I've tried it a bunch of different ways with no luck.  Any ideas?

  • | Post Points: 20
Not Ranked
Points 150

 $App.RemoveServer($Server.ToUpper())

  • | Post Points: 5
Not Ranked
Points 150
Never mind, i see you are already doing this. Try the following - Initialize the app object, $App.LoadData(false). - If that doesn't work, Remove the line $App.SaveData() and try again.
  • | Post Points: 35
Not Ranked
Points 70

Hi Mike,

Thanks for your reply, but still no.  In fact, I'm more confused because the statement looks perfect to me.

I added the LoadData method before RemoveServer, and the output is now:

 

        Missing ')' in method call.

        At :line:12 char:18

        + $App.LoadData(f <<<< alse)

  • | Post Points: 5
Top 10 Contributor
Points 24,330

The original poster was looking for a script; however, perhaps these free apps are useful to someone:


http://www.citrixtools.net
http://sbc.vanbragt.net/mambo/index.php?option=com_content&task=view&id=523&Itemid=49
http://sbc.vanbragt.net/mambo/index.php?option=com_content&task=view&id=749&Itemid=49
http://sbc.vanbragt.net/mambo/index.php?option=com_content&task=view&id=221&Itemid=49

 

Alan Osborne

President (MCSE, CCNA, VCP, CCA)

VCIT Consulting - Citrix/Terminal Services Remote Desktop Solutions for SMB

VCIT website My Blog

  • | Post Points: 5
Not Ranked
Points 70

Hey Mike,

Believe it or not, I'm still struggling with this.  Do you (or perhaps anyone out there) have any other recommendations?

  • | Post Points: 20
Not Ranked
Points 150

try $app.loaddata(0) instead of false.

also what version of Citrix is this?

  • | Post Points: 20
Not Ranked
Points 70

Sorry, meant to post that off the top, but I apparrently forgot.

XA4.5 R03, running on W2K3 SP2 (mainly, a few SP1 servers still).

  • | Post Points: 20
Not Ranked
Points 150

did you try the $app.loaddata(0) ?

  • | Post Points: 5
Not Ranked
Points 150

also put a sleep right after removeserver and after savedata, like this

 

 $App.RemoveServer($Server)

Start-Sleep –milliseconds 2000

         $App.SaveData()

Start-Sleep –milliseconds 2000

  • | Post Points: 5
Not Ranked
Points 150

Sorry for multiple postings, here is the script i want you to try. Loaddata call should be set to true instead of false, as you are changing the application properties. Looks like for 4.5 LoadData  call MUST be made, where as CPS 4.0 versions this wasn't necessary.

This line also looks like need to be modified , enclosed in Quotes. 

Write-Host "Removing PUblished Application $PubApp from Server $Server"

Finalized script to try as below, input a test server name to test on one of your test servers, instead of passing it as argument.

 

   $Server="ServerName"

   $Server = $Server.toUpper()

   $MFSrv = New-Object -ComObject MetaFrameCOM.MetaFrameServer
   $MFSrv.Initialize(6,"$Server")
   If($MFSrv.Applications.Count -gt 0) {
      Write-Host "Removing All Published Applications from $Server"
      Write-Host "==================================================="
      ForEach($App in $MFSrv.Applications) {

        $App.LoadData(1)
         $PubApp = $App.BrowserName

         Write-Host "Removing Published Application $PubApp from Server $Server"

         $App.RemoveServer($Server)

         Start-Sleep -milliseconds 2000

        $App.SaveData()

         Start-Sleep -milliseconds 2000
      }
   }
   else {
     Write-Host "No Published Applications for $Server"
   }

  • | Post Points: 5
Page 1 of 1 (15 items) | RSS