Author Posts

August 21, 2017 at 3:06 pm

Right now I am learning Powershell Studio, so I have a basic code that has a Button plus a RichTextBox.

Code

I am having trouble figuring out where I would need to insert my RichTextBox code so I can have the output display there.

Thanks for any help.

August 21, 2017 at 5:58 pm

If you want the information to display in the rich text box as soon as you click on the button then the code to display the information in the text box should appear in the event for the button click for the button SystemInfo – $buttonSystemInfo_Click

August 21, 2017 at 6:35 pm

I did have $RichTextBox.Text = $Object. Runs but nothing is displayed.

August 21, 2017 at 7:34 pm

I tried the following chunk and it worked fine and showed up in my copy of studio


$buttonSystemInfo_Click = {
	#TODO: Place custom script here
	Import-Module Activedirectory
	$pc = Read-Host -Prompt " Enter Computer Name"
	$bios = Get-WmiObject Win32_BIOS -ComputerName $pc
	$networkResult = Get-WmiObject win32_networkadapterconfiguration -Filter 'ipenabled = "true"' -ComputerName $pc
	
	$Object = New-Object PSObject -Property @{
		'BIOS Version'	     = $bios.Version
		'Serial Number'	     = $bios.SerialNumber
		'MACAddress'		 = $networkResult.MACAddress
	}
	$richtextbox1.text = $Object | Out-String
}

The formatting isn't the nicest doing just out-string like that so i cleaned it up a little

$richtextbox1.Text = $object.psobject.properties | Where-Object{ $_.membertype -eq "noteproperty" } | ForEach-Object{
		"$($_.name) - $($_.value)`r`n"
	}

August 21, 2017 at 7:45 pm

Hey I appreciate the help. I was putting the code in the wrong line. It works, now I have to work on formatting it. Would format-table be better?

August 21, 2017 at 9:11 pm

Not on my computer with studio but I imagine it would not be better off the top of my head. You can always test it out to see if its better as well