This repository has been archived by the owner on Jul 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
setupSnapIn.ps1
81 lines (74 loc) · 2.13 KB
/
setupSnapIn.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
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
param([switch]$force)
function Is-SnapinRegistered()
{
$registered = $false;
if ( $null -ne (Get-PSSnapIn -Registered | where { $_.Name -eq "iControlSnapIn" } ) )
{
$registered = $true;
}
$registered;
}
function Install-Snapin()
{
param(
[string]$assembly = $null
);
foreach ($platform in ("", "64") )
{
Write-Host "Registering $assembly on platform '$platform'";
if ( Test-Path "$env:windir\Microsoft.Net\Framework${platform}\v4.0.30319" )
{
Write-Host '.NET v4 present'
$installUtil = "$env:windir\Microsoft.Net\Framework${platform}\v4.0.30319\installUtil.exe";
}
ElseIf ( Test-Path "$env:windir\Microsoft.Net\Framework${platform}\v3.5" )
{
Write-Host '.NET v3.5 present'
$installUtil = "$env:windir\Microsoft.Net\Framework${platform}\v3.5\installUtil.exe";
}
ElseIf ( Test-Path "$env:windir\Microsoft.Net\Framework${platform}\v3.0" )
{
Write-Host '.NET v3.0 present'
$installUtil = "$env:windir\Microsoft.Net\Framework${platform}\v3.0\installUtil.exe";
}
ElseIf ( Test-Path "$env:windir\Microsoft.Net\Framework${platform}\v2.0.507272" )
{
Write-Host '.NET v2 present'
$installUtil = "$env:windir\Microsoft.Net\Framework${platform}\v2.0.50727\installUtil.exe";
}
Else
{
Write-Host 'Could not find any version of .NET >=2 and <=4'
Exit 1
}
if ( [System.IO.File]::Exists($installUtil) )
{
Set-Alias installUtil $installUtil;
installUtil $assembly /LogToConsole=false /LogFile=;
}
}
}
function Remove-Snapin()
{
param(
[string]$assembly = $null
);
foreach ($platform in ("", "64") )
{
Write-Host "Unregistering $assembly on platform '$platform'";
$installUtil = "$env:windir\Microsoft.Net\Framework${platform}\v2.0.50727\installUtil.exe";
if ( [System.IO.File]::Exists($installUtil) )
{
Set-Alias installUtil $installUtil;
installUtil /u $assembly /LogToConsole=false /LogFile=;
}
}
}
if ( ($force) -or !(Is-SnapinRegistered) )
{
Install-Snapin -assembly iControlSnapin.dll;
}
else
{
Write-Host "iControlSnapIn already registered..."
}