Thursday, December 15, 2016

O365 Powershell script to Delete user from User Profile

#Add SharePoint PowerShell SnapIn if not already added
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}


$site = new-object Microsoft.SharePoint.SPSite("http://skvkfm-it01/");
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);

#Get UserProfileManager from the My Site Host Site context
$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)  
$AllProfiles = $ProfileManager.GetEnumerator()

foreach($profile in $AllProfiles)
{
    $DisplayName = $profile.DisplayName
    $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value

    #Do not delete setup (admin) account from user profiles. Please enter the account name below
    if($AccountName -ne "Domain\MySiteSVApp")
    {
        $ProfileManager.RemoveUserProfile($AccountName);
        write-host "Profile for account ", $AccountName, " has been deleted"
    }

}
write-host "Finished."
$site.Dispose() 

O365 Powershell script to Delete user from given site

#Add SharePoint PowerShell SnapIn if not already added
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}


#Remove site users retireved from AD in notepad file, create RemovedUsers.txt to write the users

$url = "http://teamsite/sites/Test"

$CurrentDirectory =  Split-Path -parent $MyInvocation.MyCommand.Definition
$users= Get-content "$CurrentDirectory\users.txt"


foreach($user in $users)
{

Write-Host $user


Remove-SPUser -Identity $user -Web $Web -Confirm:$False


Add-Content RemovedUsers.txt $user

}

write-Host "Finished"

O365 Powershell script to Delete User from Entire Web Application

#Add SharePoint PowerShell SnapIn if not already added
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}



#Delete from entire site coll, create RemovedUsers.txt to write the users


#Get the web application

$WebApp = Get-SPWebApplication $WebAppURL

#Loop through each site collection

foreach ($Site in $WebApp.Sites)
{


$CurrentDirectory =  Split-Path -parent $MyInvocation.MyCommand.Definition
$users= Get-content "$CurrentDirectory\users.txt"

foreach($user in $users)
{

Write-Host $user

Remove-SPUser -Identity $user -Web $Web -Confirm:$False

Add-Content RemovedUsers.txt $user

}


}


write-Host "Finished"

O365 Powershell script to get SharePoint Web Groups and its Count

Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
 Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell
}


$username = "username@microsoft.com"
$password = "12345"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force

Add-Type -Path "D:\Dlls\Microsoft.SharePoint.Client.dll"
Add-Type -Path "D:\Dlls\Microsoft.SharePoint.Client.Runtime.dll"
#Get the Client Context and Bind the Site Collection


function Get-SPGroups()
{

//Load your sites as input file
$getSites= Get-content "D:\Scripts\Sites.txt"

foreach($webUrl in $getSites)
{

try{

$context = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
#Authenticate
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$context.Credentials = $credentials
$web = $context.Web;
$context.Load($web)
$context.ExecuteQuery()
Write "Url: $webUrl : $_" >>D:\Scripts\UrlProcessed.txt
}
catch{
Write "Error: $webUrl : $_" >>D:\Scripts\Error.txt -Append
continue;
}


$ListItemCollection = @()
$groups = $web.RoleAssignments.Groups
$context.Load($groups);
$context.ExecuteQuery()

foreach($grp in $groups) {


$data = @{
                        "Site URL" = $webUrl
                        "Site Title" = $web.Title
                        "Group Name" = $grp.Title
"Group Count" = $groups.Count                                      
}

New-Object PSObject -Property $data | Select "Site URL", "Site Title","Group Name", "Group Count"



}

}

$context="";



}

Get-SPGroups  | Export-Csv -NoTypeInformation -Path D:\Scripts\Sites1.csv

O365 Powershell script to get List Item Properties with Versions

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$web = Get-SPWeb -identity "Site URL"
$list = $web.Lists["ListName"]

$ListItemCollection = @()

foreach ($item in $list.Items) {
foreach($version in $item.Versions){
$data = @{
                        "Version" = $version.VersionLabel
                        "List Name" = $list.Title
                        "Created By" = $item["Author"]
                        "Created Date" = $item["Created"]
                        "Modified By" = $item["Editor"]
                        "Modified Date" = $item["Modified"]
                        "Item Name" = $item.File.Name                      
}
$ExportItem = New-Object PSObject -Property $data | Select "List Name", "Item Name", "Version", "Created By", "Created Date", "Modified By", "Modified Date"

$ListItemCollection += $ExportItem

}
}

$ListItemCollection | Export-CSV D:\List.csv -NoTypeInformation 

Wednesday, June 8, 2016

Setup is unable to proceed due to the following error(s): This product requires Microsoft .Net Framework 4.5

when I was installing SharePoint 2013 for a client.

Setup is unable to proceed due to the following error(s): This product requires Microsoft .Net Framework 4.5
So you need to check which version of .NET framework is installed on the server :
 Set-Location 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client'
 Get-ItemProperty -Path . | Select-Object Version
Then depending on the version installed and the OS you're using, you need to uninstall the corresponding KB :
  1. Windows 8 ou Windows Server 2012 : KB3102439
  2. Windows 8.1 or Windows Server 2012 R2 : KB3102467
  3. Windows 10 : KB3102495
  1. Windows 8 or Windows Server 2012 : KB3045562
  2. Windows 8.1 or Windows Server 2012 R2 : KB3045563

I have used to remove the "KB3102439" from installed updates and restarted my machine and ran SharePoint 2013 setup, it worked fine.



Wednesday, April 6, 2016

SharePoint 2013 - Not able to see Navigation Panel, Add an App, Site Permission settings



In SharePoint 2013, if you modify any thing in Master Page file, it may cause below issues:

1. Site Settings->navigations not appearing correctly as mentioned below.




2. Site Settings->Site Permissions, not able to find Grant Permission, Check permission tool bar as mentioned below.


3. Site Contents->Add an app, page should be blank.

The above issues are may be possible of having below scripts in Master Page.

<script type="text/javascript" src="/_layouts/15/init.js"></script>

If it exists, remove it and save and check the page.