Categories
Who's Online
12 visitors online now
1 guests, 11 bots, 0 members
Support my Sponsor

Posts Tagged ‘powershell’

Connect to On Premises SharePoint 2013 site using Powershell on your local computer

Hi Friends,

Recently I had a word with Ryan Yates on our yammer group and found a interesting Powershell script. Ryan created a powershell script named “Client-side SharePoint PowerShell”is avaiable on Codeplex https://sharepointpowershell.codeplex.com. We can use this script to connect to on-premises SharePoint site using Powershell and execute queries on same. I found it pretty intreseting so I tried same. Below are couple of requirement to use this powershell script.

  1. Windows powershell 3.0
  2. Copy 15 folder from any sharepoint server(path C:\Program Files\Common Files\microsoft shared\Web Server Extensions) to local client machine at same location.
  3. Client user have atleast read permission on target URL.
  4. Client system should be part of same domain.

If above requirement are met, lets get connect to remote SharePoint server. We need to download “Client-side SharePoint PowerShell” from codeplex site and extract it to a folder(e.g. c:\inder). Then Open Windows Powershell(Run as Admin) and browse(cd C:\Inder\sharepointpowershell-42493) to Powershell folder as shown below:
234

  1. Now we We need to load “Client-side SharePoint PowerShell” module using “Import-Module .\spps.psm1” command
    235
    Note: You might have to select “R” multiple times to load all the scripts

  2. Finally we need to connect to SharePoint site using command “Initialize-SPPS -siteURL http://siteurl”
    236

  3. If we dont see any error message, it means our SharePoint is now conenct and ready to use.
    Below are arguments you can use in this powershell

Upload Sandboxed WSP to the site

Add-Solution -path “$exampledir\Solutions\solution.wsp”

Activate the WSP

Install-Solution -solutionName “AESBTwitterWebpart.wsp”

Create a subsite

Add-Subsite -title “Subsite” -webTemplate “STS#0” -description “Description…” -url “subsite” -language 1033 -useSamePermissionsAsParentSite $true

Go to the subsite

Open-Subsite -relativeUrl “/subsite”

Enable the publishing feature

Enable-Feature -featureId “94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb” -force $false -featureDefinitionScope “Web”

Create document library on the subsite

Add-DocumentLibrary -listTitle “Testdoclib”

Copy testfiles to this document library

Copy-Folder “$exampledir\Subsite\Testdoclib” “Testdoclib” $false

Go back to the root site

Open-Rootsite

copy contents of local folders to SharePoint

$stylelibdir = “$exampledir\Style Library”
$styleliburl = “/Style Library”

Set master page

$masterFile = “seattle_custom.master”
Set-CustomMasterPage $masterFile

Create news list

$newsListName = “News”
$newsItemsCSV = “$exampledir\News\items.csv”

Add news web part to the page

Add-Webpart “/Pages/default.aspx” “Header” 0 $webpartXml

Create SharePoint Groups

Add-Group -name “Example Group”

#roleTypes are Guest, Reader, Contributor, WebDesigner, Administrator, Editor

Web

Set-WebPermissions -groupname “Example Group” -roleType “Reader”

Pages lib

Set-ListPermissions -groupname “Example Group” -listname “Pages” -roleType “Reader”

News list

Set-ListPermissions -groupname “Example Group” -listname “News” -roleType “Reader”

Hope this will help you all and help you save time.

Note: If you get error while loading the SharePoint site, make sure you have properly copied 15 hive folder and you are running Windows powershell as admin

 

You can also check below article written by Ryan Yates himself:

http://www.kilasuit.org/Blog/Post/6/Getting-up-and-Running-with-SPPS-for-PowerShell-and-SharePoint-Usage

Manage Multiple subscriptions in Microsoft Azure PowerShell

Hi All,

We will try to understand if we have multiple Azure subscription in Azure PowerShell, how we need to manage these subscription.

Let us try to find problems when we have Multiple Azure subscriptions in PowerShell.
1. When we run any command we get results only from current subscription
2. Its difficult to find in which subscription our command are being executed

  1. We need to run command “get-azuresubscription” get more details regarding our subscription in PowerShell.
    0221

  2. You can see that I have 2 subscription with ID 7045 and 68b3. We can see that 7045 subscription status has Isdefault and Iscurrent value marked as True, where as 68b3 is marked as false

  3. We can get only subscription 7045  when use command “Get-AzureSubscription –Default” and “Get-AzureSubscription –Current”
    0223

  4. Now when we run command get-azurevm we get details related to current/default subscrption(7045) only.
    0222

  5. Now I tried below command and see details of other subscriptions
    Select-AzureSubscription –SubscriptionName <subscriptionname>
    get-azurevm
    0224

  6. Now if you observe when we run “Get-AzureSubscription –Default” or “Get-AzureSubscription –Current” command we will get 7045 has changed its value to false for Iscurrent.
    0225

