Skip to content

Instantly share code, notes, and snippets.

@jstangroome jstangroome/demo.ps1
Created Sep 24, 2013

Embed
What would you like to do?
Demo script for my PowerShell v4 Desired State Configuration presentation at the Sydney DevOps user group in September 2013
########
Configuration SydDevOpsDemo {
param (
[Parameter(Mandatory)]
[string]
$LogMessage
)
Node localhost {
WindowsFeature TelnetClient {
Ensure = 'Present'
Name = 'Telnet-Client'
}
Log LogBefore {
Message = 'Before LogMessage demo'
}
Log LogMessage {
Message = $LogMessage
DependsOn = '[Log]LogBefore'
}
Log LogAfter {
Message = 'After LogMessage demo'
DependsOn = '[Log]LogMessage'
}
}
}
SydDevOpsDemo -LogMessage "Convert to MOF at $(Get-Date)"
& notepad SydDevOpsDemo\localhost.mof
$AnalyticLog = Get-WinEvent -ListLog Microsoft-Windows-DSC/Analytic
$AnalyticLog.IsEnabled = $true
$AnalyticLog.SaveChanges()
Start-DscConfiguration -Path SydDevOpsDemo -Wait -Verbose
Get-WinEvent -LogName Microsoft-Windows-DSC/Analytic -Oldest | ogv
wevtutil clear-log Microsoft-Windows-DSC/Analytic
########
Test-DscConfiguration
Get-DscConfiguration
Uninstall-WindowsFeature -Name Telnet-Client
Test-DscConfiguration
Get-DscConfiguration
Restore-DscConfiguration
Test-DscConfiguration
Get-DscConfiguration
Get-WindowsFeature -Name Telnet-Client
########
Get-DscLocalConfigurationManager
Configuration FileSharePull {
LocalConfigurationManager {
RefreshMode = 'Pull' # Push
DownloadManagerName = 'DSCFileDownloadManager'
DownloadManagerCustomData = @{ SourcePath = '\\DevOpsDSC\Share\' }
ConfigurationId = 'UseSystemUUID'
ConfigurationMode = 'ApplyAndMonitor' # ApplyOnly, ApplyAndAutoCorrect
ConfigurationModeFrequencyMins = 30
RebootNodeIfNeeded = $false
#AllowModuleOverwrite
#CertificateID
#Credential
}
}
FileSharePull
& notepad FileSharePull\localhost.meta.mof
Set-DscLocalConfigurationManager -Path FileSharePull
Get-DscLocalConfigurationManager
Get-FileHash -Path SydDevOpsDemo\*.mof <# -Algorithm SHA1 #>
Get-FileHash -Path SydDevOpsDemo\*.mof | % { Set-Content -Path "$($_.Path).checksum" -Value $_.Hash -Encoding Ascii }
Get-ChildItem -Path SydDevOpsDemo
Get-ScheduledTask -TaskPath '\Microsoft\Windows\Desired State Configuration\' | Tee-Object -Variable Tasks
$Tasks.Actions
########
Get-ChildItem -Path $env:SystemRoot\System32\Configuration
########
Get-DscResource
Get-DscResource -Name User -Syntax
########
Configuration MultiNodeDemo {
Node DevOpsDSC {
WindowsFeature TelnetClient {
Ensure = 'Present'
Name = 'Telnet-Client'
}
}
Node DevOpsWeb {
WindowsFeature TelnetClient {
Ensure = 'Present'
Name = 'Telnet-Client'
}
WindowsFeature WebServer {
Ensure = 'Present'
Name = 'Web-Server'
}
}
}
########
Configuration ConfigurationDataDemo {
Node $AllNodes.NodeName {
WindowsFeature TelnetClient {
Ensure = 'Present'
Name = 'Telnet-Client'
}
Log LogMessage {
Message = "Installed telnet client: $($Node.LogMessage)"
DependsOn = '[WindowsFeature]TelnetClient'
}
}
Node $AllNodes.Where({ $_.NodeRole -eq 'Web' }).NodeName {
WindowsFeature WebServer {
Ensure = 'Present'
Name = 'Web-Server'
}
}
}
$Nodes = @{
AllNodes = @(
@{
NodeName = '*'
LogMessage = 'Message for all nodes'
#PSDscAllowPlainTextPassword = $true
}
@{
NodeName = 'DevOpsDSC.devops.intranet'
NodeRole = 'PullServer'
}
@{
NodeName = 'DevOpsWeb.devops.intranet'
NodeRole = 'Web'
LogMessage = 'Message for DevOpsWeb'
}
)
}
ConfigurationDataDemo -ConfigurationData $Nodes
Start-DscConfiguration ConfigurationDataDemo -Wait -Verbose
########
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.