Posts Tagged ‘Powershell’

SharePoint Online – Setting up PowerShell

SharePoint global administrator can use the SharePoint Online Management Shell to manage the site and content.

Following are the steps we should do for that

  1. Install Windows Management Framework 3.0 – You can download it from This require a system restart
  2. Install SharePoint Online Management Shell – You can download it from

Once this is done, you can start “SharePoint Online Management Shell” and use following command to connect

Connect-SPOService -Url -credential

After connection, you can execute SPO cmdlets and work remotely.



will retrieve all sites.

Take a look at this to find the list of supported cmdlets

Categories: Misc, SharePoint Online Tags:

PowerShell – Delete all files & folders from SharePoint library

February 26, 2013 8 comments

The good thing about PowerShell is that we don’t need to compile anything. Just write the script and execute.

In this article I am going to share a very useful PowerShell script which can be used for clearing SharePoint document library.

Add-PSSnapin Microsoft.SharePoint.PowerShell

# Replace siteurl with actual web url
$web = Get-SPWeb -Identity "siteurl"
# Replace docurl with document library url
$list = $web.GetList("docurl")

function DeleteFiles {
    $folder = $web.GetFolder($folderUrl)
    foreach ($file in $folder.Files) {
        # Delete file by deleting parent SPListItem
        Write-Host("DELETED FILE: " + $

# Delete root files

# Delete files in folders
foreach ($folder in $list.Folders) {

# Delete folders
foreach ($folder in $list.Folders) {
    try {
        Write-Host("DELETED FOLDER: " + $
    catch {
        # Deletion of parent folder already deleted this folder

PowerShell Import all AD users to SharePoint 2010 Group

$spgroupname = "Group Name"
$sitename= "http://sitename"
$domain = $env:USERDOMAIN

$spsite = SPSite($sitename)
$rootweb = $spsite.rootweb
$spgroup = $rootweb.Groups[$spgroupname]

$allowUnsafeUpdates = $spsite.AllowUnsafeUpdates
$spsite.allowUnsafeUpdates = 1

$searcher = New-Object 
$results = $searcher.FindAll()
foreach($result in $results){
	$username = $domain + "\" + $user.sAMAccountName
	$spsiteuser = $rootweb.EnsureUser($username)
        $spUser = $rootweb.AllUsers[$spsiteuser]

$spsite.allowUnsafeUpdates = $allowUnsafeUpdates


Get-SPUser –Web $sitename| Set-SPUser –SyncFromAD
Categories: SharePoint 2010 Tags:

SharePoint Configuring WAS

Powershell scripts for configuring WAS

$serviceName = "Word Automation Service"
$appPool = $null

Add-pssnapin Microsoft.SharePoint.PowerShell
$appPool = Get-SPIisWebServiceApplicationPool -Identity <appPoolName>
if ($appPool –eq $null)
   $appPool = New-SPIisWebServiceApplicationPool 
            -Name <appPoolName> -Account <admin>
            -Name $serviceName -ApplicationPool $appPool