Tuesday, April 7, 2015

Recover SharePoint Farm Managed Account Passwords

You lost password for SharePoint accounts? Recover them from PowerShell

This script will Display the SharePoint Farm Managed Accounts password including the Farm Account, without requiring the current user to be a part of the SharePoint Farm Admin Group.

Run PowerShell as Administrator on a SharePoint Server.



Download script


#------------------------------------------------------------------------------------------
# Name:            Recover-SPManagedAccounts
# Description:    This script will retrieve the Farm Account credentials and show the 
#                passwords for all of the SharePoint Managed Accounts
# Usage:        Run the script on a SP Server with an account that has Local Admin Rights
# By:            Ivan Josipovic, Softlanding.ca
#------------------------------------------------------------------------------------------

#Checks if the Current PowerShell Session is running as the Administrator
if(([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") -eq $false){
    Throw "This Script must be ran as Administrator"
}

#This section retrives the Farm Account UserName/Password from the Security Token Service Application Pool
$Farm_user = C:\Windows\System32\cmd.exe /q /c $env:windir\system32\inetsrv\appcmd.exe list apppool "SecurityTokenServiceApplicationPool" /text:ProcessModel.UserName;
$Farm_pass = C:\Windows\System32\cmd.exe /q /c $env:windir\system32\inetsrv\appcmd.exe list apppool "SecurityTokenServiceApplicationPool" /text:ProcessModel.Password;
$Credential = New-Object System.Management.Automation.PsCredential($Farm_user, (ConvertTo-SecureString $Farm_pass -AsPlainText -Force));

# This line contains the script which returns the account passwords, script is from http://sharepointlonghorn.com/Lists/Posts/Post.aspx?ID=11
$GetManagedAccountPasswords = "
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0;
function Bindings(){
    return [System.Reflection.BindingFlags]::CreateInstance -bor
    [System.Reflection.BindingFlags]::GetField -bor
    [System.Reflection.BindingFlags]::Instance -bor
    [System.Reflection.BindingFlags]::NonPublic;
}
function GetFieldValue([object]`$o, [string]`$fieldName){
    `$bindings = Bindings;
    return `$o.GetType().GetField(`$fieldName, `$bindings).GetValue(`$o);
}
function ConvertTo-UnsecureString([System.Security.SecureString]`$string){ 
    `$intptr = [System.IntPtr]::Zero;
    `$unmanagedString = [System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUnicode(`$string);
    `$unsecureString = [System.Runtime.InteropServices.Marshal]::PtrToStringUni(`$unmanagedString);
    [System.Runtime.InteropServices.Marshal]::ZeroFreeGlobalAllocUnicode(`$unmanagedString);
    return `$unsecureString;
}
Get-SPManagedAccount | select UserName, @{Name='Password'; Expression={ConvertTo-UnsecureString (GetFieldValue `$_ 'm_Password').SecureStringValue}}";

#Writes the Script to the Public Folder (C:\Users\Public), this is required as we cant run the script inline as its too long.
Set-Content -Path "$($env:public.TrimEnd("\"))\GetManagedAccountPasswords" -Value $GetManagedAccountPasswords;

#The Script which will be ran in the new PowerShell Window running as the Farm Account, it also removes the script above which we wrote to the file system
$Script = "
`$Script = Get-Content `"$($env:public.TrimEnd("\"))\GetManagedAccountPasswords`";
PowerShell.exe -Command `$Script;
Remove-Item `"$($env:public.TrimEnd("\"))\GetManagedAccountPasswords`";
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0;"

#Runs PowerShell as the Farm Account and loads the Script above
Start-Process -FilePath powershell.exe -Credential $Credential -ArgumentList "-noexit -command $Script" -WorkingDirectory C:\





Monday, April 6, 2015

Create new Host Header Site Collection in a new content database SharePoint 2013

Host-Named Site Collection (HNSC) is actually a means to have a separate DNS for each site collection rather than having all the site collections follow the URL of the web application (path-based site collections). Now you can to have and separate database with PowerShell.

 Download script


Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
 $webapp = Read-Host "Enter WebApplication URL"
 $dbserver = Read-Host "Enter SQL Server"
 $siteurl = Read-Host "Enter Host Header Site Collection URL"
 $site = Read-Host "Enter Host Header Site Collection Name"
 $language = Read-Host "Enter Language (2074)"
 $dbname = Read-Host "Enter ContentDB name of WebApplication"
 $dbname1 = Read-Host "Enter ContentDB name of HHSC"
 $owner1 = Read-Host "Enter Primary Site Collection Administrator (DOMAIN\UserName)"
 $owner2 = Read-Host "Enter Secondary Site Collection Administrator (DOMAIN\UserName)"
 New-SPContentDatabase -Name $dbname1 -DatabaseServer $dbserver -WebApplication $webapp | out-null
 New-SPSite $siteurl -OwnerAlias $owner1 -SecondaryOwnerAlias $owner2 -ContentDatabase $dbname1 -HostheaderWebApplication $webapp -Name $site -Language $language
 Get-SPContentDatabase -Site $siteUrl | Set-SPContentDatabase -maxSiteCount 1 -WarningSiteCount 0
Write-Host “Site Collection at” $site “has been created in the” $dbname1 “content database” -ForegroundColor Yellow


Create HostA in DNS.
Open IIS Manager, Sites, Edit Bindings on WebApplication, add Site Binding (picture).
Change on all SharePoint servers.
















When you open site in browser choose site template and set up groups for site.

Wednesday, April 1, 2015

Import Google embed map in SharePoint web part


How to Embed Google Maps to a SharePoint?

Google Maps can be embedded onto a Microsoft SharePoint page very easily using a Google Maps and web part.


Open https://maps.google.com


Find location. 

















 




 
Copy link.


























Open SharePoint site, Edit page, Insert, Embed Code.



















Paste link.

Insert.

 
Save.