Archive
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
- Install Windows Management Framework 3.0 – You can download it from http://go.microsoft.com/fwlink/p/?LinkID=244693. This require a system restart
- Install SharePoint Online Management Shell – You can download it from http://go.microsoft.com/fwlink/p/?LinkId=255251
Once this is done, you can start “SharePoint Online Management Shell” and use following command to connect
Connect-SPOService -Url https://tenant-admin.sharepoint.com -credential admin@tenant.com
After connection, you can execute SPO cmdlets and work remotely.
Example:
Get-SPOSite
will retrieve all sites.
Take a look at this http://technet.microsoft.com/en-us/library/cb90889b-9c1e-4cec-ab0f-774be623022f(v=office.15) to find the list of supported cmdlets
PowerShell – Delete all files & folders from SharePoint library
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 { param($folderUrl) $folder = $web.GetFolder($folderUrl) foreach ($file in $folder.Files) { # Delete file by deleting parent SPListItem Write-Host("DELETED FILE: " + $file.name) $list.Items.DeleteItemById($file.Item.Id) } } # Delete root files DeleteFiles($list.RootFolder.Url) # Delete files in folders foreach ($folder in $list.Folders) { DeleteFiles($folder.Url) } # Delete folders foreach ($folder in $list.Folders) { try { Write-Host("DELETED FOLDER: " + $folder.name) $list.Folders.DeleteItemById($folder.ID) } 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 System.DirectoryServices.DirectorySearcher("(objectCategory=User)") $results = $searcher.FindAll() foreach($result in $results){ $user=$result.GetDirectoryEntry() $username = $domain + "\" + $user.sAMAccountName $spsiteuser = $rootweb.EnsureUser($username) $spUser = $rootweb.AllUsers[$spsiteuser] $spgroup.AddUser($spsiteuser) } $spsite.allowUnsafeUpdates = $allowUnsafeUpdates $rootweb.dispose() $spsite.dispose() Get-SPUser –Web $sitename| Set-SPUser –SyncFromAD
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> } New-SPWordConversionServiceApplication -Name $serviceName -ApplicationPool $appPool