gtrapp
asked on
Errors when running PowerShell script
I am on a Windows 2003 Standard Edition SP2 server. I have a WSS 3.0 site. I found this script to cycle through document libraries and turn versioning on and set other versioning settings.
When running the script with PowerShell, I see these errors:
The term 'Get-SPSite' 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 C:\backups\version.ps1:2 char:19
+ $site = Get-SPSite <<<< http://v1
+ CategoryInfo : ObjectNotFound: (Get-SPSite:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Get-SPWeb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
pelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\backups\version.ps1:6 char:18
+ $site | Get-SPWeb <<<< |
+ CategoryInfo : ObjectNotFound: (Get-SPWeb:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
You cannot call a method on a null-valued expression.
At C:\backups\version.ps1:32 char:14
+ $site.Dispose <<<< ()
+ CategoryInfo : InvalidOperation: (Dispose:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I am very new working with WSS 3.0 with PowerShell. Any suggestions would be much appreciated.
When running the script with PowerShell, I see these errors:
The term 'Get-SPSite' 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 C:\backups\version.ps1:2 char:19
+ $site = Get-SPSite <<<< http://v1
+ CategoryInfo : ObjectNotFound: (Get-SPSite:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The term 'Get-SPWeb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
pelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\backups\version.ps1:6 char:18
+ $site | Get-SPWeb <<<< |
+ CategoryInfo : ObjectNotFound: (Get-SPWeb:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
You cannot call a method on a null-valued expression.
At C:\backups\version.ps1:32 char:14
+ $site.Dispose <<<< ()
+ CategoryInfo : InvalidOperation: (Dispose:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I am very new working with WSS 3.0 with PowerShell. Any suggestions would be much appreciated.
$site = Get-SPSite http://site
$listName = "Shared Documents"
#Walk through each site in the site collection
$site | Get-SPWeb |
ForEach-Object {
#Get the list in this site
$list = $_.Lists[$listName]
#Create a version each time you edit an item in this list (lists)
#Create major versions (document libraries)
$list.EnableVersioning = $true
#Create major and minor (draft) versions (document libraries only)
$list.EnableMinorVersions = $true
#Keep the following number of versions (lists)
#Keep the following number of major versions (document libraries)
$list.MajorVersionLimit = 7
#Keep drafts for the following number of approved versions (lists)
#Keep drafts for the following number of major versions (document libraries)
$list.MajorWithMinorVersionsLimit = 5
#Update the list
$list.Update()
}
#Dispose of the site object
$site.Dispose()
try this
function Get-SPSite([string]$url) {
New-Object Microsoft.SharePoint.SPSite($url)
}
function Get-SPWeb([string]$url) {
$SPSite = Get-SPSite $url
return $SPSite.OpenWeb()
$SPSite.Dispose()
}
$site = Get-SPSite http://site
$listName = "Shared Documents"
#Walk through each site in the site collection
$site | Get-SPWeb |
ForEach-Object {
#Get the list in this site
$list = $_.Lists[$listName]
#Create a version each time you edit an item in this list (lists)
#Create major versions (document libraries)
$list.EnableVersioning = $true
#Create major and minor (draft) versions (document libraries only)
$list.EnableMinorVersions = $true
#Keep the following number of versions (lists)
#Keep the following number of major versions (document libraries)
$list.MajorVersionLimit = 7
#Keep drafts for the following number of approved versions (lists)
#Keep drafts for the following number of major versions (document libraries)
$list.MajorWithMinorVersionsLimit = 5
#Update the list
$list.Update()
}
#Dispose of the site object
$site.Dispose()
after your function name add this
[System.Reflection.Assembl y]::LoadWi thPartialN ame("Micro soft.Share Point")
Add-PsSnapin Microsoft.SharePoint.Power Shell
e.g.
function RunThis()
{
[System.Reflection.Assembl y]::LoadWi thPartialN ame("Micro soft.Share Point")
Add-PsSnapin Microsoft.SharePoint.Power Shell
...your code
}
also make sure you are running the script as an administrator (right click -> run as administrator)
what you can also do is create a batch file that will do this for you. Make sure you run this batch file as an administrator. The %~sp0 portion will be the path and folder of your powershell file, and the filename is the powershell filename
powershell.exe -command %~sp0filename.ps1
[System.Reflection.Assembl
Add-PsSnapin Microsoft.SharePoint.Power
e.g.
function RunThis()
{
[System.Reflection.Assembl
Add-PsSnapin Microsoft.SharePoint.Power
...your code
}
also make sure you are running the script as an administrator (right click -> run as administrator)
what you can also do is create a batch file that will do this for you. Make sure you run this batch file as an administrator. The %~sp0 portion will be the path and folder of your powershell file, and the filename is the powershell filename
powershell.exe -command %~sp0filename.ps1
ASKER
I get the following error. I tried to add the Microsoft.SharePoint.Power Shell in the MMC, but its not listed. So, not sure how to add the snapin?
Error:
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
2.
At C:\Backups\2version.ps1:4 char:13
+ Add-PsSnapin <<<< Microsoft.SharePoint.Power Shell
+ CategoryInfo : InvalidArgument: (Microsoft.SharePoint.Powe rShel
l:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft. PowerShell .Commands. Ad
dPSSnapinCommand
Error:
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
2.
At C:\Backups\2version.ps1:4 char:13
+ Add-PsSnapin <<<< Microsoft.SharePoint.Power
+ CategoryInfo : InvalidArgument: (Microsoft.SharePoint.Powe
l:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.
dPSSnapinCommand
ASKER
Do I need to register DLLs for this to work? I have WSS 3.0 and the Microsoft.SharePoint.Power Shell
snap-on works with SharePoint 2007 and MOSS 2010. Is that correct? How would I register the DLLS to make the script work?
Thank you.
snap-on works with SharePoint 2007 and MOSS 2010. Is that correct? How would I register the DLLS to make the script work?
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for you help. I need to go to MOSS 2010.
it looks like the script you are working with was based off of the functions found here http://powershell.com/cs/media/p/3329.aspx