Monday, October 17, 2016

PowerShell Script to List All Users who have access into document library in SharePoint site


Add-PSSnapin "Microsoft.SharePoint.PowerShell"

$web = Get-SPWeb -Identity https://bw.bytes.co.za/applications/

$list = $web.Lists[“Client Billing”]
$siteCollUsers = $web.SiteUsers

$filename = "E:\Applications\application_usersxyz1.csv"

foreach($MyUser in $siteCollUsers)
{
#Write-Host ” ————————————- ”
#Write-Host “Site Collection URL:”, $SiteCollectionURL
if($list.DoesUserHavePermissions([Microsoft.SharePoint.SPBasePermissions]::ViewListItems,$MyUser) -eq $true)
{
#Write-Host “User : “, $MyUser.LoginName
#Write-Host “Assigned Permissions : “, $list.GetUserEffectivePermissions($MyUser.LoginName)

 "User:" + $MyUser.UserLogin +"     "+ "User Name: " +$MyUser.name + "     " + "Email: " +$MyUser.Email  | Out-File $filename -Append


}
#Write-Host ” ————————————- ”
}

Tuesday, October 11, 2016

PowerShell Script to List All Users in All Groups in SharePoint site(SharePoint 2010)

we can run below PowerShell script in SharePoint 2010 management Shell to get  List All Users in All Groups in SharePoint site.

Inputs : $siteUrl,  $filename


$siteUrl="site url"  # url name
$web = Get-SPWeb $siteUrl
$site = $web.Site
$rootWeb = $site.RootWeb
$filename = "E:\Applications\application_users.csv"    # file path name
foreach($group in $site.RootWeb.SiteGroups)
{
   "Group:" + $group.Name | Out-File $filename -Append
   foreach ($user in $group.Users)
   {
       "User:" + $user.UserLogin +"     "+ "User Name: " +$user.name + "     " + "Email: " +$user.Email  | Out-File $filename -Append
   }
}

Wednesday, September 14, 2016

Retreive ALL Service Accounts and Passwords via PowerShell


We can use below script to get all the service accounts passwords


Just copy the following script and paste it into an elevated/admin SharePoint PowerShell

#------------------------------------------------------------------------------------------
# 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
#
#------------------------------------------------------------------------------------------

#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:\

Friday, June 10, 2016

SharePoint server status "Installation Required" or "Upgrade Blocked"

I have noticed that servers in my SharePoint 2013 farm are showing statuses like "Installation Required" or "Upgrade Blocked". 





 When you install the SharePoint (CU) updates on one of SP server, we see the Installation required and upgrade blocked in the status of servers under the system settings in CA.

Installation Required : The server still not yet installed with the same CU that already installed in other servers in the farm.

Upgrade Blocked : The server is blocked from upgrade as they are on latest CU than other servers in the Farm. Current Server is installed with latest CU and it will remained blocked until all the other SP servers in the farm are installed with the same version.

Thursday, October 15, 2015

Converting Word or Excel File To PDF Without Losing Hyperlinks

One of my user experiencing issues with opening hyperlinks from PDF document. the hyperlinks are working in word and excel documents but when converted to PDF then the hyperlinks are displayed but not clickable.

You can covert the word or excel document to PDF including embedded links by doing the following steps,

  1. Go to File→Save As and choose the destination where you want to save your file. Name your file.
  2. Under File Name, you’ll see a drop down menu labelled Save as Type, select PDF.
  3. Under PDF Options (near the bottom), unselect ISO 19005-1 Compliant (PDF/A). Forcing compliance is what disables hyperlinks. By unchecking the box, your links will become clickable. Click Okay.




Thursday, October 8, 2015

Image map with SharePoint designer 2010


A picture with hot spots is called an image map, hot spot is area on an object containing a hyperlink. The picture can contain multiple hot spots.

In SharePoint Designer 2010, all you need to do is open page and select the picture (that you want to add an image map to).  At the top of the Ribbon, click on Picture Tools –> Format –> Hotspot, and then add in whatever hotspots you want (after adding the hotspot, you will be prompted for the URL you are linking to).


Note: This will not work on Publishing Pages, as SharePoint Designer will only let you edit the layout of publishing pages, and not the content.

Tuesday, September 22, 2015

PowerShell script to get all the documents with the last modified date in a SharePoint site

To find out all the documents with the last modified date using PowerShell Script

In Site level,

    If you want to find out in a specific site , please use the following script. Provide the site URL where heighted.

Get-SPWeb http://yoursite[site Url] | Select -ExpandProperty Lists | Where {-not $_.hidden -and $_.GetType().Name -eq "SPDocumentLibrary" } | Select -ExpandProperty Items | Select Name, { $_["Modified"] } | Out-File C:\filename.txt

In Site Collection level,

    If you want to find out in entire site collection, please use the following script. Provide the site collection URL where heighted.

Get-SPSite http://yoursite[site collection url] | Select -ExpandProperty AllWebs | Select -ExpandProperty Lists | Where {-not $_.hidden -and $_.GetType().Name -eq "SPDocumentLibrary" } | Select -ExpandProperty Items | Select Name, { $_["Modified"] } | Out-File C:\filename.txt