citrix - Unable to pass command properly to remote computers in Powershell -
i've got powershell script when copied local remote server , executed remotely using psexec correctly runs , need do. trying adapt same script able run remotely not relying on script being copied , executed remotely psexec. command have citrix xenapp server join farm.
# establish variables $zonename = "myzone" $odbcusername = "mycitrixuseracct" $odbcpassword = "mypassword" $licenseservername = "mylicenseserver.company.com" $xaconfigconsoleexe = "c:\progra~2\citrix\xenapp\serverconfig\xenappconfigconsole.exe" $servers = get-content -path .\serverlist.txt foreach ($server in $servers) { # creating mf20.dsn file if ((test-path \\$server\c$\temp\mf20.dsn) -eq $true) { remove-item \\$server\c$\temp\mf20.dsn } add-content \\$server\c$\temp\mf20.dsn "[odbc]" add-content \\$server\c$\temp\mf20.dsn "driver=sql server" add-content \\$server\c$\temp\mf20.dsn "database=mydb" add-content \\$server\c$\temp\mf20.dsn "app=citrix ima" add-content \\$server\c$\temp\mf20.dsn "uid=" add-content \\$server\c$\temp\mf20.dsn "server=dbserver.company.com,1433" add-content \\$server\c$\temp\mf20.dsn "trusted_connection=no" # setting setup arguments [array]$xaarguments = @() $xaarguments += "/executionmode:join" $xaarguments += "/zonename:$zonename" $xaarguments += "/imaworkermode:true" $xaarguments += "/dsnfile:c:\temp\mf20.dsn" $xaarguments += "/authenticationtype:sql" $xaarguments += "/odbcusername:$odbcusername" $xaarguments += "/odbcpassword:$odbcpassword" $xaarguments += "/licenseservername:$licenseservername" $xaarguments += "/licenseserverport:27000" $xaarguments += "/licensemodel:xa" $xaarguments += "/customxmlserviceport:8080" # running setup arguments invoke-command -computername $server {$xaconfigconsoleexe + $xaarguments} }
i've tried ton of different permutations , combinations (i.e. using -scriptblock, using pssessions) of things i've found through searches. know command line because if take output of write-host $xaconfigconsoleexe $xaarguments
, passed powershell console of server works.
i'm sure i'm missing obvious. didn't write original script. can't defend things how arguments built, if there better (more reliable way) doing here open ideas.
here original script can execute remotely psexec looks like:
# establish variables $zonename = "myzone" $odbcusername = "mycitrixuseracct" $odbcpassword = "mypassword" $licenseservername = "mylicenseserver.company.com" $xaconfigconsoleexe = "c:\program files (x86)\citrix\xenapp\serverconfig\xenappconfigconsole.exe" # creating mf20.dsn file if ((test-path c:\temp\mf20.dsn) -eq $true) { remove-item c:\temp\mf20.dsn } add-content c:\temp\mf20.dsn "[odbc]" add-content c:\temp\mf20.dsn "driver=sql server" add-content c:\temp\mf20.dsn "database=mydb" add-content c:\temp\mf20.dsn "app=citrix ima" add-content c:\temp\mf20.dsn "uid=" add-content c:\temp\mf20.dsn "server=mydbserver.company.com,1433" add-content c:\temp\mf20.dsn "trusted_connection=no" # setting setup arguments [array]$xaarguments = @() $xaarguments += "/executionmode:join" $xaarguments += "/zonename:$zonename" $xaarguments += "/imaworkermode:true" $xaarguments += "/dsnfile:c:\temp\mf20.dsn" $xaarguments += "/authenticationtype:sql" $xaarguments += "/odbcusername:$odbcusername" $xaarguments += "/odbcpassword:$odbcpassword" $xaarguments += "/licenseservername:$licenseservername" $xaarguments += "/licenseserverport:27000" $xaarguments += "/licensemodel:xa" $xaarguments += "/customxmlserviceport:8080" # running setup arguments & $xaconfigconsoleexe $xaarguments
i've edited answer reflect final version of script went with. didn't change logic or methods. merely cleaned things , added more variables make script more flexible editing in future.
well isn't prettiest solution, reliable solution find self contained (outside of input .txt file server list). nothing copied from/to anywhere, created dynamically. sense of adventure free on , suggest better/cleaner ways achieve goal.
# establish variables $zonename = read-host 'zone name?' $odbcusername = "citrixuser" $odbcpassword = read-host 'password citrixuser?' $licenseservername = "mylicenseserver.company.com" $database= "dbname" $dbserver= "mydbserver.company.com" $edgesightserver = "myedgesightserver.company.com" $xaconfigconsoleexe = "c:\program files (x86)\citrix\xenapp\serverconfig\xenappconfigconsole.exe" $servers = get-content -path .\serverlist.txt # setting setup arguments [array]$xaarguments = @() $xaarguments += "/executionmode:join" $xaarguments += "/zonename:$zonename" $xaarguments += "/imaworkermode:true" $xaarguments += "/dsnfile:c:\temp\mf20.dsn" $xaarguments += "/authenticationtype:sql" $xaarguments += "/odbcusername:$odbcusername" $xaarguments += "/odbcpassword:$odbcpassword" $xaarguments += "/licenseservername:$licenseservername" $xaarguments += "/licenseserverport:27000" $xaarguments += "/licensemodel:xa" $xaarguments += "/customxmlserviceport:8080" $xaarguments += "/edgesightcompanyname:companyname" $xaarguments += "/edgesightservername:$edgesightserver" $xaarguments += "/edgesightserverport:80" # running against server list foreach ($server in $servers) { # creating joinfarm.bat file on remote server if ((test-path \\$server\c$\temp\joinfarm.bat) -eq $true) {remove-item \\$server\c$\temp\joinfarm.bat} add-content \\$server\c$\temp\joinfarm.bat "$([char]34)$xaconfigconsoleexe$([char]34) $xaarguments" add-content \\$server\c$\temp\joinfarm.bat "shutdown.exe /r /f /t 10" add-content \\$server\c$\temp\joinfarm.bat "del c:\temp\mf20.dsn /q" add-content \\$server\c$\temp\joinfarm.bat "del c:\temp\joinfarm.bat /q" # creating mf20.dsn file on remote server if ((test-path \\$server\c$\temp\mf20.dsn) -eq $true) {remove-item \\$server\c$\temp\mf20.dsn} add-content \\$server\c$\temp\mf20.dsn "[odbc]" add-content \\$server\c$\temp\mf20.dsn "driver=sql server" add-content \\$server\c$\temp\mf20.dsn "database=$database" add-content \\$server\c$\temp\mf20.dsn "app=citrix ima" add-content \\$server\c$\temp\mf20.dsn "uid=" add-content \\$server\c$\temp\mf20.dsn "server=$dbserver,1433" add-content \\$server\c$\temp\mf20.dsn "trusted_connection=no" # running setup arguments invoke-command -computername $server -scriptblock {c:\temp\joinfarm.bat} -asjob }
what i'm doing writing batch file (i tried writing ps1 file wasn't running commands after initial command when ran ps1 -asjob
though seemed work if didn't use -asjob
) remote server , executing batch -asjob
switch can join multiple servers simultaneously. without -asjob
each server had complete before next processed. batch cleans itself, dsn file, , reboots server.
Comments
Post a Comment