Check out: http://soreddymanjunath.blogspot.in/2014/07/collection-was-modified-enumeration.html
Here is anonther example for the same problem
if($web.IsMultilingual -eq $true ) { foreach($cul in $web.SupportedUICultures) { if($cul.LCID -ne $webCul.LCID -and $cul.LCID -ne "1033") { $web.RemoveSupportedUICulture($cul) } } $web.Update() }
the first time it goes through the foreach loop, it will remove the supported culture for frist time, when it comes to the loop for the second iteration, then it will throw you an exception "Collection has been changed, the enumeration operation cannot be performed",
The solution to the above problem is to save the values changed in the Arraylist and try to change, which will fix the problem. Here I save the Arraylist called enumcul and inserting values into it and changing it ...
$enumcul=New-Object Collections.ArrayList $i=0 if($web.IsMultilingual -eq $true ) { foreach($cul in $web.SupportedUICultures) { if($cul.LCID -ne $webCul.LCID -and $cul.LCID -ne "1033") { $enumcul.Insert($i, $cul) $i=$i+1 } } foreach( $k in $enumcul) { $web.RemoveSupportedUICulture($k) $web.Update() }
Soreddy manjunath
source share