forked from proxb/PoshWSUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PoshWSUS.psm1
92 lines (81 loc) · 2.67 KB
/
PoshWSUS.psm1
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<#
To Do:
1. New-PSWSUSLocalPackage
2. Get-PSWSUSLocalPackage
3. Get-PSWSUSUpdateApproval
4. Set-PSWSUSConfiguration
5. New-PSWSUSClient
#>
# Set Script Path
$ScriptPath = Split-Path $MyInvocation.MyCommand.Path
# Ensure necessary Registry Settings
if (-not (Test-Path "HKLM:\SOFTWARE\Microsoft\Update Services\Server\Setup"))
{
# Push to registry node, so New-ItemProperty has the correct PropertyTypes
Push-Location "HKLM:\"
# Create Container
New-Item "HKLM:\SOFTWARE\Microsoft\Update Services\Server\Setup" -Force | Out-Null
# Keys necessary for WSUS libraries to function
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Update Services\Server\Setup" -Name "ConfigurationSource" -PropertyType "DWORD" -Value 0 -ErrorAction 'Stop' | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Update Services\Server\Setup" -Name "EnableRemoting" -PropertyType "DWORD" -Value 1 -ErrorAction 'Stop' | Out-Null
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Update Services\Server\Setup" -Name "TargetDir" -PropertyType "String" -Value "$($env:ProgramFiles)\Update Services\" -ErrorAction 'Stop' | Out-Null
# Pop back to where you were
Pop-Location
}
# Load libraries (32bit)
if ([System.IntPtr]::Size -eq 4)
{
try
{
# Try loading properly installed Assemblies first
Add-Type -AssemblyName "Microsoft.UpdateServices.Administration" -ErrorAction Stop
}
catch
{
# Try loading brought along Assemblies second
Add-Type -Path "$ScriptPath\Libraries\x86\Microsoft.UpdateServices.Administration.dll" -ErrorAction 'SilentlyContinue'
}
}
# Load libraries (64bit)
else
{
try
{
# Try loading properly installed Assemblies first
Add-Type -AssemblyName "Microsoft.UpdateServices.Administration" -ErrorAction Stop
}
catch
{
# Try loading brought along Assemblies second
Add-Type -Path "$ScriptPath\Libraries\x64\Microsoft.UpdateServices.Administration.dll" -ErrorAction 'SilentlyContinue'
}
}
# Validate Library
if ( -not ( [appdomain]::CurrentDomain.GetAssemblies() | %{ $_.GetName() } | Where-Object { $_.Name -eq "Microsoft.UpdateServices.Administration" } ) )
{
Write-Warning "WSUS Libraries could not be loaded"
break
}
# Load Functions
Try
{
Get-ChildItem "$ScriptPath\Scripts" | Select-Object -ExpandProperty FullName | ForEach-Object {
$Function = Split-Path $_ -Leaf
. $_
}
}
Catch
{
Write-Warning ("{0}: {1}" -f $Function,$_.Exception.Message)
Continue
}
if (-not ($DefaultWsusPort))
{
$global:DefaultWsusPort = 8530
}
<#
TODO:
$ExecutionContext.SessionState.Module.OnRemove{
Remove-Variable -Name Wsus -Scope Global -Force
}
#>