Azure Powershell Error No current subscription has been designated. Use Select-AzureSubscription – Current to set the current subscription

Hello Everyone, Today i was doing some testing and configuration on my Windows Azure server and got a weird error message as shown below:

Test-AzureStaticVNetIP : No current subscription has been designated. Use Select-AzureSubscription –
Current <subscriptionName> to set the current subscription.
At line:1 char:1
+ Test-AzureStaticVNetIP –VNetName test –IPAddress 11.0.0.1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Test-AzureStaticVNetIP], ApplicationException
+ FullyQualifiedErrorId :
System.ApplicationException,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.TestA
zureStaticVNetIPCommand

 

Did some research and found that we need to connect to Azure subscription and then run these command. To do so we need to download and install Azure Powershell. Copy paste below url on your browser and install the Web Platform Installer. This will give you option to download Azure Powershell.

http://go.microsoft.com/fwlink/p/?linkid=320376&clcid=0x409

0140

 

Once the Powershell is downloaded and installed, we will

0141

 

Now we will download the Azure Setting file to connect to the azure server. In the Azure Powershell, type below command.

Get-AzurePublishSettingsFile

0142

Once you login to your Azure website, you will get a file named “Visual Studio Premium with MSDN-date-credentials.publishsettings”. Save it to a secure location. This file contains secure credentials and additional information about subscriptions that you can use in your development environment.

 

Now Import the Azure Settings file to Powershell. Run “Import-AzurePublisingSettingsFile” and then type path of the file we just downloaded as shown in below image

0143

 

 

To check Subscription details run below command

Get-AzureSubscription

0144

 

 

Now the command completed successfully.

 

Connect to your Azure Subscription using Powershell

Today we will understand we can connect to our Azure Subscription using Powershell and run some basic command on it.

To connect to Azure subscription we need to download and install Azure Powershell. Copy paste below url on your browser and install the Web Platform Installer. This will give you option to download Azure Powershell.

http://go.microsoft.com/fwlink/p/?linkid=320376&clcid=0x409

0140

 

Once the Powershell is downloaded and installed, we will

0141

 

Now we will download the Azure Setting file to connect to the azure server. In the Azure Powershell, type below command.

Get-AzurePublishSettingsFile

0142

Once you login to your Azure website, you will get a file named “Visual Studio Premium with MSDN-date-credentials.publishsettings”. Save it to a secure location. This file contains secure credentials and additional information about subscriptions that you can use in your development environment.

 

Now Import the Azure Settings file to Powershell. Run “Import-AzurePublisingSettingsFile” and then type path of the file we just downloaded as shown in below image

0143

 

 

To check Subsctiption details run below command

Get-AzureSubscription

0144

 

 

 

SharePoint Powershell Script to create, update, delete and assign site Quota template

In this Post I am sharing Powershell Script to create, update, delete and assign site Quota template. Its a simple process hope you will find this post interesting. The Script works for both SharePoint 2010 and SharePoint 2013.

Create a new Quota template:
$NewQTemp = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate
$newQTemp.Name = “Quota Temp1”
$newQtemp.StorageMaximumLevel = 104857600
$newQtemp.StorageWarningLevel = 94371840
$newQtemp.UserCodeMaximumLevel = 300
$newQtemp.UserCodeWarningLevel = 300
$Q =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$Q.QuotaTemplates.Add($newQtemp)
$Q.Update()

Note: Value for StorageMaximumLevel and StorageWarningLevel is in bytes, so if you want 100 mb it will be 10010241024.
0116

In Central Admin we see
0115

 

Delete a Quota template:
$q =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$q.QuotaTemplates.Delete(“Quota Temp1”)
0121

In Central Admin we see
0122

Update code level and storage limit of existing Quota template:
$c =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$QTemp = $c.QuotaTemplates[“Quota Temp”];
$QTemp.Name = “Quota Temp”
$QTemp.UserCodeMaximumLevel = 500
$Qtemp.StorageMaximumLevel = 115343360
$c.Update()

Note: Increased the Quota template from 100 mb to 110 mb and UserCodeMaximumLevel to 500
0117

 

In Central Admin we see
0118
Assign a Quota template to a site Collection:

(Note Quota can only be assigned to site collection and not web application or subsite)
$QTemp = “Quota Temp1”
$site = “http://synhnjseza1181:20000/sites/upload”
Set-SPSite -Identity $site -QuotaTemplate $quotaTemplate
0119
In Central Admin we see

0120

 

 

Hope this will help you all. 🙂

SharePoint 2010 \ 2013 warm up scripts using Powershell

SharePoint app pools recycle every night so that old data is flushed and cache is cleared. It is also important from secruity aspects. But because they recycle every night the first person to hit SharePoint each morning has to wait for the app pools to warm back up, which makes them cranky. Over the years a variety of startup scripts have been written to address this, and they all work to varying degrees.

Server Side Warm script

