$richTextBox

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
obrienc
Posts: 59
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Mon Dec 12, 2016 10:58 am

$richTextBox

Post by obrienc »

I am having trouble getting $report to output to the richtextbox. If I put a test "teststring" instead of the $report object it is okay. Not sure what I am missing. the file has 2 VM names in it.

Code: Select all

$form1_Load={
	Import-Module VirtualMachineManager
	$global:vmmsrv = "DC1SC1","DC2SC1"
}

$buttonFile_Click={
	$openfiledialog1.ShowDialog()
	foreach ($dc in $global:vmmsrv)
	{
		$file = Get-Content -Path $openfiledialog1.FileName
		$global:vm = foreach ($f in $file)
		{
			Get-SCVirtualMachine -Name $f -VMMServer $dc | where { $_.Name -match $t }
		}
	}
}

$button1_Click={
	$report = foreach ($pc in $global:vm)
	{
		New-SCVMCheckpoint -VM $pc -Description ([Environment]::UserDomainName + "\" + [Environment]::UserName) -Name "Pre-Patch"
	}
	$richtextbox1.Text = $report|Select *|FT -AutoSize|Out-String
}

User avatar
obrienc
Posts: 59
Joined: Mon Dec 12, 2016 10:58 am

Re: $richTextBox

Post by obrienc »

The only action I did on the richtextbox is Apply Property Set Apply Console Font

jvierra
Posts: 14444
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: $richTextBox

Post by jvierra »

Are you sure there is data?

User avatar
obrienc
Posts: 59
Joined: Mon Dec 12, 2016 10:58 am

Re: $richTextBox

Post by obrienc »

No, what do I need to read up on to see if the variable is populated?

This is the short script I wrote and worked it into a GUI.

Code: Select all

$vmmsrv = "systemcenter"
$list = "DSC"

$vm = foreach ($v in $vmmsrv)
{
	foreach ($t in $list)
	{
		Get-SCVirtualMachine -VMMServer $v | where { $_.Name -match $t }
	}
}

$x = @()
foreach ($pc in $vm)
{
    New-SCVMCheckpoint -VM $pc -Description ([Environment]::UserDomainName + "\" + [Environment]::UserName) -Name "Pre-Patch"
    $x += New-Object -TypeName System.Management.Automation.PSObject -Property @{
			    Name	 = $pc.Name
			    Started  = $pc.MostRecentTask.StartTime
			    Ended    = $pc.MostRecentTask.EndTime
			    Status 	 = $pc.MostRecentTask.Status
		    }
}$x|Select Name,Status,Started,Ended|fl *

jvierra
Posts: 14444
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: $richTextBox

Post by jvierra »

Run it under the debugger and inspect the variables.

User avatar
obrienc
Posts: 59
Joined: Mon Dec 12, 2016 10:58 am

Re: $richTextBox

Post by obrienc »

I ran the debug mode what do I need to do to see what's in the variable?

I looked through some of these but couldn't catch on to what they were doing for my script.
https://www.sapien.com/blog/2015/09/08/ ... -handlers/

jvierra
Posts: 14444
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: $richTextBox

Post by jvierra »

The "Product Manual" with instructions is on the "Help" menu panel at the far left.

User avatar
obrienc
Posts: 59
Joined: Mon Dec 12, 2016 10:58 am

Re: $richTextBox

Post by obrienc »

I put breakpoints on each line and added a few pieces of text before the command and after. I also added $x to the CheckPoint command. When I look at all variables under Variables in the debug console $x doesn't show up. Under $richtextbox "Begin" is listed but not "End". The checkpoint works on the VM and I verified I can revert to the previous snapshot.

Code: Select all

$button1_Click = {
	$richtextbox1.Text = "Begin"
	foreach ($f in $global:vm)
	{
		$x = New-SCVMCheckpoint -VM $f -Description ([Environment]::UserDomainName + "\" + [Environment]::UserName) -Name "Pre-Patch"|Out-String
	}
	$richtextbox1.Text = "End"
}

jvierra
Posts: 14444
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: $richTextBox

Post by jvierra »

Because $x is null. Now you get to debug your command. break should stop on "$x = <command>" but only if $global:vm is a collection with at least one member. Break and inspect $global:vm.

User avatar
obrienc
Posts: 59
Joined: Mon Dec 12, 2016 10:58 am

Re: $richTextBox

Post by obrienc »

$x isn't showing up in "Show all variables". $global:vm is returning the correct names from the file and then getting the virtual machine info from vmm correctly.
in the debug console if I right click on the $x statement and execute selection in debug console it shows this, but i cant find a | Out-Default anywhere

>>
At line:1 char:4
+ | Out-Default
+ ~
An empty pipe element is not allowed.

Locked