Tuesday, July 5, 2022

How to get workflow manager server information from SharePoint servers.

 Add-PSSnapin microsoft.sharepoint.powershell

$site = Get-SPSite http://sharepoint.contaso.com

$proxy = Get-SPServiceApplicationProxy | ?{$_.TypeName -eq 'Workflow Service Application Proxy'}

$proxy.GetHostname($site)

Thursday, June 9, 2022

Banner on sharepoint sites.

 Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 

Function Add-CustomAction

{

    param

    (

        [parameter(Mandatory=$true, ParameterSetName='Site')]

        [Microsoft.SharePoint.SPSite]$Site,

         

        [parameter(Mandatory=$true, ParameterSetName='Web')]

        [Microsoft.SharePoint.SPWeb]$Web,

         

        [parameter(Mandatory=$true, ParameterSetName='Site')]

        [parameter(Mandatory=$true, ParameterSetName='Web')]

        [string]$Message,

         

        [parameter(Mandatory=$true, ParameterSetName='Site')]

        [parameter(Mandatory=$true, ParameterSetName='Web')]

        [string]$ActionName,

         

        [parameter(Mandatory=$false, ParameterSetName='Web')]

        [switch]$IncludeSubWebs,

 

        [parameter(Mandatory=$true, ParameterSetName='Site')]

        [parameter(Mandatory=$true, ParameterSetName='Web')]

        [string][ValidateSet("Red", "Yellow", "Green", "Blue")]$BackGroundColor

    )

 

    begin

    {

        # To avoid quote conflicts

        $Message = $Message.Replace( "`"", "'")

$startingSequence = 1100

        $JavaScript = @"

 

            function Execute_$($ActionName)_MessageBar_$($PSCmdlet.ParameterSetName)()

            {

                var st = document.getElementById('$ActionName');

                if(st != null)

                {

                    st.style.display = '';

                    return;

                }

 

                st = document.createElement("div");

                st.id = "$($ActionName)_MessageBar_$($PSCmdlet.ParameterSetName)";

                st.innerHTML = "<div class='ms-status-$($BackGroundColor.ToUpper())' style='padding: 12px 14px 6px; border: 1px solid; font-family: \"Segoe UI\", Tahoma, sans-serif; font-size: 13px; min-height: 24px; font-weight: bold; background-color:Yellow;'>$Message</div>";

 

                document.body.insertBefore(st, document.body.childNodes[0]);

            }

 

            // don't show on modal dialog windows

            if(!window.location.search.match("[?&]IsDlg=1"))

            {

                Execute_$($ActionName)_MessageBar_$($PSCmdlet.ParameterSetName)();

            }

"@

    }

    process

    {

        $customAction = $null

         

        if( $PSCmdlet.ParameterSetName -eq "Site" )

        {

            Remove-CustomAction -Site $site -ActionName $ActionName | Out-Null

            $customAction = $Site.UserCustomActions.Add()

        }

        else

        {

            Remove-CustomAction -Web $Web -ActionName $ActionName | Out-Null

            $customAction = $Web.UserCustomActions.Add()

        }

 

        $customAction.Location    = "ScriptLink"

        $customAction.Sequence    = $startingSequence

        $customAction.Title       = $ActionName

        $customAction.ScriptBlock = $JavaScript

        $customAction.Update()

 

        if( $IncludeSubWebs )

        {

            foreach($w in $Web.Webs)

            {

                Add-CustomAction -Web $w -Message $Message -ActionName $ActionName -IncludeSubWebs -BackGroundColor $BackGroundColor

            }

        }

    }

    end

    {

    }

}

 

Function Remove-CustomAction

{

    param 

    (

        [parameter(Mandatory=$true, ParameterSetName='Site')]

        [Microsoft.SharePoint.SPSite]$Site,

         

        [parameter(Mandatory=$true, ParameterSetName='Web')]

        [Microsoft.SharePoint.SPWeb]$Web,

         

        [parameter(Mandatory=$true, ParameterSetName='Site')]

        [parameter(Mandatory=$true, ParameterSetName='Web')]

        [string]$ActionName

    )

 

    begin

    {

        $existingActions = @()

    }

    process

    {

        if( $PSCmdlet.ParameterSetName -eq "Site" )

        {

            $Site.UserCustomActions | ? { $_.Title -eq $ActionName } | % { $existingActions += $_ }

            $existingActions | % { $Site.UserCustomActions.Item($_.Id).Delete() }

        }

        else

        {

            $Web.UserCustomActions | ? { $_.Title -eq $ActionName } | % { $existingActions += $_ }

            $existingActions

            $existingActions | % { $Web.UserCustomActions.Item($_.Id).Delete() }

        }

    }

    end

    {

    }

}

 

$sites = get-spsite "http://sharepoint.com/sites/test" #-Limit all -webapplication http://webapplicationurl/ 


foreach($site in $sites)

{


Add-CustomAction -Site $site -Message “We are planning to migrate this site to Sharepoint 2016 on date ********** The new site URL is 'https://sharepoingonline.com/sites/coc2' " -ActionName "SiteMovedBanner" -BackGroundColor "Red"



#Remove-CustomAction  -Site $site -ActionName "SiteMovedBanner"


}

Tuesday, April 26, 2022

Workflow manager certificate and service bus certificate renewal process

 

Workflow manager certificate and service bus certificate renewal process



Note: This Article is created based on the experience in recent MI, Microsoft has clearly stated this process has to be done by approaching Microsoft. Please log MS ticket before doing this activity. below steps are supposed to be performed with Microsoft on the call.

Step1 : Workflow manager certificate and service bus certificate have both expired.


Workflow services will be automatically stopped once workflow manger certificate expires.

Step 2:

clock should be turned back to a time when the cert is still available, and run the commands on workflow manger server

 

# Check SB and WFM status

Get-sbfarm

Get-sbfarmstatus

Get-wffarm

Get-wffarmstatus

 

The actions we have taken:

1. Backup all WFM and Service Bus Databases. Take WFM server’s VM snapshot too.

 

2. Make sure that the clock is turned back to a time when the cert is still available.

 

3. Run some commands to generate new certificates.

$CertKey=convertto-securestring "YourSecretPassword" -asplaintext -force

Set-WFCertificateAutoGenerationKey -Key $CertKey

Set-SBCertificateAutogenerationKey -Key $CertKey 

 

4. Open MMC to import certificates to 'Trusted Root Certificate Authorities' -> 'Certificate'.

 

5. Run some commands:

Stop-WFHost

Stop-SBFarm

Update-SBHost

Start-SBFarm

 

# Check SB status after start

Get-SBFarm

Get-SBFarmStatus

 

# Complete the WFM configuration to update nodes

Stop-WFHost

Update-WFHost -CertificateAutoGenerationKey $CertKey   

Start-WFHost

 

# Check WFM status after start

Get-WFFarm

Get-WFFarmStatus

 

6. Change the system time back to the current time. Restart the server.


Status:

Workflow manager certificate expired issue has been resolved. Run commands again.

 

# Check SB status

Get-sbfarm

Get-sbfarmstatus



# Check WFM status

Get-wffarm

Get-wffarmstatus




Passed WFMQuickTest.



 

Tuesday, November 30, 2021

Lock Bulk sharepoint sites access to Read only.

 ## Script to set sites readonly or NoAccess##

<#

Inputs

$sourcefile = Specify the location of input TXT file containing list of sites. Simple text file containing all the site URLs -

https://site1.contoso.com

https://site2.contoso.com

https://site3.contoso.com

$LockInformation = additional information about the lock , Work order number and description

$locktype = select whether you need to select site as Readonly or NoAccess

#>

#------------Define Inputs--------------#

# Enter change number and any other text description

$LockInformation = "Description"

# List of site URLs

$sourcefile = "D:\Sitelist.txt"

# Set the below variable to Readonly or NoAccess based on your requirement

$locktype = "ReadOnly"

# Enter Log file name and path to store output

$LogFile = "D:\SiteLockUpdate.log"

#-----------Do not edit below this line-------------#

#Initiate Log File

"SiteURL|LockStatus" | Out-File $LogFile

#Load snapin

Add-PSSnapin Microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$sites = Get-Content $sourcefile

foreach ( $site in $sites )

{

                                try

                                {

                                                $SPSite = Get-SPSite -Identity $site -ErrorAction Stop

                                                $SPSite.LockIssue = $LockInformation

                                                Set-SPSite $SPSite -LockState $locktype

                                                Write-Output "$site|Success-Set to $locktype"| %{Write-Host $_; Out-File $LogFile -InputObject $_ -Append}

                                }

                                Catch [Exception]

                                {

                                                $ErrorMessage = $_.Exception.Message

                                                Write-Output "$site|Failed - $ErrorMessage"| %{Write-Host $_; Out-File $LogFile -InputObject $_ -Append}

                                }                             

}

 

Tuesday, September 28, 2021

jQuery script to hide SharePoint a field in New, Edit, and Display Forms:

Hide List Form Field in SharePoint using jQuery

My earlier post listed various methods such as C# Object model, PowerShell, JavaScript methods to hide columns in SharePoint list forms: Hide Columns in SharePoint List NewForm, EditForm and DispForms

Now, let’s hide fields in SharePoint list form pages using jQuery. Let’s say you have a field called “Parent Project” and want to hide it from All SharePoint list forms such as NewForm.aspx, EditForm.aspx and DispForm.aspx.

jQuery script to hide SharePoint a field in New, Edit, and Display Forms:








<script src="https://code.jquery.com/jquery-1.2.6.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function()

{

   $('td.ms-formlabel:contains("Parent Project")').parent().hide();

});

