Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

A self documenting DSC Configuration wich contains all Resources

$
0
0

One funny thing with PowerShell is allways: It can document himself.
Inspired by Steven Murawskis video on Desired State Configuration (DSC) I have done a full Blowen full self documenting DSC Configuration:
Not perfect but it works for the first shot...
This code:

$ConfigOut = @"
Configuration Name {
    param(
        [String]`$Parameter1
    )

    
    # One can evaluate expression
    # E.g.: `$AllNodes.Where("Role -eq Web").NodeName
    Node ('Node1','Node2','Node3') {   
$(

Get-DscResource | ForEach {
    
    "`n`t`t# Call the '$($_.Name)' Resource the Provider`n""`t`t$($_.Name) FriendlyName {`n`n""`t`t`t# Possible Resource Options`n"
    $Ofs = "','"
    $_.Properties | ForEach {"`t`t`t$($_.Name) = '$($_.Values)' # Type:$($_.PropertyType) $(If($_.IsMandatory) {'is Mandatory!'})`n" 
    }
    $Ofs = ' '"`t`t}`n"
}
)
    } # end Node
} # end Configuration"@

$ConfigOut

Produces this output on my Windows 8.1:

Configuration Name {
    param(
        [String]$Parameter1
    )

    
    # One can evaluate expression
    # E.g.: $AllNodes.Where("Role -eq Web").NodeName
    Node ('Node1','Node2','Node3') {   

		# Call the 'File' Resource the Provider
 		File FriendlyName {

 			# Possible Resource Options
 			DestinationPath = '' # Type:[string] is Mandatory!
 			Attributes = 'Archive','Hidden','ReadOnly','System' # Type:[string[]] 
 			Checksum = 'CreatedDate','ModifiedDate','SHA-1','SHA-256','SHA-512' # Type:[string] 
 			Contents = '' # Type:[string] 
 			Credential = '' # Type:[PSCredential] 
 			DependsOn = '' # Type:[string[]] 
 			Ensure = 'Absent','Present' # Type:[string] 
 			Force = '' # Type:[bool] 
 			MatchSource = '' # Type:[bool] 
 			Recurse = '' # Type:[bool] 
 			SourcePath = '' # Type:[string] 
 			Type = 'Directory','File' # Type:[string] 
 		}
 
		# Call the 'Archive' Resource the Provider
 		Archive FriendlyName {

 			# Possible Resource Options
 			Destination = '' # Type:[string] is Mandatory!
 			Path = '' # Type:[string] is Mandatory!
 			Checksum = 'CreatedDate','ModifiedDate','SHA-1','SHA-256','SHA-512' # Type:[string] 
 			DependsOn = '' # Type:[string[]] 
 			Ensure = 'Absent','Present' # Type:[string] 
 			Force = '' # Type:[bool] 
 			Validate = '' # Type:[bool] 
 		}
 
		# Call the 'Environment' Resource the Provider
 		Environment FriendlyName {

 			# Possible Resource Options
 			Name = '' # Type:[string] is Mandatory!
 			DependsOn = '' # Type:[string[]] 
 			Ensure = 'Absent','Present' # Type:[string] 
 			Path = '' # Type:[bool] 
 			Value = '' # Type:[string] 
 		}
 
		# Call the 'Group' Resource the Provider
 		Group FriendlyName {

 			# Possible Resource Options
 			GroupName = '' # Type:[string] is Mandatory!
 			Credential = '' # Type:[PSCredential] 
 			DependsOn = '' # Type:[string[]] 
 			Description = '' # Type:[string] 
 			Ensure = 'Absent','Present' # Type:[string] 
 			Members = '' # Type:[string[]] 
 			MembersToExclude = '' # Type:[string[]] 
 			MembersToInclude = '' # Type:[string[]] 
 		}
 
		# Call the 'Log' Resource the Provider
 		Log FriendlyName {

 			# Possible Resource Options
 			Message = '' # Type:[string] is Mandatory!
 			DependsOn = '' # Type:[string[]] 
 		}
 
		# Call the 'Package' Resource the Provider
 		Package FriendlyName {

 			# Possible Resource Options
 			Name = '' # Type:[string] is Mandatory!
 			Path = '' # Type:[string] is Mandatory!
 			ProductId = '' # Type:[string] is Mandatory!
 			Arguments = '' # Type:[string] 
 			Credential = '' # Type:[PSCredential] 
 			DependsOn = '' # Type:[string[]] 
 			Ensure = 'Absent','Present' # Type:[string] 
 			LogPath = '' # Type:[string] 
 			ReturnCode = '' # Type:[UInt32[]] 
 		}
 
		# Call the 'Registry' Resource the Provider
 		Registry FriendlyName {

 			# Possible Resource Options
 			Key = '' # Type:[string] is Mandatory!
 			ValueName = '' # Type:[string] is Mandatory!
 			DependsOn = '' # Type:[string[]] 
 			Ensure = 'Absent','Present' # Type:[string] 
 			Force = '' # Type:[bool] 
 			Hex = '' # Type:[bool] 
 			ValueData = '' # Type:[string[]] 
 			ValueType = 'Binary','Dword','ExpandString','MultiString','Qword','String' # Type:[string] 
 		}
 
		# Call the 'Script' Resource the Provider
 		Script FriendlyName {

 			# Possible Resource Options
 			GetScript = '' # Type:[string] is Mandatory!
 			SetScript = '' # Type:[string] is Mandatory!
 			TestScript = '' # Type:[string] is Mandatory!
 			Credential = '' # Type:[PSCredential] 
 			DependsOn = '' # Type:[string[]] 
 		}
 
		# Call the 'Service' Resource the Provider
 		Service FriendlyName {

 			# Possible Resource Options
 			Name = '' # Type:[string] is Mandatory!
 			BuiltInAccount = 'LocalService','LocalSystem','NetworkService' # Type:[string] 
 			Credential = '' # Type:[PSCredential] 
 			DependsOn = '' # Type:[string[]] 
 			StartupType = 'Automatic','Disabled','Manual' # Type:[string] 
 			State = 'Running','Stopped' # Type:[string] 
 		}
 
		# Call the 'User' Resource the Provider
 		User FriendlyName {

 			# Possible Resource Options
 			UserName = '' # Type:[string] is Mandatory!
 			DependsOn = '' # Type:[string[]] 
 			Description = '' # Type:[string] 
 			Disabled = '' # Type:[bool] 
 			Ensure = 'Absent','Present' # Type:[string] 
 			FullName = '' # Type:[string] 
 			Password = '' # Type:[PSCredential] 
 			PasswordChangeNotAllowed = '' # Type:[bool] 
 			PasswordChangeRequired = '' # Type:[bool] 
 			PasswordNeverExpires = '' # Type:[bool] 
 		}
 
		# Call the 'WindowsFeature' Resource the Provider
 		WindowsFeature FriendlyName {

 			# Possible Resource Options
 			Name = '' # Type:[string] is Mandatory!
 			Credential = '' # Type:[PSCredential] 
 			DependsOn = '' # Type:[string[]] 
 			Ensure = 'Absent','Present' # Type:[string] 
 			IncludeAllSubFeature = '' # Type:[bool] 
 			LogPath = '' # Type:[string] 
 			Source = '' # Type:[string] 
 		}
 
		# Call the 'WindowsProcess' Resource the Provider
 		WindowsProcess FriendlyName {

 			# Possible Resource Options
 			Arguments = '' # Type:[string] is Mandatory!
 			Path = '' # Type:[string] is Mandatory!
 			Credential = '' # Type:[PSCredential] 
 			DependsOn = '' # Type:[string[]] 
 			Ensure = 'Absent','Present' # Type:[string] 
 			StandardErrorPath = '' # Type:[string] 
 			StandardInputPath = '' # Type:[string] 
 			StandardOutputPath = '' # Type:[string] 
 			WorkingDirectory = '' # Type:[string] 
 		}

    } # end Node
} # end Configuration

Watch:

Steven Murawskis and Joel Bennett: Video on Desired State Configuration (DSC)
http://www.youtube.com/watch?v=EN8eJA9rpXw

hope this helps....


PowerShell Artikel, Buchtipps und kostenlose PowerShell Tutorials + E-Books
auf der deutschsprachigen PowerShell Community

Mein 21 Teiliger PowerShell Video Grundlehrgang
Deutsche PowerShell Videos auf Youtube
Folge mir auf:
Twitter | Facebook | Google+


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>