File Locked After Sending via Email with Powershell

The files that you attach to an email become locked until the instance of Powershell you are running has exited completely. So if you run a script through Powershell ISE that attaches a file to an email, that file will remain locked until you exit Powershell ISE.

If the file is locked by Powershell, you will get an error/warning message similar to the following if you try to modify it in any way;

The process cannot access the file 'c:\filename.txt' because it is being used by another process

By using the following command, you can ensure that Powershell 'disposes' of the email message once it has been sent and does not continue to 'lock' any files you attach and send via email;

$mailmessage.dispose()

Note: this is assuming that $MailMessage = New-Object system.net.mail.mailmessage

Outlook Notes to Text Files

Here is some code for exporting your Outlook Notes.

Sub NotesToRTF()
    Dim myNote As Variant
    Dim cnt As Integer
    Dim noteName As String
    Dim strExportFolder As String
   
    strExportFolder = "C:\Notes-RTF\"
   
    If Dir(strExportFolder, vbDirectory) = "" Then
        MkDir strExportFolder
    End If
   
    Set myNote = Application.GetNamespace("MAPI").PickFolder
    For cnt = 1 To myNote.Items.Count
        noteName = Trim(Replace(Replace(Replace(Replace(myNote.Items(cnt).Subject, "/", "-"), "\", "-"), ":", ""), vbTab, ""))
        Debug.Print noteName
        myNote.Items(cnt).SaveAs strExportFolder & noteName & ".rtf", OlSaveAsType.olRTF
    Next
   
    Shell "C:\WINDOWS\explorer.exe """ & strExportFolder & "", vbNormalFocus
End Sub

Sub NotesToText()
    Dim myNote As Variant
    Dim cnt As Integer
    Dim noteName As String
    Dim strExportFolder As String
   
    strExportFolder = "C:\Notes-Text\"
   
    If Dir(strExportFolder, vbDirectory) = "" Then
        MkDir strExportFolder
    End If
   
    Set myNote = Application.GetNamespace("MAPI").PickFolder
    For cnt = 1 To myNote.Items.Count
        noteName = Trim(Replace(Replace(Replace(Replace(myNote.Items(cnt).Subject, "/", "-"), "\", "-"), ":", ""), vbTab, ""))
        Debug.Print noteName
        myNote.Items(cnt).SaveAs strExportFolder & noteName & ".txt", OlSaveAsType.olTXT
    Next
   
    Shell "C:\WINDOWS\explorer.exe """ & strExportFolder & "", vbNormalFocus
End Sub

Hope it helps someone else out there.

Run all SharePoint 2010 Health Analyzer checks / jobs

When you install a new farm, you might be curious to find out what the Health Analyzer results are. Instead of waiting for the checks to happen (basically timer jobs scheduled at different intervals), you could force them to run all at one go, so you can review the results and address them.

You can easily run this in PowerShell. All it does is start all the timer jobs with ‘Health’ in its name. That fires off all SharePoint 2010 Health Analyzer jobs for your new farm in one go.

# Check to ensure Microsoft.SharePoint.PowerShell is loaded
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
  Write-Host "Loading SharePoint Powershell Snapin"
  Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
Get-SPTimerJob | Where {$_.Name -like "*Health*" -and $_.Name -like "*-all-*"} | Start-SPTimerJob

SharePoint 2010 Health Analyzer Reanalyze Now and Actions grayed out

QUESTION: I'm using the SharePoint 2010 Health Analyzer and I've noticed that on some of the issues, when I open the Review window either or both of the Actions or Reanalyze Now options are grayed out. The pop up window says I may not have the right permission level to use this, might need to select an dobject or item, or the control might now work in this context. Can anyone explain why I wouldn't be able to do a reanalyze now? It seems strange this would be grayed out at all.

ANSWER:

Not only was the reanalyze greyed out but non of the scheduled tasks were running. I was able to trace it down to the account that was used to run "SharePoint 2010 Timer" service was not a local admin. I changed it to an account that is a domain service account that has local admin rights and had the rights outlined below:

1.Verify that the user account that is performing this procedure is a member of the Administrators group on the local computer.

2.Click Start, click Administrative Tools, and then click Services.

3.Right-click Windows SharePoint Services Timer V4, and then click Properties.

4.On the Log On tab, confirm that the account being used is a domain user account and is a member of the following:

dbcreator fixed SQL Server server role
securityadmin fixed SQL Server server role
db_owner fixed database role for all databases in the server farm

 Here is the Microsoft link I used.

http://technet.microsoft.com/en-us/library/ee924649.aspx

This resolved my issue. I hope this helps.

SharePoint 2010 – Database is up to date, but some sites are not completely upgraded

In Central Administration, if you visit Upgrade and Patch Management, Review Database Status and notice some DBs have the status ‘Database is up to date, but some sites are not completely upgraded.’ follow the procedure below to rectify.

If you are attempting to upgrade the Admin Content Database then Get-SPContentDatabase will not work, or at least it didn’t for me so refer to the extra steps at the end of this article.

The upgrade status reflects the current state of the database and hence this is not resolved via PSConfig but  rather by PowerShell.  If you need to perform this on a production or any other important environment, make sure you have an agreed maintenance window plus backups before beginning!

  • Using the farm account or equvilently privileged user, start the SharePoint 2010 Management Shell
  • Enter $DB = Get-SPContentDatabase -Identity [ Your Database Name]
  • Now enter Upgrade-SPContentDatabase -id $DB
  • You’ll now be prompted to confirm, just hit enter to accept the default of Yes
  • The upgrade will begin and a percentage complete will be displayed

When the process completes, return to Manage Databases Upgrade Status in Central Admin and the status will not be No action required.

Upgrading the Admin Content Database

As stated at the beginning of this article, Get-SPContentDatabase will not work with the Admin Content Database so another method needs to be found.  As long as you know the DB GUID, you can still execute Upgrade-SPContentDatabase so a simple query of the Config database could be used to find this.  However a better solution is to use Powershell.

The following script iterates though all Content DBs for a given Web Application, so can be used to upgrade the Central Admin Content Database.  You will need to the replace <WA URL> in the script with your Central Administration URL.

$wa = Get-SPWebApplication -Identity "<WA URL>"
foreach($ContentDB in $wa.ContentDatabases)
{
  Upgrade-SPContentDatabase -id $ContentDB
}

Rename a chart in Excel 2010

Rename a chart

When you create charts, Microsoft Office Excel assigns a default name to each chart by using the following naming convention: Chart1, Chart2, and so on. However, you can change the name of each chart to make it more meaningful to you.

  1. Click the chart that you want to rename.

This displays the Chart Tools, adding the Design, Layout, and Format tabs.

  1. On the Layout tab, in the Properties group, click the Chart Name text box.

 Tip   You may have to click the Properties icon in the Properties group to expand the group.

  1. Type a new name.
  2. Press ENTER.

SharePoint ItemUpdated fires twice

The ItemUpdated event does fire twice - by design. Once when the item is actually updated, and then again when SharePoint is done checking in the item.
See http://www.simple-talk.com/dotnet/.net-tools/managing-itemupdating-and-itemupdated-events-firing-twice-in-a-sharepoint-item-event-receiver/ for more info on that. 
Some people use a workaround like this:
if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null &&    
              properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)
{
           //This is when the update event is triggered by check-in.
}
else
{
          //This is triggered by events other than check-in action.
}

Changing the SharePoint wsp file name.

The default file name given to your solution will match the project name.  I.e. a SharePoint project SharePointProject1 will result in a package SharePointProject1.wsp.

If you want VS to spit out a different name, modify the name attribute in the Package\Package.package file for your project.

To open the file mentioned in the above post, use Notepad as Visual Studio will automatically detect the .package extension and open the associatied template file and NOT the .package file itself.

Also be sure to remove the write protection from the file otherwise Notepad cannot overwrite it.

How to hide Revert to Template Status on the SPD Customized Pages

From this link: http://social.technet.microsoft.com/Forums/sharepoint/en-US/61a953cc-6480-429f-bbee-a34988c1e031/how-to-hide-revert-to-template-status-on-the-spd-customized-pages

But if that's gone here it is:

Here is some information regarding this issue:

=================================

When a wiki page is edited by SPD2010 in advanced mode the page will display a status bar message for all users regardless of permission level.

The current page has been customized from its template.

If user has adequate permissions a link to reset the page to site definition will be displayed as well.

The current page has been customized from its template. Revert to template.

1. Since the page is being unghosted anyways, the easiest workaround, without modifying the page with additional CSS to hide the message, is to copy the content of the page into a blank aspx page and the status message will not display since a blank aspx page is not based on a site definition.

a. Open the page in SPD2010.
b. Switch to code view or split view and copy the markup.
c. Click the site pages site object.
d. Right click in some white space to bring up the context menu.
e. Select New > ASPX and this should get you a blank aspx page.
f. Go into code view on the blank aspx page and paste the content you copied in step b.
g. Save the page and set it as the new home page by right clicking on the page and picking set as home page.

2. Option 2 is: Don't unghost the page.

3. Another option is to create a blank web part page and set it as the home page. This can be made easier by disabling the site feature called Wiki Page Home Page and will more in tune with what users are accustomed to from the 2007 days.

This site feature is on by default when an enterprise wiki is used to create a site or a 2010 team site.

Description:
Wiki Page Home Page
This site feature will create a wiki page and set it as your site home page.

4. You can use the CSS to hide the div that contains the status bar but this might block status bar messages you may want to see.

Depending on your upgrade scenario some customer's have reported that the default.aspx page found in a team site is not used after an upgrade.

I could not reproduce this but the page should reside in the root of the site and can always bet set back to the home page if this scenario does occur.

During my testing I tested the following scenarios:

1. Unghosted default.aspx and visual upgrade performed from the browser. Could not reproduce the issue. Wiki feature is enabled for new page creation.
2. Ghosted default.aspx and a visual upgrade performed from the browser. Could not reproduce the issue. Wiki feature is enabled for new page creation.
3. Ghosted default.aspx page with UpdateUserExperience flag used Windows PowerShell upgrade. Couldn't reproduce issue and wiki feature was disabled.
4. Unghosted default.aspx page with UpdateUserExperience flag used during Windows PowerShell upgrade. Couldn't reproduce issue and wiki feature was disabled after upgrade.

Each time I performed the upgrade I created a new web application. I didn't test this with web application that already had an upgrade performed against it but had the content database deleted.
If you do the UpdateUserExperience flag during the Windows PowerShell command and then enable the Wiki Page Home Page site feature it will create a page in the site pages library called Home.aspx. Your upgraded default.aspx should still be around but you will have a new home page.
The new behavior that is throwing folks off is because of the SharePoint:EmbeddedFormField. This is what the editable region on a wiki page uses. It does not like JavaScript and will strip it out. This is most likely for security reasons.
Also, if you add an image with SPD 2010 to the editable region it will get removed server side by this control unless you prove a path that that adheres to its standard.
The easiest way to figure this out is edit the page in a browser and take note how the src attribute is built. It should contain a URL like this:
/sites/team site/site assets/image.jpg
If you add it with spd the src attribute will contain a value like this:
../site assets/image.jpg
The SharePoint:EmbeddedFormField does not care much for this and will remove it. Other than JavaScript I could not identify any other markup that is changed.
The idea behind this new wiki feature is to allow users to create content without needing an HTML editor like SPD. More to the point, it is a wiki page and the idea behind wiki is to allow a lot of individuals to add content without allowing for unsafe markup that could harm your users/site due to the open nature of wikis.


OR

Insert a HTML Form web part. Replace the source code with the following:

<style type="text/css">
body #pageStatusBar{height:0px; font-size:0px; padding:0px; border-style:none;}
</style>

 


 

OR

Open master page through SPD. Goto code view. then ctrl+F "s4-status"
then type in style:display:none
status bar will be hidden.

 

SharePoint 2010 Template Codes

Each SharePoint site is based on one of the templates provided with the technology. The templates have specific options of SharePoint turned on or off by default. So, sometimes when you inherit a site it is nice to know which template you are using to determine what the site can and cannot do out of the box.

Note: To quickly get a list of SharePoint templates you can even use the Get-SPWebTemplate CMDLet.

Also few of the templates are marked as obsolete i.e the old Records Center template (OFFILE#0) I would suggest you to use the new template if possible when creating a Records center which is (OFFILE#1).

Check the table below for the list of Template & their respective Codes with a brief description.

Name Title Description
GLOBAL#0 Global template This template is used for initializing a new site.
STS#0 Team Site A site for teams to quickly organize, author, and share information. It provides a document library, and lists for managing announcements, calendar items, tasks, and discussions.
STS#1 Blank Site A blank site for you to customize based on your requirements.
STS#2 Document Workspace A site for colleagues to work together on a document. It provides a document library for storing the primary document and supporting files, a tasks list for assigning to-do items, and a links list for resources related to the document.
MPS#0 Basic Meeting Workspace A site to plan, organize, and capture the results of a meeting. It provides lists for managing the agenda, meeting attendees, and documents.
MPS#1 Blank Meeting Workspace A blank meeting site for you to customize based on your requirements.
MPS#2 Decision Meeting Workspace A site for meetings that track status or make decisions. It provides lists for creating tasks, storing documents, and recording decisions.
MPS#3 Social Meeting Workspace A site to plan social occasions. It provides lists for tracking attendees, providing directions, and storing pictures of the event.
MPS#4 Multipage Meeting Workspace A site to plan, organize, and capture the results of a meeting. It provides lists for managing the agenda and meeting attendees in addition to two blank pages for you to customize based on your requirements.
CENTRALADMIN#0 Central Admin Site A site for central administration. It provides Web pages and links for application and operations management.
WIKI#0 Wiki Site A site for a community to brainstorm and share ideas. It providesWeb pages that can be quickly edited to record information and then linked together through keywords.
BLOG#0 Blog A site for a person or team to post ideas, observations, and expertise that site visitors can comment on.
SGS#0 Group Work Site This template provides a groupware solution that enables teams to create, organize, and share information quickly and easily. It includes Group Calendar, Circulation, Phone-Call Memo, the Document Library and the other basic lists.
TENANTADMIN#0 Tenant Admin Site A site for tenant administration. It provides Web pages and links for self-serve administration.
ACCSRV#0 Access Services Site Microsoft Access Server
ACCSRV#1 Assets Web Database Create an assets database to keep track of assets, including asset details and owners.
ACCSRV#3 Charitable Contributions Web Database Create a database to track information about fundraising campaigns including donations made by contributors, campaign related events, and pending tasks.
ACCSRV#4 Contacts Web Database Create a contacts database to manage information about people that your team works with, such as customers and partners.
ACCSRV#6 Issues Web Database Create an issues database to manage a set of issues or problems. You can assign, prioritize, and follow the progress of issues from start to finish.
ACCSRV#5 Projects Web Database Create a project tracking database to track multiple projects, and assign tasks to different people.
BDR#0 Document Center A site to centrally manage documents in your enterprise.
OFFILE#0 (obsolete) Records Center (obsolete) This template creates a site designed for records management. Records managers can configure the routing table to direct incoming files to specific locations. The site also lets you manage whether records can be deleted or modified after they are added to the repository.
OFFILE#1 Records Center This template creates a site designed for records management. Records managers can configure the routing table to direct incoming files to specific locations. The site also lets you manage whether records can be deleted or modified after they are added to the repository.
OSRV#0 Shared Services Administration Site This template creates a site for administering shared services.
PPSMASite#0 PerformancePoint A site for presenting PerformancePoint dashboards and scorecards. The site also includes links to PerformancePoint Dashboard Designer and storage for dashboard content such as analytic charts, reports, KPIs, and strategy maps.
BICenterSite#0 Business Intelligence Center A site for presenting Business Intelligence Center.
SPS#0 SharePoint Portal Server Site This template is obsolete.
SPSPERS#0 SharePoint Portal Server Personal Space This web template defines a Personal Space for an individual participating on a SharePoint Portal.
SPSMSITE#0 Personalization Site A site for delivering personalized views, data, and navigation from this site collection into My Site. It includes personalization specific Web Parts and navigation that is optimized for My Site sites.
SPSTOC#0 Contents area Template This template is obsolete.
SPSTOPIC#0 Topic area template This template is obsolete.
SPSNEWS#0 News Site This template is obsolete.
CMSPUBLISHING#0 Publishing Site A blank site for expanding your Web site and quickly publishing Web pages. Contributors can work on draft versions of pages and publish them to make them visible to readers. The site includes document and image libraries for storing Web publishing assets.
BLANKINTERNET#0 Publishing Site This template creates a site for publishing Web pages on a schedule, with workflow features enabled. By default, only Publishing subsites can be created under this site. A Document and Picture Library are included for storing Web publishing assets.
BLANKINTERNET#1 Press Releases Site This template creates the Press Releases subsite for an Internet-facing corporate presence website.
BLANKINTERNET#2 Publishing Site with Workflow A site for publishing Web pages on a schedule by using approval workflows. It includes document and image libraries for storing Web publishing assets. By default, only sites with this template can be created under this site.
SPSNHOME#0 News Site A site for publishing news articles and links to news articles. It includes a sample news page and an archive for storing older news items.
SPSSITES#0 Site Directory A site for listing and categorizing important sites in your organization. It includes different views for categorized sites, top sites, and a site map.
SPSCOMMU#0 Community area template This template is obsolete.
SPSREPORTCENTER#0 Report Center A site for creating, managing, and delivering Web pages, dashboards, and key performance indicators that communicate metrics, goals, and business intelligence information.
SPSPORTAL#0 Collaboration Portal A starter site hierarchy for an intranet divisional portal. It includes a home page, a News site, a Site Directory, a Document Center, and a Search Center with Tabs. Typically, this site has nearly as many contributors as readers and is used to host team sites.
SRCHCEN#0 Enterprise Search Center A site for delivering the search experience. The welcome page includes a search box with two tabs: one for general searches, and another for searches for information about people. You can add and customize tabs to focus on other search scopes or result types.
PROFILES#0 Profiles This template creates a profile site that includes page layout with zones.
BLANKINTERNETCONTAINER#0 Publishing Portal A starter site hierarchy for an Internet-facing site or a large intranet portal. This site can be customized easily with distinctive branding. It includes a home page, a sample press releases subsite, a Search Center, and a login page. Typically, this site has many more readers than contributors, and it is used to publish Web pages with approval workflows.
SPSMSITEHOST#0 My Site Host A site used for hosting personal sites (My Sites) and the public People Profile page. This template needs to be provisioned only once per User Profile Service Application, please consult the documentation for details.
ENTERWIKI#0 Enterprise Wiki A site for publishing knowledge that you capture and want to share across the enterprise. It provides an easy content editing experience in a single location for co-authoring content, discussions, and project management.
SRCHCENTERLITE#0 Basic Search Center A site for delivering the search experience. The site includes pages for search results and advanced searches.
SRCHCENTERLITE#1 Basic Search Center The Search Center template creates pages dedicated to search. The main welcome page features a simple search box in the center of the page. The template includes a search results and an advanced search page. This Search Center will not appear in navigation.
SRCHCENTERFAST#0 FAST Search Center A site for delivering the FAST search experience. The welcome page includes a search box with two tabs: one for general searches, and another for searches for information about people. You can add and customize tabs to focus on other search scopes or result types.
visprus#0 Visio Process Repository A site for teams to quickly view, share, and store Visio process diagrams. It provides a versioned document library for storing process diagrams, and lists for managing announcements, tasks, and review discussions.