Powershell script is not providing a correct output.


hi experts,

i have requirement accomplish. need check if specific asp role installed on our windows server machines or not.

below screenshot of role , installed on 1 of servers.

we have 450 machines , manual checking not possible. wrote powershell script , able output wrong. says feature installed on servers not.

post investigation, script running , checks if feature installed in server running script , if installed in above screenshot gives yes servers there in list.

if run script on server in asp role not installed run script against list of servers says not installed in of servers.

below script used test this.

get-content c:\hps_report\server_list.txt | foreach-object {import-module servermanager;get-windowsfeature web-asp}

where - c:\hps_report\server_list.txt list of servers in want check if role installed or not.

below screenshot same. [x] represents role installed [ ] represents role not installed.

below in screenshot showing installed in all, know there server in feature not installed logged on manually , checked same.

below screenshot same.

can 1 please me in this.


gautam.75801

hi guys,

before goes further out of hand, ought work fine (maybe bit of overkill, bored during first 3 minutes of lunch-break):

function get-aspreport { 	[cmdletbinding()] 	param ( 		[parameter(valuefrompipeline = $true, position = 0)] 		[string[]] 		$computername = $env:computername 	) 	 	begin 	{ 		 	} 	process 	{ 		foreach ($computer in $computername) 		{ 			try 			{ 				$result = get-wmiobject win32_optionalfeature -filter "name = 'iis-asp'" -computername $computer -erroraction 'stop' 				$props = @{ 					server = $computer 					success = $true 					hasasp = $result.installstate -eq 1 				} 				new-object psobject -property $props 			} 			catch 			{ 				$props = @{ 					server = $computer 					success = $false 					hasasp = "error: $($_.exception.message)" 				} 				new-object psobject -property $props 			} 		} 	} 	end 	{ 		 	} }  get-content "c:\temp\servers.txt | get-aspreport

i know, know, bit undercommented , significant room improvement, function works fine me.

this notwithstanding, jrv absolutely right, gautam: try learning powershell basics. is, i'm sure sneak in format c: equivalent answer without noticing.

learn windows powershell in month of lunches is great book started, addresses common issue admins face (not enough time).

cheers,
fred


there's no place 127.0.0.1



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file