There are two ways you can suppress confirmation from a script or console:
1. Set the automatic variable to 'None' or 0 in your
$ConfirmPreference = 'None'
cd Variable:
then dir to see all the variables currently defined in your shell, the text above will change the behavior though, and then at the end of your script you could change it back to 'High'
2. Pass $false to the Cmdlet's -Confirm switch
... -confirm:$false
Windows PowerShell blog on this topic: http://blogs.msdn.com/b/powershell/archive/2006/12/15/confirmpreference.aspx
Windows PowerShell blog home: http://blogs.msdn.com/b/powershell/
Video Content
Translate
Saturday, January 18, 2014
Saturday, January 11, 2014
Customizing your PowerShell window colors
The information about the settings for your PowerShell's shell colors are stored in the object model at:
System.Management.Automation.Internal.Host.InternalHost and at
System.Management.Automation.Internal.Host.InternalHostRawUserInterface
under the PrivateData and RawUI Properties
you can see the various settings by typing
$host.PrivateData and pressing enter
PS C:\Users\Stacy> $host.PrivateData
ErrorForegroundColor : Red
ErrorBackgroundColor : Black
WarningForegroundColor : Yellow
WarningBackgroundColor : Black
DebugForegroundColor : Yellow
DebugBackgroundColor : Black
VerboseForegroundColor : Yellow
VerboseBackgroundColor : Black
ProgressForegroundColor : Yellow
ProgressBackgroundColor : DarkCyan
Or by typing $host.UI.RawUI
ForegroundColor: DarkYellow
BackgroundColor: Black
CursorPosition: 0,70
WindowPosition : 0,21
CursorSize: 25
BufferSize: 120,3000
WindowSize: 120,50
MaxWindowSize: 120,84
MaxPhysicalWindowSize: 274,84
KeyAvailable: False
WindowTitle : Windows PowerShell
Now if you don't care for the red error text and would rather see it in green, type this
(get-host).PrivateData.ErrorForegroundColor = 'Green'
You also could have used Get-Host alias $host, like this:
$host.PrivateData.ErrorForegroundColor = 'Green'
Either way, powershell will just prompt back to normal, it will seem like nothing happened. You can verify that it worked by typing this
$host.PrivateData.ErrorForegroundColor = Green
without the single quotes and including Green.
It will result in an error, the error text will be Green with a black Error background color.
If you want to see information about the User Interface
$host.UI.RawUI | gm
If you wanted to change the background color of your current shell to black:
$host.ui.rawUi.backgroundcolor = 'Black'
press enter
cls
press enter
If you want your shell to always open up with a black background, you could create a folder in your my documents folder and name this new folder, WindowsPowerShell. Then create a .ps1 file and include these two lines of code:
$host.ui.rawUi.backgroundcolor = 'Black'
cls
This channel, by Don Jones, on YouTube has really, quick and easy PowerShell tutorials on the above information and more: https://www.youtube.com/playlist?list=PL6D474E721138865A
System.Management.Automation.Internal.Host.InternalHost and at
System.Management.Automation.Internal.Host.InternalHostRawUserInterface
under the PrivateData and RawUI Properties
you can see the various settings by typing
$host.PrivateData and pressing enter
PS C:\Users\Stacy> $host.PrivateData
ErrorForegroundColor : Red
ErrorBackgroundColor : Black
WarningForegroundColor : Yellow
WarningBackgroundColor : Black
DebugForegroundColor : Yellow
DebugBackgroundColor : Black
VerboseForegroundColor : Yellow
VerboseBackgroundColor : Black
ProgressForegroundColor : Yellow
ProgressBackgroundColor : DarkCyan
Or by typing $host.UI.RawUI
ForegroundColor: DarkYellow
BackgroundColor: Black
CursorPosition: 0,70
WindowPosition : 0,21
CursorSize: 25
BufferSize: 120,3000
WindowSize: 120,50
MaxWindowSize: 120,84
MaxPhysicalWindowSize: 274,84
KeyAvailable: False
WindowTitle : Windows PowerShell
Now if you don't care for the red error text and would rather see it in green, type this
(get-host).PrivateData.ErrorForegroundColor = 'Green'
You also could have used Get-Host alias $host, like this:
$host.PrivateData.ErrorForegroundColor = 'Green'
Either way, powershell will just prompt back to normal, it will seem like nothing happened. You can verify that it worked by typing this
$host.PrivateData.ErrorForegroundColor = Green
without the single quotes and including Green.
It will result in an error, the error text will be Green with a black Error background color.
If you want to see information about the User Interface
$host.UI.RawUI | gm
If you wanted to change the background color of your current shell to black:
$host.ui.rawUi.backgroundcolor = 'Black'
press enter
cls
press enter
If you want your shell to always open up with a black background, you could create a folder in your my documents folder and name this new folder, WindowsPowerShell. Then create a .ps1 file and include these two lines of code:
$host.ui.rawUi.backgroundcolor = 'Black'
cls
This channel, by Don Jones, on YouTube has really, quick and easy PowerShell tutorials on the above information and more: https://www.youtube.com/playlist?list=PL6D474E721138865A
Sunday, January 5, 2014
Backing up a SharePoint 2010 farm
There are a lot of good scripts out there to use for backing up your SharePoint. This one is one of my favorites:
http://spfarmbackup.codeplex.com/
Just download it, unzip it, create a folder to store your backups, share that folder complete the Params.xml and you're about ready to go!
Read this detailed instruction guide written by the scripts author for step-by-step instructions: http://www.darrenmarsden.com/file.axd?file=2013%2f1%2fPreparing+for+%26+Configuring+the+SharePoint+Farm+Backup+Script.pdf
Here is another, and probably the best script for backing up your SharePoint Farm. It is written by John Ferringer, a SharePoint Guru - http://gallery.technet.microsoft.com/scriptcenter/9b99c435-8831-4c9e-a70b-1f13158ef22a
If the Ferringer solution or the codeplex solution above seems a bit to daunting, you can copy and paste the powerhsell from this blog: http://bradcote.wordpress.com/2012/05/02/powershell-script-to-backup-site-collections/ into a .ps1 file and then set it up to run as a scheduled task using credentials that have Shell admin access and full control over the shared network location where the backups will be stored.
You'll need to share a folder for the script to write into. Here is the powershell script from bradcote with a few additional notes
# Backup all site collections in the farm, placing them in
# a directory on a shared location
# Note - Does not backup the /train site collection
# adds the SharePoint cmdlets to your powershell and effectively turns it into the SharePoint
#Management Shell
Add-PsSnapin Microsoft.SharePoint.PowerShell
# Take care of the disposable objects to prevent memory leak.
Start-SPAssignment -Global
# This is the backup path - must be shared with account that is executing the script and the
# farm account
$backupLocation="\\\SharePointBackups"
# Remove all that backup folders created > 7 days ago
get-childitem $backupLocation |
where {$_.Lastwritetime -lt (date).adddays(-7)} |
remove-item -recurse -Confirm:$false
# Get current date for use in log file and format it to avoid
# invalid characters such as "/" and ":"
$today=Get-Date -format "MM-dd-yyyy HH.mm.ss"
# Create a folder in the backup location with todays date (sortable)
$todayFolder = $backupLocation + '\' + $((get-date).toString('MM-dd-yyyy'))
$logFile="$todayFolder\BackupLog.log"
md $todayFolder
# Does not backup the /train site collection
# or the temporary web ap site collection on port 15702
# Disregard this, or use it, depending on whether you have a /train site collection, etc.
foreach ($site in get-spsite -limit all |
where-object -FilterScript {$_.url -notlike "*/train*"} |
where-object -FilterScript {$_.url -notlike "*15702"}) {
write-Host Start backing up $site to $todayFolder
try {
# Create a new backup file and name it based on current date.
# If you want to create only 1 backup file and overwrite it
# each time the backup is run, you can replace "$today.bak"
# with your desired file name.
$pathName = ($todayFolder + '\' + $($site.ID) + '.bak')
write-Host 'Backing up ' $site ' GUID = ' $($site.ID)
# This farm does not have Enterprise SQL Server, so snapshots
# cannot be used. This requires that the sites belocked for
# update during the backup, so this should be run after hours
Backup-SPSite -Identity $site -Path $pathName -EV Err
-EA "SilentlyContinue"
write-Host Backup succeeded.
# Write success message to the log file
write "$today $site GUID =
$($site.ID) successfully backed up.">>logFile
} catch {
write-Host Backup failed. See $logFile for more information.
# Write error message to the log file
# change the logFile to some other name if you want, e.g. BackupHistory.txt
$e = $Err[0].ToString()
write "$today $site Error: $e">>logFile
}
}
Stop-SPAssignment -Global
Remove-PsSnapin Microsoft.sharepoint.powershell
write-Host "Finished script."
This blog has another script that you can use, also an easier to use version:
http://www.mysharepointadventures.com/2012/05/powershell-script-to-backup-farm-configuration-and-service-applications/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Make sure to update these variables:
#Variables
$logfile = "SPFarm-Backup-" + $(Get-Date -Format dd-MM-yy) + ".log"
$ConfigDB = "SP_Config"
$DBServer = "server"
$BackupConfigFolder = "\\server\SharePoint\Backup\Config"
$BackupSAFolder = "\\server\SharePoint\Backup\ServiceApp"
$AdminEmail = <a href="mailto:admin@sharepoint.com">admin@sharepoint.com</a>
$MailServer = "mail.sharepoint.com"
$FromAddress = <a href="mailto:sharepoint.notifications@sharepoint.com">sharepoint.notifications
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Microsoft TechNet - http://technet.microsoft.com/en-us/library/ee428316.aspx - Backing up a Farm in SharePoint 2013
Petri blog - backup and restore advice - Good Read http://www.petri.co.il/how-to-backup-restore-sharepoint-2013.htm
John Ferringer on backups - http://mycentraladmin.wordpress.com/2011/07/11/use-powershell-to-back-up-your-sharepoint-farm/
Microsoft's scripting guy defers to John Ferringer - http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/22/use-powershell-to-back-up-your-sharepoint-farm.aspx - same here
Cheers,
Stacy
http://spfarmbackup.codeplex.com/
Just download it, unzip it, create a folder to store your backups, share that folder complete the Params.xml and you're about ready to go!
Read this detailed instruction guide written by the scripts author for step-by-step instructions: http://www.darrenmarsden.com/file.axd?file=2013%2f1%2fPreparing+for+%26+Configuring+the+SharePoint+Farm+Backup+Script.pdf
Here is another, and probably the best script for backing up your SharePoint Farm. It is written by John Ferringer, a SharePoint Guru - http://gallery.technet.microsoft.com/scriptcenter/9b99c435-8831-4c9e-a70b-1f13158ef22a
If the Ferringer solution or the codeplex solution above seems a bit to daunting, you can copy and paste the powerhsell from this blog: http://bradcote.wordpress.com/2012/05/02/powershell-script-to-backup-site-collections/ into a .ps1 file and then set it up to run as a scheduled task using credentials that have Shell admin access and full control over the shared network location where the backups will be stored.
You'll need to share a folder for the script to write into. Here is the powershell script from bradcote with a few additional notes
# Backup all site collections in the farm, placing them in
# a directory on a shared location
# Note - Does not backup the /train site collection
# adds the SharePoint cmdlets to your powershell and effectively turns it into the SharePoint
#Management Shell
Add-PsSnapin Microsoft.SharePoint.PowerShell
# Take care of the disposable objects to prevent memory leak.
Start-SPAssignment -Global
# This is the backup path - must be shared with account that is executing the script and the
# farm account
$backupLocation="\\\SharePointBackups"
# Remove all that backup folders created > 7 days ago
get-childitem $backupLocation |
where {$_.Lastwritetime -lt (date).adddays(-7)} |
remove-item -recurse -Confirm:$false
# Get current date for use in log file and format it to avoid
# invalid characters such as "/" and ":"
$today=Get-Date -format "MM-dd-yyyy HH.mm.ss"
# Create a folder in the backup location with todays date (sortable)
$todayFolder = $backupLocation + '\' + $((get-date).toString('MM-dd-yyyy'))
$logFile="$todayFolder\BackupLog.log"
md $todayFolder
# Does not backup the /train site collection
# or the temporary web ap site collection on port 15702
# Disregard this, or use it, depending on whether you have a /train site collection, etc.
foreach ($site in get-spsite -limit all |
where-object -FilterScript {$_.url -notlike "*/train*"} |
where-object -FilterScript {$_.url -notlike "*15702"}) {
write-Host Start backing up $site to $todayFolder
try {
# Create a new backup file and name it based on current date.
# If you want to create only 1 backup file and overwrite it
# each time the backup is run, you can replace "$today.bak"
# with your desired file name.
$pathName = ($todayFolder + '\' + $($site.ID) + '.bak')
write-Host 'Backing up ' $site ' GUID = ' $($site.ID)
# This farm does not have Enterprise SQL Server, so snapshots
# cannot be used. This requires that the sites belocked for
# update during the backup, so this should be run after hours
Backup-SPSite -Identity $site -Path $pathName -EV Err
-EA "SilentlyContinue"
write-Host Backup succeeded.
# Write success message to the log file
write "$today $site GUID =
$($site.ID) successfully backed up.">>logFile
} catch {
write-Host Backup failed. See $logFile for more information.
# Write error message to the log file
# change the logFile to some other name if you want, e.g. BackupHistory.txt
$e = $Err[0].ToString()
write "$today $site Error: $e">>logFile
}
}
Stop-SPAssignment -Global
Remove-PsSnapin Microsoft.sharepoint.powershell
write-Host "Finished script."
This blog has another script that you can use, also an easier to use version:
http://www.mysharepointadventures.com/2012/05/powershell-script-to-backup-farm-configuration-and-service-applications/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Make sure to update these variables:
#Variables
$logfile = "SPFarm-Backup-" + $(Get-Date -Format dd-MM-yy) + ".log"
$ConfigDB = "SP_Config"
$DBServer = "server"
$BackupConfigFolder = "\\server\SharePoint\Backup\Config"
$BackupSAFolder = "\\server\SharePoint\Backup\ServiceApp"
$AdminEmail = <a href="mailto:admin@sharepoint.com">admin@sharepoint.com</a>
$MailServer = "mail.sharepoint.com"
$FromAddress = <a href="mailto:sharepoint.notifications@sharepoint.com">sharepoint.notifications
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Microsoft TechNet - http://technet.microsoft.com/en-us/library/ee428316.aspx - Backing up a Farm in SharePoint 2013
Petri blog - backup and restore advice - Good Read http://www.petri.co.il/how-to-backup-restore-sharepoint-2013.htm
John Ferringer on backups - http://mycentraladmin.wordpress.com/2011/07/11/use-powershell-to-back-up-your-sharepoint-farm/
Microsoft's scripting guy defers to John Ferringer - http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/22/use-powershell-to-back-up-your-sharepoint-farm.aspx - same here
Cheers,
Stacy
Saturday, December 28, 2013
Merry Christmas!!!
I hope you've enjoyed reading this blog over the last year and that you've had a great year in SharePoint.
There isn't going to be a blog post this week, due to the Christmas Holiday.
Next week I'll be back at it with instruction on putting a backup script in place.
Have a Merry Christmas and a Happy new year!
Cheers,
Stacy
P.S.
Check out this awesome PowerShell Reference Library on PowerShell.com: http://powershell.com/cs/media/28/default.aspx
Check out this PowerShell Code repository on http://poshcode.org/
There isn't going to be a blog post this week, due to the Christmas Holiday.
Next week I'll be back at it with instruction on putting a backup script in place.
Have a Merry Christmas and a Happy new year!
Cheers,
Stacy
P.S.
Check out this awesome PowerShell Reference Library on PowerShell.com: http://powershell.com/cs/media/28/default.aspx
Check out this PowerShell Code repository on http://poshcode.org/
Saturday, December 21, 2013
Setting up your farm for optimal performance - Super User and Super Reader Accounts
It is important to configure the super user and super reader accounts for your SharePoint farm in order to optimize it's use of the object cache. This is true especially if you are using the SharePoint Server Publishing Infrastructure.
Here is a link to the detailed steps on TechNet: http://technet.microsoft.com/en-us/library/ff758656.aspx
Here are the high level steps:
Create or get two service accounts created, one for the Super User and one for the Super Reader
Add the Super User account to each web application with Full Control
Add the Super Reader account to each web application with Full Read
(Both of the above can be performed via central admin - Application Management > Manage Web Applications > User Policy)
Then run the following four lines in an elevated SharePoint management console
$wa = Get-SPWebApplication -Identity "<WebApplication>"
Repeat this for each web application that you have.
use these values:
Here is a link to the detailed steps on TechNet: http://technet.microsoft.com/en-us/library/ff758656.aspx
Here are the high level steps:
Create or get two service accounts created, one for the Super User and one for the Super Reader
Add the Super User account to each web application with Full Control
Add the Super Reader account to each web application with Full Read
(Both of the above can be performed via central admin - Application Management > Manage Web Applications > User Policy)
Then run the following four lines in an elevated SharePoint management console
$wa = Get-SPWebApplication -Identity "<WebApplication>"
$wa.Properties["portalsuperuseraccount"] = "<SuperUser>"
$wa.Properties["portalsuperreaderaccount"] = "<SuperReader>"
$wa.Update()
Repeat this for each web application that you have.
use these values:
- <WebApplication> is the name of the web application to which the accounts will be added.
- <SuperUser> is the account to use for the Portal Super User account as you saw it displayed in the User Column field mentioned in Step 14 of the previous procedure.
- <SuperReader> is account to use for the Portal Super Reader account as you saw it displayed in the User Column field mentioned in Step 14 of the previous procedure.
For example, assuming the sp content account shown below was the Super User account, you would type $wa.properties["portalsuperuseraccount"]="THEMANCAVE\SPContent"
on line two. On line one, you'd type either the URL or the name of the web application, so either $wa = Get-SPWebApplication -Identity "SharePoint - 80" or $wa = Get-SPWebApplication -Identity "http://2010app1/"
and on line three, it would be similar to line two, just replacing the account with the reader account, assuming spreader was the reader account,
$wa.properties["portalsuperreaderaccount"]="THEMANCAVE\SPreader"
Note: this server uses that as the search account, so you would want a different search account or a different reader account, don't use the same account for crawling and for reading the object cache.
Also, if you are working with a SharePoint 2013, you'll want to use the claims based accounts when running the powershell
$wa.properties["portalsuperreaderaccount"]="i.0#.w|THEMANCAVE\SPreader"
Also, if you are working with a SharePoint 2013, you'll want to use the claims based accounts when running the powershell
$wa.properties["portalsuperreaderaccount"]="i.0#.w|THEMANCAVE\SPreader"
Cheers,
Saturday, December 14, 2013
Web Application not getting created on all Web Front ends?
If you ever run into a situation where your farm suddenly fails to create the web application on all front end web servers, in other words it only gets created on the server running central admin, one good indication of that will be that the screen shown here:
Which normally advises you that the web application was created and would you like to know more about FBA (forms based authentication) will not appear.
Instead you will see a screen that says the page can not be displayed by Internet explorer, similar to the one shown here:
Which normally advises you that the web application was created and would you like to know more about FBA (forms based authentication) will not appear.
Instead you will see a screen that says the page can not be displayed by Internet explorer, similar to the one shown here:
This starts to occur when the process model shutdown time limit for the application pool that runs central admin is not long enough. This is usually due to one or a combination of the farm not having enough resources, being overworked due to more than 20 web applications, or numerous extended web applications.
The detailed steps for this blog post are found here: http://support.microsoft.com/kb/2543306
Here are the high level steps to resolve this issue:
Logon to your server that runs central admin
Open IIS Manager (inetmgr.exe)
Right click on the Central Administration application pool
Select Advanced Settings
increase the Shutdown Time Limit for the Process Model from the default of 90 seconds to something higher, e.g. 300 Seconds.
You're good to go now; but you should check and delete the web application that didn't replicate and make sure it was removed from the physical path of IIS before you attempt to recreate. Check all servers in your farm that have SharePoint binaries installed.
Before I knew this trick, I was adding and removing servers from the farm to get the web application to replicate, adjusting the process model shutdown time limit is much faster,
Cheers
Saturday, December 7, 2013
Exporting and Importing just a list or a library
If the goal is to import just one list or one library there are a couple ways you can accomplish this:
1. Navigate to settings for the list or library, save it as a template, navigate to the solutions gallery, right click on the newly created template, save it as Windows SharePoint Services solutions package and then deploy that solutions package to your site, activate the feature, and begin using the list or library, Or,
2. Run this PowerShell, making sure to use the actual URL of the list or the correct name of the library. Surround this item in quotes
Export-SPweb http://mySitethathaslist/sites/ToExport -Item "Lists\Name of the list" -Path e:\PathToSaveFile\Filename.cmp -IncludeUserSecurity -IncludeVersions All
then copy that Filename.cmp to the destination server and run
Import-spweb http://anothersharepointblog.blogspot.com -Path e:\PathtoWheretheFilewasImported\FileName.cmp -includeUserSecurity -UpdateVersions Overwrite
Note: if the url to the list was actually lists/nameList then the Item part in the Export-spWeb above would've read "Lists\nameList" and not "Lists\Name of Lists". Also if you are performing this for a document library, Lists\ is not needed.
Cheers,
1. Navigate to settings for the list or library, save it as a template, navigate to the solutions gallery, right click on the newly created template, save it as Windows SharePoint Services solutions package and then deploy that solutions package to your site, activate the feature, and begin using the list or library, Or,
2. Run this PowerShell, making sure to use the actual URL of the list or the correct name of the library. Surround this item in quotes
Export-SPweb http://mySitethathaslist/sites/ToExport -Item "Lists\Name of the list" -Path e:\PathToSaveFile\Filename.cmp -IncludeUserSecurity -IncludeVersions All
then copy that Filename.cmp to the destination server and run
Import-spweb http://anothersharepointblog.blogspot.com -Path e:\PathtoWheretheFilewasImported\FileName.cmp -includeUserSecurity -UpdateVersions Overwrite
Note: if the url to the list was actually lists/nameList then the Item part in the Export-spWeb above would've read "Lists\nameList" and not "Lists\Name of Lists". Also if you are performing this for a document library, Lists\ is not needed.
Cheers,
Subscribe to:
Posts (Atom)
Popular Posts
-
When you're migrating sites using export-spweb and import -spweb , you might receive an error message on the import, when reviewing th...
-
Here are a couple ways to copy content around in SharePoint: Backup-SPSite and Restore-SPSite and Export-SPWeb and Import-SPW...
-
Let's say you go to provision a Project Web App via managed service applications, project server server application, and it fails. Ther...
-
Log onto each additional server that you wish to join into the farm Open the ”SharePoint 2010 Management Shell” administratively (righ...
-
Configuring User Profile Synchronization Service Applications for SharePoint 2010 or SharePoint 2013This post assumes you've already installed the SharePoint Binaries (Grey Wizard), and that you are not using the Farm Config Wizard (Wh...
-
If you ever run into a situation where your farm suddenly fails to create the web application on all front end web servers, in other words i...
-
Sorry to be blogurgitating this week. Here's a really good technet site with a load of virtual labs: SharePoint Server 2010 In...
-
Once a web application has been extended into a zone, the option to choose that zone disappears from the drop down, off the extend web appli...
-
When the need to list out the members of an active directory group arises, say management asks, who are the members of this group, and you d...
-
The steps below turn your team site into a team site that is capable of using publishing features and capabilities. But all they really do,...