Powershell is most powerful tool in sharepoint 2010.Administrator can access the all sp objects to get the data also.
Windows PowerShell is an extensible executable that can process scripts and interactive commands. Windows PowerShell has many standard scripting constructs—including variables, loops, and conditional logic—allowing administrators to create, save, and execute powerful scripts.
With the release of SharePoint Foundation Server 2010 and SharePoint Server 2010, Windows PowerShell is the default command-line and scripting tool. STSADM is still available to use, but it has limited coverage of administration actions compared to the SharePoint commands available using Windows PowerShell.
The Management Shell is a Windows PowerShell host that loads the Microsoft.SharePoint.PowerShell module and makes available all of the SharePoint commands. Because SharePoint 2010 Management Shell is a Windows PowerShell host, all the Windows PowerShell features and functionality are part of the shell. This means that to create more robust scripts and commands administrators need to learn, at a minimum, some Windows PowerShell scripting.
Get-Command –Module Microsoft.SharePoint.PowerShell
Get –Help Get –SPSite
Run a SharePoint PowerShell Backup Script using Windows Scheduler
SharePoint administrators need to run regular backups using PowerShell, the STSADM tool or in Central Administration. There is no "built in" way to automate these backups. Wouldn't it be great to devise a method to automate these jobs.
The solution is just to create a batch file that can execute a PowerShell script, and then launch it from the Windows Task Scheduler.
PowerShell Command to Backup SharePoint Site Collection
backup-spsite -identity http://moss2010/ -path D:\Backup\Backup.bak
So, you can use the backup-spsite command to do site backup (the example shows http://moss2010/). The following script will start a full backup to D:\backup where you can send a site collection URL and backup file name as a parameter to the PowerShell Script.
$args[0] = http://moss2010/ [Source site location URL]
$args[1] = D:\backup\backup_site.bak [Destination path]
Create Windows PowerShell script
Add-PSSnapin Microsoft.SharePoint.PowerShell
backup-spsite -identity $args[0] -path $args[1] -force
Save it as PowerShell D:\Scripts\BackupSPSite.ps1
Create Batch Script to execute PowerShell script
@echo off
SET SOURCE_SITE=http://moss2010/
SET DEST=D:\backup\Backup_site.bak
echo "backup Started at" %DATE% >> D:\backup\Log.txt
powershell -command D:\Scripts\BackupSPSite.ps1 %SOURCE_SITE% %DEST%
echo "Backup completed successfully at %DEST%" on %DATE% >> D:\backup\Log.txt
@echo on
Save it as Batch file D:\Scripts\BackupSPSite.bat. Now you have to run this script.
Run Batch Script to execute PowerShell script
Run batch script to check successful backup and log creation at D:\backup.
Now run it from the Windows Task Scheduler. In the Task Scheduler, the account needs to be set with admin permissions to run it properly.
So now you can automate your daily backup of a SharePoint Site.
You can also run an entire Farm backup just by using the following command in a PowerShell Script (i.e. D:\Scripts\BackupSPSit
some examples for powershell commands.
Get-SPSite http://portal.contoso.com/sites/*
Get-SPSite –Identity http://portal.contoso.com/sites/*
Get-SPSite http://portal.contoso.com/sites/* -Limit All | Set-SPSite –SecondaryOwnerAlias contoso\andyr
Get-SPSite http://portal.contoso.com/* | Select Url, SecondaryContact
Get-SPSite –Filter {$_.SecondaryContact –eq "contoso\andyr"}
Get-SPLogEvent | ?{$_.Level –eq "High"} | Select Category, Message
Get-SPSite “http://portal.contoso.com/(sites|my)/.*” -RegEx –Limit All | Select Url
Get-SPSite http://portal.contoso.com/sites/* -Limit All | foreach{New-SPWeb –Url ($_.Url + "/blog") –Template BLOG#0}
Start-SPAssignment -Global
$Web = Get-SPWeb http://portal.contoso.com
$Web.Description = "Testing variable assignment!"
$Web.Update()
Stop-SPAssignment -Global
$SiteScope = Start-SPAssignment
Foreach($Site in ($SiteScope | Get-SPSite http://portal.contoso.com/sites/*))
{
Get-SPFeature PublishingSite | Enable-SPFeature –Url $Site.Url
New-SPWeb –Url ($Site.Url + "/news")
$WebScope = Start-SPAssignment
$Web = $WebScope | Get-SPWeb ($Site.Url + "/news")
$Web.Title = "Team News"
$Web.Description = "All the latest news and information"
$Web.Update()
Stop-SPAssignment $WebScope
}
Stop-SPAssignment $SiteScope
Get-SPSite | Get-Member
Start-SPAssignment -Global
$Site = Get-SPSite http://portal.contoso.com
Write-Host $Site.Url
Write-Host $Site.Zone
Write-Host $Site.Quota
$Site.Quota | Get-Member
$Site.Quota | Select StorageMaximumLevel
$Site.Quota.StorageMaximumLevel = 52428800
$Site.Quota.StorageWarningLevel = 41943040
Stop-SPAssignment -Global



No comments:
Post a Comment