3

PS C:\logfiles> dir

Directory: C:\logfiles

Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 12/11/2013 2:54 PM 50707 Detail_LandingPage.txt -a--- 12/12/2013 10:36 AM 1641 Post-KJUninstall.ps1

PS C:\logfiles> Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFiles\Detail_La ndingPage.txt }" Unexpected token '}' in expression or statement. At line:1 char:80 + Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFiles\Detail_LandingPage.txt } <<<< " + CategoryInfo : ParserError: (}:String) [], ParentContainsErrorR ecordException + FullyQualifiedErrorId : UnexpectedToken

PS C:\logfiles> Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFiles\Detail_La ndingPage.txt"

Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFiles\Detail_LandingPage.txt " The term 'Post-KJUninstall.ps1' is not recognized as the name of a cmdlet, func tion, 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:1 char:21 + Post-KJUninstall.ps1 <<<< -UninstallLogFilePath C:\LogFiles\Detail_LandingPa ge.txt" + CategoryInfo : ObjectNotFound: (Post-KJUninstall.ps1:String) [] , CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

PS C:\logfiles> PS C:\logfiles> Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFiles\Detail_La ndingPage.txt"

> > > >

Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFiles\Detail_LandingPage.txt " The term 'Post-KJUninstall.ps1' is not recognized as the name of a cmdlet, func tion, 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:1 char:21 + Post-KJUninstall.ps1 <<<< -UninstallLogFilePath C:\LogFiles\Detail_LandingPa ge.txt" + CategoryInfo : ObjectNotFound: (Post-KJUninstall.ps1:String) [] , CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

PS C:\logfiles> Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFiles\Detail_La ndingPage.txt The term 'Post-KJUninstall.ps1' is not recognized as the name of a cmdlet, func tion, 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:1 char:21 + Post-KJUninstall.ps1 <<<< -UninstallLogFilePath C:\LogFiles\Detail_LandingPa ge.txt + CategoryInfo : ObjectNotFound: (Post-KJUninstall.ps1:String) [] , CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

PS C:\logfiles> c:\LogFiles\Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFil es\Detail_LandingPage.txt The term 'c:\LogFiles\Post-KJUninstall.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the n ame, or if a path was included, verify that the path is correct and try again. At line:1 char:33 + c:\LogFiles\Post-KJUninstall.ps1 <<<< -UninstallLogFilePath C:\LogFiles\Deta il_LandingPage.txt + CategoryInfo : ObjectNotFound: (c:\LogFiles\Post-KJUninstall.ps 1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

PS C:\logfiles> c:\LogFiles\Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFil es\Detail_LandingPage.txt

Param($UninstallLogFilePath) 
$file = $UninstallLogFilePath 

Add-PSSnapin Microsoft.SharePoint.PowerShell 

$powerPivotFeatures = @("1a33a234-b4a4-4fc6-96c2-8bdb56388bd5", "e9c4784b-d453-46f5-8559-3c891d7159dd", "f8c51e81-0b46-4535-a3d5-244f63e1cab9") 
$premiumSiteId = "8581a8a7-cf16-4770-ac54-260265ddb0b2" 

#Remove PowerPivot features 
foreach($featureId in $powerPivotFeatures) 
{ 
    if(Get-SPFeature | where {$_.Id -eq $featureId}) 
    { 
        Write-Host "Found feature $featureId" 
        Uninstall-SPFeature -Id $featureId -force 
    } 
} 

# Verify if the premium site feature was indeed removed 
$premiumSiteFeature = Get-SPFeature | where {$_.Id -eq $premiumSiteId} 
if($premiumSiteFeature -eq $null) 
{ 
    # Re-install the feature 
    Install-SPFeature -path PremiumSite 
} 

switch -regex -file $file 
{ 
    "de-activating feature"    { 
                    # This will return every entry in the file for feature deactivation 
                    $Url = $_.Split() | ?{$_ -match "http://([a-zA-Z0-9_\-]+)([\.][[a-zA-Z0-9_\-]+)*(\:[0-9]+)*(/\S*)?"} 
                    #Remove the period at the end 
                    $Url = $Url.Substring(0, $Url.Length – 1) 
                    # Match the Guid for the feature 
                    $Id = $_.Split() | ?{$_ -match "([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}"} 
                    if(!($powerPivotFeatures -contains $Id)) 
                    { 
                        Write-Host "Re-activating feature $Id on site $Url" 
                        Enable-SPFeature -Id $Id -Url $Url 
                        trap 
                            { 
                                Write-Host "Could not Re-activate feature $Id on site $Url" 
                                Write-Host $("Exception: "+ $_.Exception.Message); 
                                continue 
                            } 
                    } 

                    continue 
                } 
} 
  • If you changed the title to PowerShell instead of SharePoint Management Shell, this question would be out of topic for SharePoint StackExchange. Is this working in PS but not in SharePoint Management Shell, or is there any other reason why this question belongs here? – Robert Lindgren Dec 12 '13 at 12:07
4

to execute a script in powershell, create the script in notepad++ save as .ps1 (powershell).

save to desktop.

open powershell as admin, drag the file from desktop and drop the file into the shell and hit enter. It should run fine!

edit

Please make sure you follow these steps!

1) run sharepoint 2010 managment shell as admin

2) run this code: Add-PSSnapin Microsoft.SharePoint.PowerShell

3) create your ps1 from notepad++ as it contains the extention method .ps1 when you save the file rather than renaming the file from a text file!

4) save the file to desktop

5) drag the saved file and drop it into sharepoint 2010 managment shell, now hit enter... it should run your code within your file!

just try the above to see it work! dont do: Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFiles\Detail_La ndingPage.txt all you want to see is if its going to run your ps1 file first!

EDIT

now we know its not your powershell thats broken but the script!

look at your params:

Param($UninstallLogFilePath)

change to

Param([String]$UninstallLogFilePath="") 

now in powershell do:

Post-KJUninstall.ps1 -UninstallLogFilePath "C:\LogFiles\Detail_LandingPage.txt"
  • I get that error: PS C:\logfiles> c:\LogFiles\Post-KJUninstall.ps1 -UninstallLogFilePath C:\LogFil es\Detail_LandingPage.txt The term 'c:\LogFiles\Post-KJUninstall.ps1' is not recognized as the name of a cmdlet, function, script file, or operable – JulianoG Dec 12 '13 at 11:01
  • what version of sharepoint are you using? 2010? – Ali Jafer Dec 12 '13 at 11:04
  • yes 2010 Ali!!! – JulianoG Dec 12 '13 at 11:04
  • are you opening sharepoint 2010 managment shell? or are you using the standard powershell? – Ali Jafer Dec 12 '13 at 11:05
  • sharepoint 2010 managment shell – JulianoG Dec 12 '13 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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