SOLVED: See #2
Hi guys,
Programming newbie here.
I am writing a tool which among other things needs to list some servers from a configuration file. The tool needs a GUI, and I am using PowerShell with .net components to write it (it might be an idea to use .net only for this, but that is a task for the future),
I can parse from the configuration file, and create a window for the GUI. I can use labels to display describing text and the variables I use to store the content from the config file, but I cannot figure out how to mix the variables and text. I suspect I need some sort of escape character, but I do not now which.
Any ideas?
Hi guys,
Programming newbie here.
I am writing a tool which among other things needs to list some servers from a configuration file. The tool needs a GUI, and I am using PowerShell with .net components to write it (it might be an idea to use .net only for this, but that is a task for the future),
I can parse from the configuration file, and create a window for the GUI. I can use labels to display describing text and the variables I use to store the content from the config file, but I cannot figure out how to mix the variables and text. I suspect I need some sort of escape character, but I do not now which.
Code:
#Load nescessary .net components
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#Get variable from environment variable
$fromenvvariable = $env:Configroot
#Get content from config file
[xml]$datafromconfigfile = Get-Content $fromenvvariable\servicesconfiguration.XML
#Get machine name
$datafromconfigfile.configuration.services | %{$_.machineName} | select-object -unique
#Add form and controls
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Server locations"
$objForm.Size = New-Object System.Drawing.Size(300,400)
$objForm.StartPosition = "CenterScreen"
#Add text box label for presentation
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,100)
$objLabel.Text = "Some text`n`$datafromservicesconf.configuration.services.machineName" <------- here is my problem, I think
$objForm.Controls.Add($objLabel)
#Create Next button
$NextButton = New-Object System.Windows.Forms.Button
$NextButton.Location = New-Object System.Drawing.Size(75,160)
$NextButton.Size = New-Object System.Drawing.Size(75,23)
$NextButton.Text = "Next"
$NextButton.Add_Click({
$objForm.Close()})
$objForm.Controls.Add($NextButton)
#Activate form
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
Any ideas?
Last edited:
