Archive for August, 2011

Posted by IsaacBlum at 24 August 2011

Category: Business, Cloud, For The Greater Good, Free Help, Microsoft, PowerShell

Tags: , , ,

It has come to my attention that there is still a handful of folks out there writing PowerShell with NOTEPAD…. I won’t name names… But you all know who you are. :) :)

Anyway I use a free tool from Quest software called PowerGUI. See the link to the latest build http://community-downloads.quest.com/powergui/Release/3.0/PowerGUI.3.0.0.2015.msi or http://powergui.org This is the tool that you “never leave home without”. It’s just like visual studio in the sense that you can step into code and debug variables, for each loops, you name it, it can do it. Please let me know if you have any questions.

BTW, a solid second place winner is… Microsoft Windows PowerShell ISE http://technet.microsoft.com/en-us/library/dd315244.aspx

The script enumerates a folder structure based off the input section of the PowerShell script. It then detects all .wsp files in any folder at the root of the folder and below. Once the list of files is compiled by PowerShell, it begins to either upgrade or installs each detected wsp. The script has a bit of logic when attempting an install or upgrade. If the PowerShell script detects that the solution is already deployed to the farm, it will first attempt to retract the solution, once completed it then removes the solution before it attempts to install and deploys the feature to all web applications.

 

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
######################################
######## Set Variables ###############
######################################
$InstallDIR = "C:\install"
 
######################################
#### CODE, No Changes Necessary ######
######################################
Write-Host "Working, Please wait...."
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
 
$Dir = get-childitem $InstallDIR -Recurse
$WSPList = $Dir | where {$_.Name -like "*.wsp*"}
Foreach ($wsp in $WSPList )
{
	$WSPFullFileName = $wsp.FullName
	$WSPFileName = $wsp.Name
	clear
	Write-Host -ForegroundColor White -BackgroundColor Blue "Working on $WSPFileName" 
 
	try
	{
		Write-Host -ForegroundColor Green "Checking Status of Solution"
		$output = Get-SPSolution -Identity $WSPFileName -ErrorAction Stop
	}
	Catch
	{
		$DoesSolutionExists = $_
	}
	If (($DoesSolutionExists -like "*Cannot find an SPSolution*") -and ($output.Name -notlike  "*$WSPFileName*"))
	{
		Try
		{
			Write-Host -ForegroundColor Green "Adding solution to farm"
			Add-SPSolution "$WSPFullFileName" -Confirm:$false -ErrorAction Stop | Out-Null
 
			Write-Host -ForegroundColor Green "Checking Status of Solution"
			$output = Get-SPSolution -Identity $WSPFileName -ErrorAction Stop
			$gobal = $null
			if ($output.Deployed -eq $false)
			{
				try
				{
					Write-Host -ForegroundColor Green "Deploy solution to all Web Apps, will skip if this solution is globally deployed"
					Install-SPSolution -Identity "$WSPFileName" -GACDeployment -AllWebApplications -Force -Confirm:$false -ErrorAction Stop | Out-Null
				}
				Catch
				{
					$gobal = $_
				}
				If ($gobal -like "*This solution contains*")
				{
					Write-Host -ForegroundColor Green "Solution requires global deployment, Deploying now"
					Install-SPSolution -Identity "$WSPFileName" -GACDeployment -Force -Confirm:$false -ErrorAction Stop | Out-Null
				}
			}
 
			Sleep 1
			$dpjobs = Get-SPTimerJob | Where { $_.Name -like "*$WSPFileName*" }
			If ($dpjobs -eq $null)
    		{
        		Write-Host -ForegroundColor Green "No solution deployment jobs found"
    		}
			Else
			{
				If ($dpjobs -is [Array])
				{
					Foreach ($job in $dpjobs)
					{
						$jobName = $job.Name
						While ((Get-SPTimerJob $jobName -Debug:$false) -ne $null)
						{
							Write-Host -ForegroundColor Yellow -NoNewLine "."
							Start-Sleep -Seconds 5
						}
						Write-Host
					}
				}
    			Else
    			{
					$jobName = $dpjobs.Name
					While ((Get-SPTimerJob $jobName -Debug:$false) -ne $null)
					{
						Write-Host -ForegroundColor Yellow -NoNewLine "."
						Start-Sleep -Seconds 5
					}
					Write-Host
    			}
			}
		}
		Catch
		{
			Write-Error $_
			Write-Host -ForegroundColor Red "Skipping $WSPFileName, Due to an error"
			Read-Host
		}
	}
	Else
	{
		$skip = $null
		$tryagain = $null
		Try
		{
			if ($output.Deployed -eq $true)
			{
			Write-Host -ForegroundColor Green "Retracting Solution"
			Uninstall-SPSolution -AllWebApplications -Identity $WSPFileName -Confirm:$false -ErrorAction Stop
			}
		}
		Catch
		{
			$tryagain = $_
		}
		Try
		{
			if ($tryagain -ne $null)
			{
				Uninstall-SPSolution -Identity $WSPFileName -Confirm:$false -ErrorAction Stop
			}
		}
		Catch
		{
			Write-Host -ForegroundColor Red "Could not Retract Solution"
		}
 
		Sleep 1
		$dpjobs = Get-SPTimerJob | Where { $_.Name -like "*$WSPFileName*" }
		If ($dpjobs -eq $null)
    	{
        	Write-Host -ForegroundColor Green "No solution deployment jobs found"
    	}
		Else
		{
			If ($dpjobs -is [Array])
			{
				Foreach ($job in $dpjobs)
				{
					$jobName = $job.Name
					While ((Get-SPTimerJob $jobName -Debug:$false) -ne $null)
					{
						Write-Host -ForegroundColor Yellow -NoNewLine "."
						Start-Sleep -Seconds 5
					}
					Write-Host
				}
			}
    		Else
    		{
				$jobName = $dpjobs.Name
				While ((Get-SPTimerJob $jobName -Debug:$false) -ne $null)
				{
					Write-Host -ForegroundColor Yellow -NoNewLine "."
					Start-Sleep -Seconds 5
				}
				Write-Host
    		}
		}		
 
		Try
		{
			Write-Host -ForegroundColor Green "Removing Solution from farm"
			Remove-SPSolution -Identity $WSPFileName -Confirm:$false -ErrorAction Stop
		}
		Catch
		{
			$skip = $_
			Write-Host -ForegroundColor Red "Could not Remove Solution"
			Read-Host
		}
		if ($skip -eq $null)
		{
			Try
			{
				Write-Host -ForegroundColor Green "Adding solution to farm"
				Add-SPSolution "$WSPFullFileName" -Confirm:$false -ErrorAction Stop | Out-Null
				$gobal = $null
				try
				{
					Write-Host -ForegroundColor Green "Deploy solution to all Web Apps, will skip if this solution is globally deployed"
					Install-SPSolution -Identity "$WSPFileName" -GACDeployment -AllWebApplications -Force -Confirm:$false -ErrorAction Stop | Out-Null
				}
				Catch
				{
					$gobal = $_
				}
				If ($gobal -like "*This solution contains*")
				{
					Write-Host -ForegroundColor Green "Solution requires global deployment, Deploying now"
					Install-SPSolution -Identity "$WSPFileName" -GACDeployment -Force -Confirm:$false -ErrorAction Stop | Out-Null
				}
			}
			Catch
			{
				Write-Error $_
				Write-Host -ForegroundColor Red "Skipping $WSPFileName, Due to an error"
				Read-Host
			}
 
			Sleep 1
			$dpjobs = Get-SPTimerJob | Where { $_.Name -like "*$WSPFileName*" }
			If ($dpjobs -eq $null)
    		{
        		Write-Host -ForegroundColor Green "No solution deployment jobs found"
    		}
			Else
			{
				If ($dpjobs -is [Array])
				{
					Foreach ($job in $dpjobs)
					{
						$jobName = $job.Name
						While ((Get-SPTimerJob $jobName -Debug:$false) -ne $null)
						{
							Write-Host -ForegroundColor Yellow -NoNewLine "."
							Start-Sleep -Seconds 5
						}
						Write-Host
					}
				}
    			Else
    			{
					$jobName = $dpjobs.Name
					While ((Get-SPTimerJob $jobName -Debug:$false) -ne $null)
					{
						Write-Host -ForegroundColor Yellow -NoNewLine "."
						Start-Sleep -Seconds 5
					}
					Write-Host
    			}
			}
	}
	Else
	{
		Write-Host -ForegroundColor Red "Cannot Install $WSPFileName, Please try manually"
		Read-Host
	}
}
}

