# Script resource looping through configuration items

**URL:** https://forums.powershell.org/t/script-resource-looping-through-configuration-items/7496
**Category:** DSC
**Created:** [November 9, 2016, 6:14am UTC](https://forums.powershell.org/t/script-resource-looping-through-configuration-items/7496 "2016-11-09T06:14:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![veroli](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@veroli](https://forums.powershell.org/u/veroli)
#### Post date: [November 9, 2016, 6:14am UTC](https://forums.powershell.org/t/script-resource-looping-through-configuration-items/7496/1 "2016-11-09T06:14:54Z")

</div>

Hello All,

Using DSC i am trying to set a number of web server properties in IIS.  
I’ve had a look at the xWebadministration resource and its great and I use it for setting a number of things.  
However, it doesn’t look to me like it supports setting a number of things at a server level rather than site level.  
Ok, to get round that i can create a script resource that does a number of Set-webconfigurationProperty things.  
I have 14 things to set. Now i’ve got it working by breaking it up into multiple script resources, for example,

```
Script IIS_1 {
		GetScript = {
					@{
						GetScript = $GetScript
						SetScript = $SetScript
						TestScript = $TestScript
						Result = (Get-WebConfigurationProperty /system.applicationhost/confighistory -name path.value)
					}
					}
		setScript = {
		Set-WebConfigurationProperty /system.applicationhost/confighistory -name path -value "d:\inetpub\history"
		
		}
		
		Testscript = {
			(Get-WebConfigurationProperty /system.applicationhost/confighistory -name path.value) -eq "d:\inetpub\history"
			}
			
		}
```

Now i can set the next property by creating a new script resource and just copying the above but replacing the configuration property.  
However, i think there must be a better way of achieving this by just looping through each webconfigurationproperty and checking and setting where appropriate. I am struggling though to see how this can be done

regards  
Dan

---

<div class="post-metadata">

### Author: ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)
#### Post date: [November 13, 2016, 6:26pm UTC](https://forums.powershell.org/t/script-resource-looping-through-configuration-items/7496/2 "2016-11-13T18:26:34Z")

</div>

You’re to the point where you should be writing a custom resource, rather than using Script. You’re simply running up against the limitations of what Script was designed to do.

---

<div class="post-metadata">

### Author: ![veroli](https://avatars.discourse-cdn.com/v4/letter/v/ac91a4/32.png) [@veroli](https://forums.powershell.org/u/veroli)
#### Post date: [November 14, 2016, 11:26am UTC](https://forums.powershell.org/t/script-resource-looping-through-configuration-items/7496/3 "2016-11-14T11:26:22Z")

</div>

Thanks Don,

yes i can see that now, I have actually got the functionality I want working, which was the first step.  
I’ve dont this by repeating the script resource for each property i want to set.  
The next step is to now create a custom resource and streamline it all a bit.

thanks  
dan

---

<div class="post-metadata">

### Author: ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)
#### Post date: [May 16, 2024, 9:16pm UTC](https://forums.powershell.org/t/script-resource-looping-through-configuration-items/7496/4 "2024-05-16T21:16:48Z")

</div>