</script>


These scripts can be placed in Script Editor web part, Custom JS file linked in Master page or as part of SharePoint delegate controls.

To hide fields in SharePoint list form pages using jQuery, Navigate to Newform.aspx or any other form page, Click on site settings icon >> Edit page >> Insert a Script editor web part and paste the above codes accordingly.

hide sharepoint list column using jquery

Consider downloading and placing a jQuery JS file to your SharePoint hive in case, for faster retrieval. E.g. Instead of “http://code.jquery.com/jquery-1.2.6.min.js“, you’ll be placing it in _layouts folder and referring as: http://teamsites.crescent.com/_layouts/jquery-1.2.6.min.js

Ref: https://www.sharepointdiary.com/2013/04/hide-sharepoint-list-form-field-using-jquery.html

Wednesday, June 2, 2021

PowerShell Script - Get the size of the Sites

 I have tested this script on SharePoint 2013 to get the size of the sub-sites with in a Site Collection.


#Get Size of all Sub-sites in a Site Collection
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
# Function to calculate folder size
Function CalculateFolderSize($Folder)
{
    [long]$FolderSize = 0
    foreach ($File in $Folder.Files)
    {
        #Get File Size
        $FolderSize += $file.TotalLength;
        #Get the Versions Size
        foreach ($FileVersion in $File.Versions)
        {
            $FolderSize += $FileVersion.Size
        }
    }

    #Iterate through all subfolders
    foreach ($SubFolder in $Folder.SubFolders)
    {
        #Call the function recursively
        $FolderSize += CalculateFolderSize $SubFolder
    }

    return $FolderSize
}

