DSCResources/cWMISMTPConsumer/cWMISMTPConsumer.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# Fallback message strings in en-US DATA localizedData { # same as culture = "en-US" ConvertFrom-StringData @' GettingConsumerInstance=Getting Consumer Instance named {0}. ConsumerInstanceFound=Consumer Instance named {0} is found. ConsumerInstanceNotFound=Getting Consumer Instance named {0} not found. CreatingConsumerInstance=Creating Consumer Instance named {0}. CreatedConsumerInstance=Created Consumer Instance named {0}. RemovingConsumerInstance=Removing Consumer Instance named {0}. RemovedConsumerInstance=Removed Consumer Instance named {0}. ConsumerExistsNoAction=Consumer Instance named {0} already exists. No action needed. ConsumerDoesNotExistShouldCreate=Consumer Instance named {0} does not exist. It will be created. ConsumerExistsShouldRemove=Consumer Instance named {0} exists. This will be removed. ConsumerDoesNotExistNoAction=Consumer Instance named {0} not found. No action needed. '@ } if (Test-Path $PSScriptRoot\en-us) { Import-LocalizedData LocalizedData -filename WMISMTPConsumer.psd1 } function Get-TargetResource { [CmdletBinding()] [OutputType([Hashtable])] param ( [Parameter(Mandatory)] [string] $Name, [Parameter(Mandatory)] [String] $ToLine, [Parameter(Mandatory)] [String] $FromLine, [Parameter(Mandatory)] [String] $SMTPServer, [Parameter()] [String] $Message, [Parameter()] [String] $Subject, [Parameter()] [String] $CcLine, [Parameter()] [String] $BccLine, [Parameter()] [String] $ReplyToLine ) $Configuration = @{ Name = $Name ToLine = $ToLine FromLine = $FromLine SMTPServer = $SMTPServer } Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) $SMTPEventConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM SMTPEventConsumer WHERE Name='$Name'" if ($SMTPEventConsumer) { Write-Verbose ($localizedData.ConsumerInstanceFound -f $Name) $Configuration.Add('Ensure','Present') $Configuration.Add('Message',$SMTPEventConsumer.Message) $Configuration.Add('Subject',$SMTPEventConsumer.Subject) $Configuration.Add('CcLine',$SMTPEventConsumer.CcLine) $Configuration.Add('BccLine',$SMTPEventConsumer.CcLine) $Configuration.Add('ReplyToLine',$SMTPEventConsumer.CcLine) } else { Write-Verbose ($localizedData.ConsumerInstanceNotFound -f $Name) $Configuration.Add('Ensure','Absent') } return $Configuration } function Set-TargetResource { [CmdletBinding()] param ( [Parameter(Mandatory)] [string] $Name, [Parameter(Mandatory)] [String] $ToLine, [Parameter(Mandatory)] [String] $FromLine, [Parameter(Mandatory)] [String] $SMTPServer, [Parameter()] [String] $Message, [Parameter()] [String] $Subject, [Parameter()] [String] $CcLine, [Parameter()] [String] $BccLine, [Parameter()] [String] $ReplyToLine, [Parameter()] [ValidateSet('Present','Absent')] [string] $Ensure = 'Present' ) if ($Ensure -eq 'Present') { Write-Verbose ($localizedData.CreatingConsumerInstance -f $Name) $Properties = @{ Name = $Name ToLine = $ToLine FromLine = $FromLine SMTPServer = $SMTPServer } if ($Message) { $Properties.Add('Message',$Message) } if ($Subject) { $Properties.Add('Subject',$Subject) } if ($CcLine) { $Properties.Add('CcLine',$CcLine) } if ($BccLine) { $Properties.Add('BccLine',$BccLine) } if ($ReplyToLine) { $Properties.Add('ReplyToLine',$ReplyToLine) } Write-Verbose ($localizedData.CreatedConsumerInstance -f $Name) New-CimInstance -Namespace 'root\subscription' -ClassName 'SMTPEventConsumer' -Property $Properties } else { Write-Verbose ($localizedData.RemovingConsumerInstance -f $Name) Remove-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM SMTPEventConsumer WHERE Name='$Name'" Write-Verbose ($localizedData.RemovedConsumerInstance -f $Name) } } function Test-TargetResource { [CmdletBinding()] [OutputType([Bool])] param ( [Parameter(Mandatory)] [string] $Name, [Parameter(Mandatory)] [String] $ToLine, [Parameter(Mandatory)] [String] $FromLine, [Parameter(Mandatory)] [String] $SMTPServer, [Parameter()] [String] $Message, [Parameter()] [String] $Subject, [Parameter()] [String] $CcLine, [Parameter()] [String] $BccLine, [Parameter()] [String] $ReplyToLine, [Parameter()] [ValidateSet('Present','Absent')] [string] $Ensure = 'Present' ) Write-Verbose ($localizedData.GettingConsumerInstance -f $Name) $SMTPEventConsumer = Get-CimInstance -Namespace 'root\subscription' -Query "SELECT * FROM SMTPEventConsumer WHERE Name='$Name'" if ($Ensure -eq 'Present') { if ($SMTPEventConsumer) { Write-Verbose ($localizedData.ConsumerExistsNoAction -f $Name) return $true } else { Write-Verbose ($localizedData.ConsumerDoesNotExistShouldCreate -f $Name) return $false } } else { if ($SMTPEventConsumer) { bose ($localizedData.ConsumerExistsShouldRemove -f $Name) return $false } else { Write-Verbose ($localizedData.ConsumerDoesNotExistNoAction -f $Name) return $true } } } |