Posts mit dem Label PowerShell werden angezeigt. Alle Posts anzeigen
Posts mit dem Label PowerShell werden angezeigt. Alle Posts anzeigen

Sonntag, 22. April 2012

Clear WebConfigModifications using powershell

While playing arround with the SPWebConfigModification Class I added some wrong entries to the web.config. These entries where added every time I activated or deactivated my feature. It seemed the WebConfigModifications of the WebApplication object had some corrupt entries. So I found this blog. David Petersen explains how to clear these WebConfigModifications using code in a console application.

This was very helpfull and solved my Problem. But instead of creating a console application I simply made a PowerShell Script. The code is basically the same but I wanted to add it here for those who are still afraid of using PoweShell. Don't be. Powershell just rocks ;)


$siteUrl = "http://yoursiteurl/";
$site = $gc | Get-SPSite -Identity $siteUrl
[Microsoft.SharePoint.Administration.SPWebApplication]$webApp = $site.WebApplication
$webApp.WebConfigModifications.Clear();
$webApp.Update();
[Microsoft.SharePoint.Administration.SPWebService] $service =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$service.WebConfigModifications.Clear();
$service.Update();
$service.ApplyWebConfigModifications();


Finally just be careful because this code removes all modifications not only yours. So don’t use it on productive environments.

Dienstag, 27. März 2012

Moving a SharePoint site Collection to another managed Path using PowerShell


I recently needed to move a Site Collection from one managed path to another. I found this blog using stsadm commands. I translated this to a PowerShell script: 


$fromUrl = "http://portal.dev/sites/TestSiteCollection"
$toUrl = "http:// portal.dev"

$backupPath = "c:\siteBackup"
Backup-SPSite $fromUrl -Path $backupPath -force
Remove-SPSite -Identity $fromUrl -Confirm:$false
Restore-SPSite -Identity $toUrl -Path $backupPath -Confirm:$false

Samstag, 24. März 2012

Adding SharePoint Shell access to an Admin Account

I was recently added as administrator to a SharePoint server farm. I was able to access the Central Administration with no problem. But the issue was that PowerShell was not working. I got this error message when I started the "SharePoint 2010 Management Shell":

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered..



Also when I tried to start the SharePoint Manager 2010 I get this error: "Object reference not set to an instance of an object"

I have had this error before and I got a lot of trouble with Powergui at that Time too. To get this work you need make sure the logged user has rights to the SharePoint Configuration Database (db_owner and SharePoint_Shell_Access)

But be aware that direct changes to the SharePoint DB are not supported by Microsoft. To make this right use the Add-SPShellAdmin PowerShell command with an Administrator account:

Add-SPShellAdmin -username MyUserName


Now you can user Powershell but you will get this error when trying to access a Site with: "Get-SPWeb $url"


Cannot find SPWeb object with 'Id' or URL:"


You need to grant rigths on the content databses using this commands:

> $contentDB = get-spcontentdatabase -site http://server/site
> add-spshelladmin -UserName DOMAIN\Username -database $contentDB



Thanks to this Blog


Dienstag, 6. September 2011

Add Circulation List to SharePoint 2010 Web using PowerShell


PowerShell is great. I'm working on scripting a whole deployment process with PowerShell. Yesterday I got stuck in a problem that costs me about 6 hours of my life. 
If you want to add a list to a SPWeb you will find in a lot of blogs this description:

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::Circulation
$spweb.Lists.Add(MyCirculation“,"Description",$listTemplate)

And guess what? It works fine for a lot of list templates. But then I tried with “Circulation” and I got this error:


Exception calling “Add” with 3 argument(s) “Invalid list template.”

I tried a lot And I found out that I need to use this Add Method:
http://msdn.microsoft.com/en-us/library/ms448694.aspx

So I tried with this code:

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]:: Circulation
$spweb.Lists.Add(“MyCirculation“,"Description", $spweb.Url, "a568770a-50ba-4052-ab48-37d8029b3f47", $listTemplate, 2)

You can get the feature ID from this location “14/TEMPLATE/FEATURES/CirculationList”
here I got this error message:

Exception calling "Add" with "6" argument(s): "The file or folder name contains characters that are not permitted.  Please use a different name

So I thought the error must be in the Url but what Url does the Method require?
Finally I tried with this:


$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::Circulation
$spweb.Lists.Add(“MyCirculation“,"Description", “MyCirculation“, "a568770a-50ba-4052-ab48-37d8029b3f47", $listTemplate, 2)

I don’t know why, but it worked. I just used the same thing for Title and Url.
I only tried this out with Circulations, but as whereabouts throw the same error I think the solution must be the same.

As I said this cost me about 6 hours trying and searching for a solution. I hope it will be useful to someone else.

Enjoy and Share :)