Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active May 19, 2016 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/51e721e0c5c42c5bda2c39c0d69a07f2 to your computer and use it in GitHub Desktop.
Save guitarrapc/51e721e0c5c42c5bda2c39c0d69a07f2 to your computer and use it in GitHub Desktop.
# sample configuration
configuration Hoge
{
Node localhost
{
File Hoge
{
Ensure = $Node.Ensure
DestinationPath = $Node.DestinationPath
Type = 'Directory'
}
User Hoge
{
UserName = "Hoge"
Password = $Node.Credential
Ensure = 'Present'
Disabled = $false
}
}
}
$cred = (Get-Credential)
# create configurationData
$configurationData = New-Object 'System.Collections.Generic.Dictionary[string, hashtable[]]'
$a = New-Object System.Collections.Hashtable
$a.Add("Credential",$cred)
$a.Add("NodeName", "*")
$a.Add("PSDSCAllowPlainTextPassword", $true)
$a.Add("Ensure", "Present")
$a.Add("DestinationPath","c:\fuga")
$b = New-Object System.Collections.Hashtable
$b.Add("NodeName","localhost")
$configurationData["AllNodes"] = @($a, $b)
Hoge -ConfigurationData $configurationData
Start-DscConfiguration -Wait -Force -Verbose Hoge
class HashtableComparer : System.Collections.IEqualityComparer
{
[bool] Equals([object]$obj, [object]$obj2)
{
return $obj -eq $obj2;
}
[int] GetHashCode([object]$obj)
{
return $obj.ToString().ToLower().GetHashCode();
}
}
$comparer = New-Object HashtableComparer;
# sample configuration
configuration Hoge
{
Node localhost
{
File Hoge
{
Ensure = $Node.Ensure
DestinationPath = $Node.DestinationPath
Type = 'Directory'
}
User Hoge
{
UserName = "Hoge"
Password = $Node.Credential
Ensure = 'Present'
Disabled = $false
}
}
}
$cred = (Get-Credential)
# create configurationData
$configurationData = New-Object 'System.Collections.Generic.Dictionary[string, hashtable[]]'
$a = New-Object System.Collections.Hashtable ($comparer)
$a.Add("Credential",$cred)
$a.Add("NodeName", "*")
$a.Add("PSDSCAllowPlainTextPassword", $true)
$a.Add("Ensure", "Present")
$a.Add("DestinationPath","c:\fuga")
$b = New-Object System.Collections.Hashtable ($comparer)
$b.Add("NodeName","localhost")
$configurationData["AllNodes"] = @($a, $b)
Hoge -ConfigurationData $configurationData
Start-DscConfiguration -Wait -Force -Verbose Hoge
# sample configuration
configuration Hoge
{
Node localhost
{
File Hoge
{
Ensure = $Node.Ensure
DestinationPath = $Node.DestinationPath
Type = 'Directory'
}
User Hoge
{
UserName = "Hoge"
Password = $Node.Credential
Ensure = 'Present'
Disabled = $false
}
}
}
$cred = (Get-Credential)
# create configurationData
$configurationData = New-Object 'System.Collections.Generic.Dictionary[string, hashtable[]]'
$a = @{}
$a.Add("Credential",$cred)
$a.Add("NodeName", "*")
$a.Add("PSDSCAllowPlainTextPassword", $true)
$a.Add("Ensure", "Present")
$a.Add("DestinationPath","c:\fuga")
$b = @{}
$b.Add("NodeName","localhost")
$configurationData["AllNodes"] = @($a, $b)
Hoge -ConfigurationData $configurationData
Start-DscConfiguration -Wait -Force -Verbose Hoge
@guitarrapc
Copy link
Author

Error Message

ConvertTo-MOFInstance : System.InvalidOperationException error processing property 'Password' OF TYPE 'User': Converting and storing encrypted passwords as plain text is not recommended. For more information on securing credentials in MOF file, please 
refer to MSDN blog: http://go.microsoft.com/fwlink/?LinkId=393729
At line:13 char:9
+   User
At line:322 char:16
+     $aliasId = ConvertTo-MOFInstance $keywordName $canonicalizedValue
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessProperty,ConvertTo-MOFInstance
WARNING: The configuration 'Hoge' is loading one or more built-in resources without explicitly importing associated modules. Add Import-DscResource –ModuleName 'PSDesiredStateConfiguration' to your configuration to avoid this message.
Errors occurred while processing configuration 'Hoge'.
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:3705 char:5
+     throw $ErrorRecord
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Hoge:String) [], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessConfiguration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment