I want to update Anonymous authentication user and password from PowerShell DSC. I wrote below script resource to update that. I have issue where to store the Service account user name and password. I am passing [blockquote]$ServiceCred[/blockquote] variable as argument to the configuration.
Script UpdateServiceUserAnonymous { GetScript = {return $null } SetScript = { $PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR[$ServiceCred.Password] $getPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto[$PasswordPointer] start-sleep -Seconds 5 Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Website'` -filter "system.webServer/security/authentication/anonymousAuthentication" -name "userName" -value $ServiceCred.UserName Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Website'` -filter "system.webServer/security/authentication/anonymousAuthentication" -name "password" -value $getPassword } TestScript = { $PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR[$ServiceCred.Password] $getPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto[$PasswordPointer] Get-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Website' -filter "system.webServer/security/authentication/anonymousAuthentication" -Name "userName" | %{$_.Value} | Set-Variable userName Get-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Martini' -filter "system.webServer/security/authentication/anonymousAuthentication" -Name "password" | %{$_.Value} | Set-Variable password if[$userName -eq $ServiceCred.UserName -and $password -eq $getPassword] {$True} else {$false} } }
I understand that this configuration argument value will be available only in compilation time(creation of MOF file) and not in run time (applying MOF file). Is there any way to store and refer this values from MOF file to script resource?
Could you please help me to solve this issue?
Thanks in advance.