Folks this is the absolute last resort. DO NOT TRY THIS ON YOUR FIRST ATTEMPT!!!!

Disclaimer: This posting is provided “AS-IS” with no warranties, and confers no rights. Use this information at your own risk, I or Microsoft are not responsible for any damage which may occur due to wrong usage of this command.

Navigate to the Manage Service Application section of central administration. ex: http://servername:2010/_admin/ServiceApplications.aspx

When you have over any of the service applications links with your mouse, you will note that at the bottom of your browser you will see a URL. The other option is to right click on any of the service application links then properties. Take further note that at the end of each URL there is an ID in the form of a GUID. I have noted a few below. Once you have determined there are no other options for removing the service application use the following command followed by the GUID.

Command: Stsadm -o deleteconfigurationobject -id %GUID%

Ex: Stsadm -o deleteconfigurationobject -id 19928d02-7ccb-44b5-9b3b-9ca1aa0130f0

Some example IDs

  • tsid=19928d02-7ccb-44b5-9b3b-9ca1aa0130f0
  • Id=178c598ac5kk405b9564a29b55fe2542
  • AppId=4beb5h7e-92bf-4f21-f859-d2e4b49457db
**Update**
You might unintentionally leave “orphaned” databases attached to your SharePoint farm using the above command. To fix, use PowerShell command “Get-SPDatabase” to get a listing of the database’s GUIDs. Then use the above stsadm command, to remove the orphaned database.
**Update**

 

  • Archives

  • Tags

  • Subscribe
  • Pages

  • More

  • Disclaimer…

    This is my personal weblog. The opinions expressed herein are my own and are not representative of any 3rd party influence. The owner of this blog reserves the right to edit or delete any comments submitted to this blog without notice if they are deemed to be spam, offensive or otherwise inappropriate. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.


    Lastly, I do my best to document my sources if the article is not of my own creation. If I have missed or forgotten to source your work. I would love feedback via the comments section. Thank you.

DreamHost promos
SiteLock