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 try and run this Script using Powershell ISC run as Admin:

 #Site URL
 $web = Get-SPWeb "http://cgprojects/sites/tfs";
 $web.AllowUnsafeUpdates = $true;    

 #List Name
 $list = $web.Lists["Project Initiation"];

 # Iterate through all Items in List and all Workflows on Items.         
 foreach ($item in $list.Items) {
 foreach ($wf in $item.Workflows) {

 #Cancel Workflows        
 [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf);      
 }
 }
 $web.Dispose()

What I get is this result:

The term 'Get-SPWeb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:2 char:18 + $web = Get-SPWeb <<<< "http:// "; + CategoryInfo : ObjectNotFound: (Get-SPWeb:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Property 'AllowUnsafeUpdates' cannot be found on this object; make sure it exists and is settable. At line:3 char:7 + $web. <<<< AllowUnsafeUpdates = $true;
+ CategoryInfo : InvalidOperation: (AllowUnsafeUpdates:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound Cannot index into a null array. At line:6 char:21 + $list = $web.Lists[ <<<< "Project Initiation"]; + CategoryInfo : InvalidOperation: (Project Initiation:String) [], RuntimeException + FullyQualifiedErrorId : NullArray Unable to find type [Microsoft.SharePoint.Workflow.SPWorkflowManager]: make sure that the assembly containing this type is loaded. At line:13 char:51 + [Microsoft.SharePoint.Workflow.SPWorkflowManager] <<<< ::CancelWorkflow($wf);
+ CategoryInfo : InvalidOperation: (Microsoft.Share...WorkflowManager:String) [], RuntimeException + FullyQualifiedErrorId : TypeNotFound You cannot call a method on a null-valued expression. At line:16 char:14 + $web.Dispose <<<< () + CategoryInfo : InvalidOperation: (Dispose:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

share|improve this question

2 Answers 2

up vote 1 down vote accepted

As @Mohammad mentioned, you need to load the SharePoint Snapin in order to avoid this error:

Add-PSSnapin Microsoft.SharePoint.PowerShell
share|improve this answer

Did you try running the command from SharePoint Management Shell? Seems like SharePoint Snapin is not loaded.

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.