DSCTest/UrlAcls/UrlAcls.psm1
[DscResource()] class UrlAcls { [DscProperty(Key)] [string]$Name [DscProperty()] [string[]]$Protocol [DscProperty()] [string]$HostName [DscProperty()] [string]$SecurityContext [DscProperty()] [int[]]$Port [DscProperty()] [string]$Path = "/" [DscProperty()] [bool]$Ensure [UrlAcls]Get(){ return $this } [bool]Test(){ $result = $true $urlAcls = Get-UrlAcl -Port $this.Port -HostName $this.HostName -Protocol $this.Protocol if($this.Port -isnot [System.Array]){ $this.Port = @($this.Port) } foreach($p in $this.Port) { $url = $this.FormatUrl($this.Protocol, $this.HostName, $this.Port, $this.Path) $acl = $urlAcls | Where-Object { $_.Port -eq $p } if($null -eq $acl){ Write-Host "No urlacl found for $url" $result = false; continue; } if($null -eq ($url.users | Where-Object { $_.Name -eq $this.SecurityContext })){ Write-Host "SecurityContext not set on: $url" $result = $false continue; } } return $result; } [void]Set(){ foreach($p in $this.Port) { $acl = Get-UrlAcl -Url (this.FormatUrl -Protocol $this.Protocol -HostName $this.HostName -Port $this.Port -Port $this.Port) if($null -ne $acl){ $acl | Remove-UrlAcl } New-UrlAcl -Protocol $this.Protocol -HostName $this.HostName -Port $this.Port -Path $this.Path -SecurityContext $this.SecurityContext } } [string]FormatUrl([string]$protocol, [string]$hostName, [string]$port, [string]$path){ return "${protocol}://${hostName}:$port$path" } } |