$SiteURL = "http://MySPSite/sites/portal"
$Site = new-object Microsoft.SharePoint.SPSite($SiteURL)
foreach($Web in $Site.AllWebs)
{ 
    #Call function to calculate Folder Size
    [long]$WebSize = CalculateFolderSize($Web.RootFolder)
    #Get Recycle Bin Size
    foreach($RecycleBinItem in $Web.RecycleBin)
    {
        $WebSize += $RecycleBinItem.Size
    }
    $Size = [Math]::Round($WebSize/1MB, 2)
    Write-Host $web.Url ":`t" $Size "MB"
}

Expected Output:

Find and Delete Orphaned Users in SharePoint

 Orphaned User? Who are they?

Orphaned users are those who have been disabled/removed from Active Directory, but still have permissions to sites, lists and items. Internally, SharePoint keeps them in "UserInfo" table of the content database for meta-data such as created/modified by fields.
how to delete orphaned users in sharepoint

Its unavoidable in any organization where employees constantly on-boarding and off-boarding. Its really difficult to manage, when it comes to thousands of sub-sites, sites, libraries and lists with their own sets of permissions.

SharePoint doesn't automatically remove users when they are deleted or disabled in Active directory!
Why we care about Orphaned users?
It is a best practice to delete orphaned users to keep the farm clean & organized. Also this will solve the problem of deleted active directory users still appearing on the people picker which was discussed here  People Picker not showing users from Active Directory? . If you know the user base or criteria then you can use: Clean-up User Information List

Found only few users and want to delete them?
Go to: http://YOUR-SHAREPOINT-SITE-URL/_layouts/people.aspx?MembershipGroupId=0
This will give the master list of users in site collection, from here you can remove users who are no longer need by clicking "Remove Users from Site Collection"

If you know the orphaned user name (E.g. Employee left the Company), You can go to above URL Filter and delete the particular user. Alternatively, You can query the SQL Server table to find the orphaned users.  Here is how:

Step 1. Open SQL Server Management Studio from SharePoint's SQL box, and run this query for relevant content database.

SELECT * FROM [MOSS_Content_DatabaseName].[dbo].[UserInfo] WHERE tp_Login='DOMAIN\UserID'

Step 2. Take note of the tp_ID column value

Step 3. Go to http://<your sharepoint-site-collection/_layouts/userdisp.aspx?ID=tp_ID, where tp_ID is the number you found from the above select statement.

Step 4. This will take you to the user's profile where you can click on the Delete User from Site Collection button.

However, it is not possible to manually check for SharePoint 2010 orphaned users and clean them, as it would take lot of time. Things become easier with PowerShell, Lets use it here to find & delete Orphaned users in SharePoint.

Ref: Find and Delete Orphaned Users in SharePoint - SharePoint Diary

How to Find and Delete Orphaned Users in SharePoint using PowerShell
Here is my script to Find and Delete Orphaned SharePoint Domain Users: Find and Delete Orphaned Users in SharePoint with PowerShell
Related Post: Remove all alerts assigned to Orphaned users: Find and Delete Orphaned Alerts in SharePoint