Use data from xml file that contains several names as input for servernames in new-xaaplication


hi powershell friends ;-)

so i'm using citrix powershell snapin create new citrix folder , citrix published application. runs fine except variable use define servers want assigned published application.

- here script -

################
# script preparation - citrix script
################

## ! load functions

. \\nobackup\options$\psscripts\codetrunk\loadsnapins_function.ps1
    # load loadsnapins function in loadsnapins_function.ps1
    loadsnapins

## load getdatatocreatehdcu function. load data (general variables used creating customer)
. \\nobackup\options$\psscripts\codetrunk\getdatatocreatehdcu_function.ps1
    getdatatocreatehdcu

## ! variables specific script only

# -- citrix 2k8 r2 farm srv
$citrixfarmsrv = "ts123"
# -- cu pub. desktop app. servers
$citrixpubdesksrvs = $scriptdata.data.citrixsetup.pubdesksrvs

#####################
# script body - start
#####################
# - citrix notes - #
# want use -computername citrix commands. contact farm server remotely. if don't have run script
# directly on farm server.

# create citrix farm folder put our customer in
new-xafolder applications/$company -computername $citrixfarmsrv

# create published desktop application our customer
new-xaapplication ($company + " " + "hosted desktop") -applicationtype serverdesktop -description ($company + " " + "hosted desktop") -servers $citrixpubdesksrvs -accounts "asp\$company desktop" -multipleinstancesperuserallowed $false -addtoclientdesktop $true -folderpath applications/$company -windowtype 100% -maximizedonstartup $true -titlebarhidden $true -addtoclientstartmenu $false -waitonprintercreation $false -encodedicondata (get-ctxicon -typedefault serverdesktop) -computername $citrixfarmsrv
###################
# script body - end
###################

the function loadsnapins, loads citrix module , other snapins

the fucntion getdatatocreatehdcu loads following code:


function getdatatocreatehdcu() {
# load data script, configured in file: create_customer_config.xml
# file location: \\nobackup\options$\psscripts\create-customer\data\config\
# file contains necessary info creating customer. data has unique.
[xml]$scriptdata = get-content \\nobackup\options$\psscripts\create-customer\data\config\create_customer_config.xml

# define $scriptdata variable can load in scripts. forexample in scripts has variables used in 1 script
new-variable -name scriptdata -value ($scriptdata) -scope 1
# read company name config file & define variable
$company = $scriptdata.data.company
new-variable -name company -value ($company) -scope 1
}

--- in first script posted define variable $citrixpubdesksrvs gets data $scriptdata loaded/defined in/from getdatatocreatehdcu.

$scriptdata defined new-variable , gets it's data [xml]$scriptdata.

--- when run script following error:

new-xaapplication : cannot find server name "ts122","ts123" (0x80000003 invalid argument.)
@ line:1 char:1
+ new-xaapplication ($company + " " + "hosted desktop") -applicationtype serverdes ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + categoryinfo          : invalidresult: (ts122,ts123:string) [new-xaapplication], citrixexception
    + fullyqualifiederrorid : getserverdatabyname,citrix.xenapp.commands.newappcmdlet

--- xml file looks this

<data>

      <citrixsetup>

           <pubdesksrvs>ts122,ts123</pubdesksrvs>

      </citrixsetup>

</data>

--- if run script within powershell window can thereafter, in same window, call $scriptdata , data doing $scriptdata.data.citrixsetup.pubdesksrvs

and calling script show me ps c:\> ts122,ts123 new-xaaplication not accept input. if try define variable again in powershell window have open, $citrixpubdesksrvs = "ts122","ts123" works.

if $citrixpubdesksrvs.gettype() can see initial variable name string , basetype system.object. if gettype() on $citrixpubdesksrvs on manually defined variable name object , basetype system.array.....

so think it's in way call data causes fail.

according new-xaaplication -servernames option requires string , if i'm not mistaking i'm providing command that....or what?

looking forward hear you.

kind regards

lars bengtsson


red baron

try this:

$citrixpubdesksrvs = ($scriptdata.data.citrixsetup.pubdesksrvs) -split ','


grant ward, a.k.a. bigteddy

what's new in powershell 3.0 (technet wiki)



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS