Hello,
I have been working on creating my own powershell scripts for a monitoring web dashboard that uses, powershell to gather data and rrdtool to save the data to generate graphs.
I am working on possibly my most complex script to date and learning as I go. Just alittle background on the setup. We have 6 domains, of which no trust exists between them. Each domain has its own citrix xenapp 6.5 farm. we have 1 designated "scripting" server where all the powershell scripts will run to query the XenApp Data collectors in each domain.
I have created a csv file with a domain and servername column. and filled out the fields with the server name of each citrix xenapp data collector and the fqdn of the server in the domain column.
I have also added to the script authentication for each domain:
$DomainAPassword = "encrypted password"
$DomainAKey = "encrypted key"
$DomainAPasswordSecure = ConvertTo-SecureString -String $DomainAPassword -Key ([Byte[]]$DomainAkey.Split(" "))
$DomainAcred = New-Object system.Management.Automation.PSCredential("DomainA\myuserid", $DomainAPasswordSecure)
$DomainAcred
$DomainBPassword = "encrypted password"
$DomainBKey = "encrypted key"
$DomainBPasswordSecure = ConvertTo-SecureString -String $accpassword -Key ([Byte[]]$DomainBkey.Split(" "))
$DomainBcred = New-Object system.Management.Automation.PSCredential("DomainB\myuserid", $DomainBPasswordSecure)
$DomainBcred
$DomainCPassword = "encrypted password"
$DomainCKey = "encrypted key"
$DomainCPasswordSecure = ConvertTo-SecureString -String $DomainCpassword -Key ([Byte[]]$DomainCkey.Split(" "))
$DomainCcred = New-Object system.Management.Automation.PSCredential("DomainC\myuserid", $DomainCpasswordSecure)
$DomainCcred
I am able to run the invoke command manually with the Add-PSSnapin Citrix.XenApp.Commands to load the XenApp sdk and then run the Get-XAFarm cmdlet to get the farm info.
In the script though I want to import the csv, lookup the domain for each server, and by domain chose the right $DomainXcred to add to the -Credential in the invoke-command to run the remote cmdlets on the respective server.
Essentially I have tried looking into params, switch and not sure what route to go, and have tried without success. so far my logic is across these lines:
$server = import-csv $csvfile
ForEach ($device in $server) {
$ScriptBlock = {
{
if($Domain = "DomainA.com") {
$FarmName = Invoke-Command -ComputerName $FQDN -Credential $DomainAcred -Scriptblock { Add-PSSnapin Citrix.XenApp.Commands; Get-XAFarm; Write-Host $FarmName }
}
if($Domain = "DomainB.com") {
Invoke-Command -ComputerName $FQDN -Credential $DomainBcred -Scriptblock { Add-PSSnapin Citrix.XenApp.Commands; Get-XAFarm }
}
if($Domain = "DomainC") {
Invoke-Command -ComputerName $FQDN -Credential $DomainCcred -Scriptblock { Add-PSSnapin Citrix.XenApp.Commands; Get-XAFarm }
}
else {}
}