Download XML file used as a config file for this script.
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
| Param([Parameter(Mandatory=$True)]
[string]$Environment
)
$snapinName = "Microsoft.SharePoint.PowerShell"
if ((Get-PSSnapin | Where-Object {$_.Name -eq $snapinName }) -eq $NULL) {
write-host "SharePoint SnapIn not loaded. Loading..."
Add-PSSnapin $snapinName -ErrorAction SilentlyContinue
}
#####################################################################
$Envpath=(Get-Location -PSProvider FileSystem).ProviderPath
write-host "Envpath" $Envpath
Write-Host 'Select Current Environment'
Write-Host 'DEV'
Write-Host 'INT'
Write-Host 'QA'
Write-Host 'STAGE'
Write-Host 'PROD'
$Env= $Environment
Write-Host 'Current environment selected' + $Env
if($Env -eq 'DEV')
{
$EnvName='Dev'
}
elseif($Env -eq 'INT')
{
$EnvName='DevInt'
}
elseif($Env -eq 'QA')
{
$EnvName='QA'
}
elseif($Env -eq 'STAGE')
{
$EnvName='Stage'
}
elseif($Env -eq 'PROD')
{
$EnvName='Prod'
}
$Envpath=(Get-Location -PSProvider FileSystem).ProviderPath
write-host "Envpath" $Envpath
#get the Config.xml file from te deployment package
$configpath = $Envpath + "\config.xml"
[xml] $configXml = Get-Content $configpath -ErrorAction SilentlyContinue
#####################################################################
#method to read cofig values from config.xml file -start
#####################################################################
function Get-ConfigValue
{
Param(
[string] $key
)
Process
{
$xpath = "Configuration/$EnvName/param[@key='" + $key + "']" + "/text()"
$configXml.SelectSingleNode($xpath).Value
}
}
$SiteCollectionURL=Get-ConfigValue "SiteCollectionUrl"
Write-Host "SiteCollection url:" $SiteCollectionURL
$solutionName = "Declaration_Email.wsp"
$solution = Get-SPSolution $solutionName
Write-Host -ForegroundColor Green "Removing $solutionName"
Write-Host ""
if( $solution.Deployed -eq $true) {
if ( $solution.ContainsWebApplicationResource ) {
Uninstall-SPSolution -Identity $solutionName -Confirm:$false -Webapplication $SiteCollectionURL
}
else {
Uninstall-SPSolution -Identity $solutionName -Confirm:$false
}
$counter = 1
$maximum = 50
$sleeptime = 2
while( $solution.JobExists -and ( $counter -lt $maximum ) ) {
Write-Host -ForegroundColor yellow "Retracting $solutionName. Please wait..."
sleep $sleeptime
$counter++
}
}
Write-Host ""
Write-Host -ForegroundColor Green "$solutionName is retracted."
Write-Host ""
Remove-SPSolution -Identity $solutionName -Force -Confirm:$false
Write-Host -ForegroundColor Green "$solutionName removed."
|