Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am new to PowerShell script. I am trying to run this specific script using .ps1 but received an error. Where do I put our SharePoint URL and the Content Type name in the script. Here is the script below:

$sitename = $args[0]
$contentType = $args[1]

$web = Get-SPWeb $sitename
$ct = $web.ContentTypes[$contentType]

if ($ct) {
$ctusage = [Microsoft.SharePoint.SPContentTypeUsage]::GetUsages($ct)
  foreach ($ctuse in $ctusage) {
        $list = $web.GetList($ctuse.Url)
        $contentTypeCollection = $list.ContentTypes;
        $contentTypeCollection.Delete($contentTypeCollection[$ContentType].Id);
        Write-host "Deleted $contentType content type from $ctuse.Url"
        }
$ct.Delete()
Write-host "Deleted $contentType from site."

} else { Write-host "Nothing to delete." }

$web.Dispose()

Thanks for your help!

Matthew

share|improve this question

1 Answer 1

You need to pass the values in as arguments to the script.

The first argument is the site URL, the second is the content type name.

See http://www.powershell.nu/2009/12/16/running-scripts-with-arguments-in-powershell/ for examples of how to do this, depending on how you invoke the script.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.