-
Notifications
You must be signed in to change notification settings - Fork 1
/
PushMoftoPull.ps1
47 lines (41 loc) · 1.45 KB
/
PushMoftoPull.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#requires -version 5.1
Function Push-MofToPullServer {
[cmdletbinding()]
Param(
[Parameter(Mandatory,Position=0,ValueFromPipelineByPropertyName)]
[ValidatePattern({\.mof$})]
[string]$FullName,
#the name of your pull server
[string]$PullServer = "SRV2"
)
Begin {
Write-Verbose "Creating a PSSession to $Pullserver"
$sess = New-PSSession -ComputerName $PullServer
}
Process {
Write-Verbose "Processing $fullname"
$filename = Split-path $fullname -Leaf
$computername = $filename.split(".")[0]
Write-Verbose "Getting configuration ID from $computername"
$configid = (Get-DscLocalConfigurationManager -CimSession $computername).ConfigurationID
if ($configid) {
$new = $fullname.replace($Computername,$configID)
Write-Verbose "Renaming to $new"
rename-item $fullname $new -Force
Write-Verbose "Adding a checksum"
New-DscChecksum -Path $new -force
Write-Verbose "copy the mof and checksum to the pull server"
write-verbose $new
Copy-Item -Path $new -Destination "C:\program files\windowspowershell\dscservice\configuration" -ToSession $sess
write-verbose "$new.checksum"
Copy-Item -Path "$new.checksum" -Destination "C:\program files\windowspowershell\dscservice\configuration" -ToSession $sess
}
else {
Write-Warning "$Computername does not appear to be configured for pull"
}
}
End {
Write-Verbose "Removing PSSession"
$sess| Remove-PSsession
}
}