SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
        Write-host "Deleted $contentType content type from $ctuse.Url"
Write-host "Deleted $contentType from site."

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


Thanks for your help!


share|improve this question

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 for examples of how to do this, depending on how you invoke the script.

share|improve this answer

You have to add the following snippet at the top of your code:

    [Parameter(Mandatory=$True, Position=1)]
    [string]$sitename ,
    [Parameter(Mandatory=$True, Position=2)]

Be careful, nothing should be addbefore this, except comments. The snippet allows the script to get input parameters entered by the user. You can also use it like this:

your_powershell_script.ps1 <http://your_site_name> <your_content_type_name>
share|improve this answer

Your Answer


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.