Last active
September 1, 2016 21:26
-
-
Save mmarseglia/6919f327642a811c585a3f7cca1b17fb to your computer and use it in GitHub Desktop.
powershell desired state configuration deploy modules for download and do a push to remote node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to get a remote host to pull modules when pushing a Desired State Configuration | |
# Package up required PowerShell modules | |
# Place them in the required directory on the pull server | |
# Execute DSC in 'push' mode | |
# Remote host will pull modules from configured DSC repository | |
# | |
# todo: DRY. Can we use the array $modules when invoking the Import-DscResource cmdlet? | |
# | |
Configuration SmbServer | |
{ | |
Import-DscResource -ModuleName xNetworking,xSmbShare,PSDesiredStateConfiguration | |
Node MS1 | |
{ | |
xFirewall SMB-In | |
{ | |
Name = 'SMB-In' | |
Action = 'Allow' | |
Description = 'Allow File and Print Sharing' | |
Direction = 'Inbound' | |
Enabled = 'True' | |
Ensure = 'Present' | |
LocalPort = '443' | |
Protocol = 'TCP' | |
Profile = @('Domain', 'Private') | |
} | |
xFirewall SMB-Out | |
{ | |
Name = 'SMB-Out' | |
Action = 'Allow' | |
Description = 'Allow File and Print Sharing' | |
Direction = 'Outbound' | |
Enabled = 'True' | |
Ensure = 'Present' | |
LocalPort = '443' | |
Protocol = 'TCP' | |
Profile = @('Domain', 'Private') | |
} | |
File DirectorySource | |
{ | |
Ensure = 'Present' | |
Type = 'Directory' | |
DestinationPath = 'C:\\FileShare' | |
SourcePath = '\\\\pull\\pshell\\labs' | |
Recurse = $True | |
MatchSource = $True | |
Checksum = 'ModifiedDate' | |
DependsOn = @('[xFirewall]SMB-In', '[xFirewall]Smb-Out') | |
} | |
xSmbShare CreateShare | |
{ | |
Name = 'SourceShare' | |
Path = 'C:\\FileShare' | |
ReadAccess = 'Everyone' | |
Ensure = 'Present' | |
DependsOn = '[File]DirectorySource' | |
} | |
} | |
} | |
$modules = @(‘xNetworking’, ‘xSmbShare’) | |
$destination = 'C:\Program Files\WindowsPowerShell\DscService\Modules' | |
foreach ($module in $modules) { | |
$version = (Get-Module -ListAvailable $module).Version.ToString() | |
$source = (Get-Module -ListAvailabe $module).ModuleBase | |
Compress-Archive -Path "$source\*" -DestinationPath "$destination\$module_$version.zip" -Verbose -Force | |
New-DscChecksum -Path "$destination\$module_$version.zip" -Force | |
} | |
SmbServer | |
SmbServerStart-DscConfiguration -Wait -Verbose -Force .\SmbServer -CimSession MS1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment