Output order


hi,
explain output behavior..

code1: invoke-command -computername "server" -scriptblock {  set-variable verbosepreference -value continue    $a = get-wmiobject win32_bios  write-verbose "line #1"  $a |select serialnumber |ft  write-verbose "line #2"  }  verbose: line #1 serialnumber                     ------------                     4984-1754-7719-9672-7070-0113-43 verbose: line #2


code2:  invoke-command -computername "server" -scriptblock {  set-variable verbosepreference -value continue    $a = get-wmiobject win32_bios  write-verbose "line #1"  $a |select serialnumber  write-verbose "line #2"  }   verbose: line #1 verbose: line #2 serialnumber                     pscomputername      runspaceid                           ------------                     --------------      ----------                           4984-1754-7719-9672-7070-0113-43 server b558dcf4-ca32-438a-9c38-81cb30eb122c

code3: invoke-command -computername "server" -scriptblock { set-variable verbosepreference -value continue $a = get-wmiobject win32_bios write-verbose "line #1" $a write-verbose "line #2" } verbose: line #1 smbiosbiosversion : 090004 manufacturer : american megatrends inc. name : bios date: 03/19/09 22:51:32 ver: 09.00.04 serialnumber : 4984-1754-7719-9672-7070-0113-43 version : vrtual - 3000919 pscomputername : server
verbose: line #2

as u see, when pipe $a variable , go select specified property $a | select ***, output order messed up.
possible fix:   add pipe  |ft      ---  but, why?  because write-host/verbose doesn't wait pipeline output?

i had code in separate scriptblocks, , got result after whole script ends..    when don't add |ft, result show after quit menu completely  (even when code in run-kes function - 2.1 submenu1)

function main { "hlavni menu";do { $menuitem = "1. menu1","2. menu2","x. exit" $selection = menu $menuitem "main menu" switch ($selection) 	{ 	"1. menu1" {do 		{       <# 	        if ($singlepc -eq $null){         new-variable -name singlepc -scope global -value $(read-host "enter dnshostname")           }        #>          $menuitem = "1.1. submenu1","1.x. back" 		$selection = menu $menuitem "1. submenu1" 		switch ($selection) 			{ 			"1.1. submenu1"                 {                 installnx -computername $singlepc                 }             "1.x. back"{remove-variable -name singlepc -scope global -ea silentlycontinue; remove-variable -name cred -scope global -ea silentlycontinue} 			} 		}until ($selection -eq "1.x. back") 	} 	"2. menu2" {do 		{                 $menuitem = "2.1. submenu1","2.x. back" 		$selection = menu $menuitem "2. menu2" 		switch ($selection) 			{ 			"2.1. submenu1"{run-kes}              "2.x. back"{} 			} 		}until ($selection -eq "2.x. back") 		} 	 	"x. exit"{"end"} 	} }until ($selection -eq "x. exit") }

 

write-host documented work way.  not write pipeline.  command writes directly console , cannot redirected.  if take basic course in powershell learn things , how powershell works. save lot of guesswork.

\_(ツ)_/



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...