Streamwriter output different as Out-File


hello,

i have script write value's file out-file:

		"<<<local>>>" | out-file $nagioslogfile -append -encoding ascii  		$export_w3svc | out-file $nagioslogfile -append -encoding ascii  		$export_app_pool | out-file $nagioslogfile -append -encoding ascii  		$export_iis_site | out-file $nagioslogfile -append -encoding ascii  		$export_nettcp_8093 | out-file $nagioslogfile -append -encoding ascii  		$export_iis_read_file | out-file $nagioslogfile -append -encoding ascii  		"" | out-file $nagioslogfile -append -encoding ascii

the output  @ file is:

<<<local>>>
0 polyop_service_w3svc - der w3svc service running
0 polyop_applpool_zwacmesbghcon_client - application pool polyop_applpool_zwacmesbghcon_client running
0 polyop_applpool_zwacmesbghcon_server - application pool polyop_applpool_zwacmesbghcon_server running
0 polyop_website_zwacmesbghcon_client - iis site polyop_website_zwacmesbghcon_client running
0 polyop_website_zwacmesbghcon_server - iis site polyop_website_zwacmesbghcon_server running
0 polyop_net_tcp_port_8093_more_then_one_time - tcp port 8093 set once @ server
0 polyop_read_file_emsdeploy_folder - ems deploy directory can read server

the other script methode - streamwriter:

		$sw = new-object system.io.streamwriter($nagioslogfile, "true", [system.text.encoding]::ascii)  		$sw.writeline("<<<local>>>")  		$sw.writeline($export_w3svc)  		$sw.writeline($export_app_pool)  		$sw.writeline($export_iis_site)  		$sw.writeline($export_nettcp_8093)  		$sw.writeline($export_iis_read_file)  		$sw.writeline("")  		$sw.close()

the output is:

<<<local>>>
0 polyop_service_w3svc - der w3svc service running
system.object[]
system.object[]
0 polyop_net_tcp_port_8093_more_then_one_time - tcp port 8093 set once @ server
0 polyop_read_file_emsdeploy_folder - ems deploy directory can read server

the values for $export_app_pool and $export_iis_site arrays - script part:

$datetime = (get-date -format yyyy.mm.dd-hh:mm:ss)  							$nagios_state = "0"  							$servicename = "applpool_"+$item.name  							$export_app_pool1 = "$nagios_state polyop_$servicename - application pool polyop_$servicename running"  							$export_app_pool += $export_app_pool1  							$export_app_pool = @($export_app_pool)

what problem?

i hope can me,


thanks horst moss 2007 farm; moss 2010 farm; tfs 2010; iis 7.5

out-file automatically puts objects through powershell's formatting cmdlets if they're not strings.  make other approaches work (such add-content or streamwriter example), you'd typically want pass objects out-string first, pass resulting strings on other command:

$sw.writeline(($export_w3svc | out-string))



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group