Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.
Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.

Administration

Practical PowerShell Logs

All scheduled PowerShell files should generate LOGs.  “Start-Transcript” is a great cmdlet for this.  Adding a few more features can boost operations support.   LOGs answer essentials support questions like:

  • Which parent PS1 generated this LOG?
  • Did script perform needed functions?
  • Any errors?
  • How long did it take?
  • Which user and computer ran the script?

Below is code template I recommend to for scheduled PowerShell jobs to generate a LOG. Key features include:

  • Auto detect current folder and script PS1
  • Create  \LOG\ subfolder
  • Prefix to match parent PS1
  • Suffix with unique date time stamp
  • Elapsed run duration (Days, Hours, Minutes)

Thank you to @ToddKlindt for improvements to formula and elapsed time.  Cheers. 

shades_smile

Video

Code

function Main() {
    ### YOUR CODE HERE
}

# Open Log
$prefix = $MyInvocation.MyCommand.Name
$host.UI.RawUI.WindowTitle = $prefix
$stamp = Get-Date -UFormat "%Y-%m-%d-%H-%M-%S"
Start-Transcript "$PSScriptRoot\log\$prefix-$stamp.log"
$start = Get-Date

Main

# Close Log
$end = Get-Date
$totaltime = $end - $start
Write-Host "`nTime Elapsed: $($totaltime.tostring("hh\:mm\:ss"))"
Stop-Transcript

Download

https://github.com/spjeff/spadmin/blob/master/Practical-PowerShell-LOGs.ps1

SharePoint – SQL Database Roles

Had a friend ask about SQL database Role Memberships that are needed for SharePoint Server on-premise.  Examined SQL roles on my dev farm.  Reference table below.

Cheers!   

shades_smile

Get-SPServiceApplication

Get-SPDatabase | Select TypeName

SQL Permission Role

App Management

App Management Database

SP_DataAccess

N/A

Configuration Database

dbo, WSS_Content_Application_Pools

N/A

Content Database

SP_DataAccess

Microsoft SharePoint Foundation

Microsoft SharePoint Foundation Subscription Settings Database

SubscriptionSettingsService_Application_Pool

Secure Store

Microsoft.Office.SecureStoreService.Server.SecureStoreServiceDatabase

SP_DataAccess

User Profile

Microsoft.Office.Server.Administration.ProfileDatabase

SP_DataAccess

User Profile

Microsoft.Office.Server.Administration.SocialDatabase

SP_DataAccess

State Service

Microsoft.Office.Server.Administration.StateDatabase

WSS_Content_Application_Pools

User Profile

Microsoft.Office.Server.Administration.SynchronizationDatabase

db_owner

Search Service Application

Microsoft.Office.Server.Search.Administration.SearchAdminDatabase

SPSearchDBAdmin

Search Service Application

Microsoft.Office.Server.Search.Administration.SearchAnalyticsReportingDatabase

SPSearchDBAdmin

Search Service Application

Microsoft.Office.Server.Search.Administration.SearchGathererDatabase

SPSearchDBAdmin

Search Service Application

Microsoft.Office.Server.Search.Administration.SearchLinksDatabase

SPSearchDBAdmin

Machine Translation Service

Microsoft.Office.TranslationServices.QueueDatabase

SP_DataAccess

Word Automation Services

Microsoft.Office.Word.Server.Service.QueueDatabase

SP_DataAccess

PerformancePoint

Microsoft.PerformancePoint.Scorecards.BIMonitoringServiceDatabase

SP_DataAccess

Business Data Connectivity

Microsoft.SharePoint.BusinessData.SharedService.BdcServiceDatabase

SP_DataAccess

Managed Metadata

Microsoft.SharePoint.Taxonomy.MetadataWebServiceDatabase

db_owner

MySite – Export user Quick Links to CSV

When migrating from MySite on-premise to OneDrive in the cloud, Quick Links are not included by third party utilities (i.e. ShareGate).  However, with PowerShell we can export the original raw CSV data and provide a list of links to end users.  They can bookmark or add to Office 365.

Cheers! 

shades_smile

 

Code

# User login parameter
$userLogin = "johndoe"
$mySiteWebApp = Get-SPWebApplication |? {$_.Name -like "*MySite*"}

# Connect to MySite
$site = Get-SPSite $mySiteWebApp.Url
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context);

# Lookup user profile in UPS
$userProfile = $profileManager.GetUserProfile($env:USERDNSDOMAIN + $userLogin);

# Display on console
$userProfile
$userProfile.QuickLinks.GetItems() | Select Title, Url

# Export to CSV file
$userProfile.QuickLinks.GetItems() | Select Title, Url | Export-Csv "C:\temp\$($userLogin)-FollowedLinks.csv" –NoTypeInformation -Force

 

Screenshot

image

 

image

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