THis script will request the default page of the root site collection of each web application in your farm:
############## Script 1 #################
Get-SPWebApplication | ForEach-Object { Invoke-WebRequest $_.url -UseDefaultCredentials -UseBasicParsing }
############## Script 1 #################

The –UseDefaultCredentials parameter tells Invoke-WebRequest to log in to the web site as the person that PowerShell is running as. –UseBasicParsing tells Invoke-WebRequest to use basic parsing of the web page. We really don’t care about the web page, we just want to wake SharePoint up to send it to us.
You can also try below Warm up script and check if can be of any help.
This passes in the default credentials needed. If you need specific stuff you can use something else to elevate basically the permissions. Or run this task as a user that has a Policy above all the Web Applications with the correct permissions
############## Script 2 #################
$cred = [System.Net.CredentialCache]::DefaultCredentials;
$cred = new-object System.Net.NetworkCredential(“username”,”password”,”machinename”)[xml]$x=stsadm -o enumzoneurls

foreach ($zone in $x.ZoneUrls.Collection)
{
[xml]$sites=stsadm -o enumsites -url $zone.Default;
foreach ($site in $sites.Sites.Site)
{
write-host $site.Url;
$html=get-webpage -url $site.Url -cred $cred;
}
}
############## Script 2 #################
The next script is completely Powershell from http://www.jonthenerd.com/2011/04/19/easy-sharepoint-2010-warmup-script-using-powershell/

############## Script 3 #################
Add-PSSnapin Microsoft.SharePoint.PowerShell;

function Get-WebPage([string]$url)
{
$wc = new-object net.webclient;
$wc.credentials = [System.Net.CredentialCache]::DefaultCredentials;
$pageContents = $wc.DownloadString($url);
$wc.Dispose();
return $pageContents;
}

Get-SPAlternateUrl -Zone Default | foreach-object
{
write-host $.IncomingUrl;
$html = Get-WebPage -url $
.IncomingUrl;
}

############## Script 3 #################

SharePoint 2010 \ 2013 Create a SharePoint Site Collection with a custom Template using Powershell

Save the custom site with all custom list\library etc as .wsp. To do so follow below:
1. Go to Site action > Site settings > Save site as template

0103

  1. Mention the name of template and select “Include content” > Click OK
    0104

  2. Once the site is saved, you will get link for “Solution gallery”. Go to Solution gallery and download the teamplate (temp.wsp) file to something like d:\temp.wsp.

You need to write powershell in 2 parts. One will create site collection and other will apply custom template.
1st Part of Powershell

Start Part 1 Create a SharePoint Site Collection with a custom Template using Powershell

Write-Host “Provide the site collection URL e.g. http://intranet/site/custom”
$Siteurl = read-host

Write-Host “Provide the site collection owner email address”
$owner = read-host

New-SPSite $Siteurl -OwnerAlias $owner -Name “This will have a custom template”

End Part 1 Create a SharePoint Site Collection with a custom Template using Powershell

Now we have to add our WSP to the Solution Gallery in the Site Collection. I have a do While loop to make sure that the solution has been uploaded successfully before activating it.

##### Start Part 2 Create a SharePoint Site Collection with a custom Template using Powershell ##############
Add-SPUserSolution -LiteralPath d:\temp.wsp -Site $Siteurl
$ErrorActionPreference = “silentlycontinue”
do
{
Write-Host “.” -NoNewline -ForeGroundColor White;
Start-Sleep -Seconds 5;
try
{
$testsolution = Get-SPUserSolution -Identity temp.wsp -Site $Siteurl
}
catch
{}
} while(!$testsolution);
$ErrorActionPreference = “stop”
Install-SPUserSolution -Identity temp.wsp -Site $Siteurl
Write-Host “Site collection with custom template is created”

End Part 2 Create a SharePoint Site Collection with a custom Template using Powershell

Note that the Template GUID and Name will never change. So if you want to send the script and the package to someone else, you can hard code this part and it will work no problem.

Bulk create items in SharePoint 2007 2010 2013 list

Hi Guys,

This article has some great link to articles which can help you create Bulk List items.

SharePoint PowerShell How To: Create SharePoint List Items (in Root and in Folders) for Load/Performance Testing
https://camerondwyer.wordpress.com/2014/05/09/sharepoint-powershell-how-to-create-sharepoint-list-items-in-root-and-in-folders-for-loadperformance-testing/

SharePoint 2007/2010 – Powershell script for bulk populating a List
http://saurabhmoss.wordpress.com/2011/03/16/sharepoint-20072010-powershell-script-for-bulk-populating-a-list/

SharePoint – adding list items with Powershell using web services
http://blogs.technet.com/b/lukeb/archive/2011/03/14/sharepoint-adding-list-items-with-powershell.aspx

Batch Update SharePoint List Items using Powershell
http://suryapulipati.blogspot.com/2013/07/batch-update-sharepoint-list-items.html

Hope this will help you all