none
Is there a PowerShell script to publish all Content types in SPO - Content type hub? RRS feed

  • Question

  • Hello,

    Is there a PowerShell script to publish all Content types in SPO - Content type hub?

    Monday, June 17, 2019 6:44 PM

Answers

  • Here is the script which I received from Microsoft support

    function Publish-ContentType {

    param(

    [Parameter(Mandatory = $true)] [string]$ContentTypeHubUrl,

    [Parameter(Mandatory = $true)] [string]$ContentTypeId,

    [Parameter(Mandatory = $true)] [string]$Username,

    [Parameter(Mandatory = $true)] [string]$Password

    )

     

    Write-Host "Logging into SharePoint via the browser"

     

    # create a new COM object for IE autmation

    $ie = New-Object -ComObject 'internetExplorer.Application'

    $ie.Visible = $true

     

    # if a user is logged in, log them out

    $ie.Navigate("https://login.microsoftonline.com/logout.srf")

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

     

    #navigate to the Office 365 login page

    $ie.Navigate("https://login.microsoftonline.com/login.srf")

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

     

    # get the page elements. GetElementById will not work in modern operating systems. Use the workaround as shown

    $usernameField = $ie.Document.body.getElementsByTagName('input') |? {$_.id -eq 'cred_userid_inputtext' }

    $passwordField = $ie.Document.body.getElementsByTagName('input') |? {$_.id -eq 'cred_password_inputtext' }

    $signInButton = $ie.Document.body.getElementsByTagName('button') |? {$_.id -eq 'cred_sign_in_button' }

     

    # simulate the same actions the user would perform while logging in

    $usernameField.focus()

    $usernameField.value = $Username

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

    $passwordField.focus()

    $passwordField.value = $Password

     

    # to get the login to work, first set focus and click on the sign in button. Then, wait for

    # the username postback to complete and click the button again

    $signInButton.focus()

    $signInButton.click()

    Start-Sleep -Seconds 3

    $signInButton.click()

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

     

    # navigate to the publishing settings page for the content type

    Write-Host "Publishing content type"

    $ie.Navigate("$($ContentTypeHubUrl)/_layouts/15/managectpublishing.aspx?ctype=$($ContentTypeId)")

    Start-Sleep -Seconds 3

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

     

    # throw an error if we do not reach the content type publishing page (i.e. failed login, bad content type id)

    if (-not $ie.Document.location.pathname.EndsWith("/_layouts/15/managectpublishing.aspx")) {

    throw "Unable to navigate to content type publishing page."

    }

     

    $publishButton = $ie.Document.body.getElementsByTagName('input') |? {$_.value -eq 'publishButton' }

    $publishButton.checked = $true

    $okButton = $ie.Document.body.getElementsByTagName('input') |? {$_.value -eq 'OK' }

    $okButton.click()

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

     

    $ie.Quit()

    }


    • Marked as answer by Vinoth_C Monday, July 8, 2019 8:05 PM
    Monday, July 8, 2019 8:05 PM

All replies

  • Hi Vinoth,

    whereas i know you can publish and republish Content Types from Content Type Hub using server side PowerShell on on-premises SharePoint, but there is no way of doing the same programmatically in SharePoint Online.

    This is one stuff which you have to do it manually i guess.

    Thanks & Regards,


    sharath aluri

    Monday, June 17, 2019 11:37 PM
  • Hi Vinoth_C,

    In SharePoint online, we only can use CSOM PowerShell script.

    And to publish the content type, we should use the server-side PowerShell script.

    I am afraid we cannot achieve your requirement in SharePoint online.

    There is a similar issue.

    https://sharepoint.uservoice.com/forums/329220-sharepoint-dev-platform/suggestions/15147111-allow-publishing-of-content-type-hub-content-types

    Best regards,

    Sara Fan


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, June 18, 2019 2:28 AM
    Moderator
  • Hi Vinoth_C,

    If the reply is helpful to you, you could mark the reply as answer. Thanks for your understanding.

    Best regards,

    Sara Fan

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, June 19, 2019 6:38 AM
    Moderator
  • Here is the script which I received from Microsoft support

    function Publish-ContentType {

    param(

    [Parameter(Mandatory = $true)] [string]$ContentTypeHubUrl,

    [Parameter(Mandatory = $true)] [string]$ContentTypeId,

    [Parameter(Mandatory = $true)] [string]$Username,

    [Parameter(Mandatory = $true)] [string]$Password

    )

     

    Write-Host "Logging into SharePoint via the browser"

     

    # create a new COM object for IE autmation

    $ie = New-Object -ComObject 'internetExplorer.Application'

    $ie.Visible = $true

     

    # if a user is logged in, log them out

    $ie.Navigate("https://login.microsoftonline.com/logout.srf")

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

     

    #navigate to the Office 365 login page

    $ie.Navigate("https://login.microsoftonline.com/login.srf")

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

     

    # get the page elements. GetElementById will not work in modern operating systems. Use the workaround as shown

    $usernameField = $ie.Document.body.getElementsByTagName('input') |? {$_.id -eq 'cred_userid_inputtext' }

    $passwordField = $ie.Document.body.getElementsByTagName('input') |? {$_.id -eq 'cred_password_inputtext' }

    $signInButton = $ie.Document.body.getElementsByTagName('button') |? {$_.id -eq 'cred_sign_in_button' }

     

    # simulate the same actions the user would perform while logging in

    $usernameField.focus()

    $usernameField.value = $Username

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

    $passwordField.focus()

    $passwordField.value = $Password

     

    # to get the login to work, first set focus and click on the sign in button. Then, wait for

    # the username postback to complete and click the button again

    $signInButton.focus()

    $signInButton.click()

    Start-Sleep -Seconds 3

    $signInButton.click()

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

     

    # navigate to the publishing settings page for the content type

    Write-Host "Publishing content type"

    $ie.Navigate("$($ContentTypeHubUrl)/_layouts/15/managectpublishing.aspx?ctype=$($ContentTypeId)")

    Start-Sleep -Seconds 3

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

     

    # throw an error if we do not reach the content type publishing page (i.e. failed login, bad content type id)

    if (-not $ie.Document.location.pathname.EndsWith("/_layouts/15/managectpublishing.aspx")) {

    throw "Unable to navigate to content type publishing page."

    }

     

    $publishButton = $ie.Document.body.getElementsByTagName('input') |? {$_.value -eq 'publishButton' }

    $publishButton.checked = $true

    $okButton = $ie.Document.body.getElementsByTagName('input') |? {$_.value -eq 'OK' }

    $okButton.click()

    while ($ie.Busy -eq $true) { Start-Sleep -Milliseconds 400 }

     

    $ie.Quit()

    }


    • Marked as answer by Vinoth_C Monday, July 8, 2019 8:05 PM
    Monday, July 8, 2019 8:05 PM
  • Hi Vinoth_C,

    It is very happy that you have resolved your problem.

    Thank you for your sharing and it will help others have the same issue.

    Best regards,

    Sara Fan

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, July 9, 2019 1:36 AM
    Moderator