0

I am trying to display whether the AppPool for IIS is started or not. By default it will display all AppPool State.

But if a parameter -EA (--exceptionAppPool) is passed while running the script it will not consider the status of those AppPool.

I am somehow stuck with the else{} statement when -EA is passed. Not sure how to remove the list of array passed in -EA from being considered in Get-WebAppPoolState method

param([String[]]$EA) if (-Not ($ParamAvailable = $PSBoundParameters.ContainsKey('EA'))){ $ApplicationPoolsState = Get-WebAppPoolState | % { return @{($_.itemxpath -split ("'"))[1]="$($_.value)" } } | % getEnumerator | % { if ($_.value -ne "Started"){ $statuses.critical += $_.key } else{ $statuses.ok += $_.key } } } else{ #----I want to exclude the Keys which is present in -EA array ? #----The example of -EA is .NET v4.5,.NET v4.5 Classic,DefaultAppPool $ApplicationPoolsState = Get-WebAppPoolState | % { return @{($_.itemxpath -split ("'"))[1]="$($_.value)" } } for ($i=0; $i -lt $EA.length; $i++){ $ApplicationPoolsState = $ApplicationPoolsState.Remove($EA[$i]) } $ApplicationPoolsState = $ApplicationPoolsState | % getEnumerator | % { if ($_.value -ne "Started"){ $statuses.critical += $_.key } else{ $statuses.ok += $_.key } } 

script will run like .\check_appPool.ps1 -EA .NET v4.5,.NET v4.5 Classic,DefaultAppPool

Got error

Exception calling "Remove" with "1" argument(s): "Collection was of a fixed size."

How do I exclude those from being checked in the else statement

3
  • One way to remove an object from a fixed-size array is to create a new array that includes only selected objects from the original array. There is a solution to this kind of problem in this blog, you can refer to it: info.sapien.com/index.php/scripting/scripting-tips-tricks/… Commented Mar 10, 2021 at 2:16
  • Thank You Very much. That solved my problem Commented Mar 10, 2021 at 4:56
  • Congratulations! I will post it as a reply, and you can mark it as an answer. Commented Mar 10, 2021 at 4:58

1 Answer 1

1

One way to remove an object from a fixed-size array is to create a new array that includes only selected objects from the original array. There is a solution to this kind of problem in this blog, you can refer to it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.