PowerShell script to Retract & Remove all farm solutions

Hi,
I need the PowerShell script to Retract & Remove all SharePoint farm solutions.
Single solution Retract & Remove
Uninstall-SPSolution -Identity <Solution name.wsp>
ex: Uninstall-SPSolution -Identity Solution.wsp
Remove-SPSolution -Identity <Solution name.wsp>
ex: Remove-SPSolution -Identity Solution.wsp

Install & Uninstall solutions from folder
file name - installwsp.ps1
Add-PsSnapin Microsoft.SharePoint.PowerShell
#Do not modify anything in the script from here onwards
function Get-ScriptDirectory
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
function Deploy-Solution{
param(
[string]$physicalPath,
[string]$name)
$SolutionName = $name
$SolutionPath = Join-Path ($physicalPath) $SolutionName
echo "Extracting information from $physicalPath"
#Admin service
$AdminServiceName = "SPAdminV4"
$IsAdminServiceWasRunning = $true;
if ($(Get-Service $AdminServiceName).Status -eq "Stopped")
$IsAdminServiceWasRunning = $false;
Start-Service $AdminServiceName
Write-Host 'SERVICE WAS STOPPED, SO IT IS NOW STARTED'
#Uninstall
Write-Host 'UNINSTALLING SOLUTION ...'
$Solution = Get-SPSolution | ? {($_.Name -eq $SolutionName) -and ($_.Deployed -eq $true)}
if ($Solution -ne $null)
if($Solution.ContainsWebApplicationResource)
Uninstall-SPSolution $SolutionName -AllWebApplications -Confirm:$false
else
Uninstall-SPSolution $SolutionName -Confirm:$false
while ($Solution.JobExists)
Start-Sleep 2
Write-Host 'SOLUTION HAS BEEN UNINSTALLED SUCCESSFULLY.'
Write-Host 'REMOVING SOLUTION ...'
if ($(Get-SPSolution | ? {$_.Name -eq $SolutionName}).Deployed -eq $false)
Remove-SPSolution $SolutionName -Confirm:$false
Write-Host 'SOLUTION HAS BEEN REMOVED SUCCESSFULLY.'
Write-Host 'ADDING SOLUTION ...'
Add-SPSolution $SolutionPath | Out-Null
Write-Host 'SOLUTION HAS BEEN ADDED SUCCESSFULLY.'
Write-Host 'DEPLOYING SOLUTION ...'
$Solution = Get-SPSolution | ? {($_.Name -eq $SolutionName) -and ($_.Deployed -eq $false)}
#use '-force' paramater to install all commands in this if statement
if(($Solution -ne $null) -and ($Solution.ContainsWebApplicationResource))
Install-SPSolution $SolutionName –AllwebApplications -GACDeployment -Force -Confirm:$false
else
Install-SPSolution $SolutionName -GACDeployment -Force -Confirm:$false
while ($Solution.Deployed -eq $false)
Start-Sleep 2
Write-Host 'SOLUTION HAS BEEN DEPLOYED SUCCESSFULLY.'
if (-not $IsAdminServiceWasRunning)
Stop-Service $AdminServiceName
#Get Current Physical Path
$currentPhysicalPath = Get-ScriptDirectory
#Iterate through all .wsp files in the current Physical Path to deploy solution
get-childitem $currentPhysicalPath -include *.wsp -recurse | foreach ($_) {Deploy-Solution $currentPhysicalPath $_.name}
#Remove SharePoint Snapin
Remove-PsSnapin Microsoft.SharePoint.PowerShell
Echo Finish
Usage file name - installwsp.bat
cd /c %~dp0
powershell -noexit -file "installwsp.ps1" "%CD%"
pause
Anandhan.S Remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

Similar Messages

  • How to get list of all sp farm solutions using powershell?

    is there any powershell script can list down all solutions deployed on farm in txt or cvs file?

    Thanks. but this is showing all features. I need only our custom developed features
    Get-SPFeature >> c:\temp\feature.txt
    Let me know how to get?

  • Executing a powershell script for checking duplicate users while creating a AD user throug ADUC console.

    Hi,
    I have a text file in which some SamAccountNames are present.I need to check the file while creating a new users through ADUC console.If a username that is going to create through ADUC console is present in the file, then it should prompt a message
    that the user is already present in the text file.
    Is there any possibility of contacting the powershell script from the ADUC console.If so, then while creating a new user through ADUC console, what is the proceedure for executing that powershell script.
    please provide me the approriate solutions.
    Thanks
    Prasanthi k

    Run the below Powershell Script for users are exist or not in AD. Later you can create the users.
    #Find Users exist in AD or Not?
    #Biswajit Biswas
    $users = get-content c:\users.txt
    foreach ($user in $users) {
    $User = Get-ADUser -Filter {(samaccountname -eq $user)}
    If ($user -eq $Null) {"User does not exist in AD ($user)" }
    Else {"User found in AD ($user)"}
    Active Directory Users attributes-Powershell
    http://gallery.technet.microsoft.com/scriptcenter/Getting-Users-ALL-7417b71d
    Regards~Biswajit
    Disclaimer: This posting is provided & with no warranties or guarantees and confers no rights.
    MCP 2003,MCSA 2003, MCSA:M 2003, CCNA, MCTS, Enterprise Admin
    MY BLOG
    Domain Controllers inventory-Quest Powershell
    Generate Report for Bulk Servers-LastBootUpTime,SerialNumber,InstallDate
    Generate a Report for installed Hotfix for Bulk Servers

  • Removed all members from SysAdmin on SQL 2000

    Aloha
    I had a faulty script that unfortunately removed all members from the SysAdmin role. Unfortunately, I cannot reinstall the instance and I only have short windows of opportunity for downtime.
    I understand if I can get the database into single user mode and log in I can add a new local account to the database with the sysadmin role, however I can't seem to get logged into the single user mode. It keeps saying "Login failed for user '<MYUSERACCOUNT>'.
    Reason: Server is in single user mode. Only one administrator can connect at this time.
    I have the SQL agent shut down, I am not running enterprise manager and, as far as I can tell, there are no other admins connecting to the system. I know with newer SQL versions one can limit the single user mode to only accept SQLCMD. Of course, 2000 doesn't
    have SQLCMD but has OSQL. Any thoughts on how I can limit the access during this maintenance? I've even tried to remove both named pipes and TCP/IP from the accepted connection types but that didn't seem to make a difference.
    Thoughts? Please?

    I'm a little rusty on SQL Server 2000. Sorry if this advise is useless.
    What account are you using to start the Database Engine. If not networkservice, then connect as that account. Try change the account to a local computer account, and then use that account. The general principal here, is that the account running the database
    engine service, can connect.
    Rick Byham, Microsoft, SQL Server Books Online, Implies no warranty

  • PowerShell Script to get the details Like Scope,Last Deployed date and Name for a Solution Deployed in the Farm.

    Hi Experts,
    I am trying to  build a PowerShell Script to get the details Like Scope,Last Deployed date and Name for a Solution Deployed in the Farm.
    Can anyone advise on this please.
    Regards

    Get-SPSolution|Select Name,Scope,LastOperationResult,LastOperationEndTime|Export-CSV "SPInstalledSolutions.csv" -NoTypeInformation
    SPSolution properties
    Get-SPSolution
    This post is my own opinion and does not necessarily reflect the opinion or view of Slalom.

  • Powershell Script to Remove and Add the user with same permission

    Hi,
    I need to remove all users within all site collection of a web application and add them back with same permission level. We have a siteminder based custom trusted identity token issuer configured in our farm. The name of the issuer will be changed
    due to some architectural decissions , hence all users which are there before will be unidentified, hence need to be removed and added again.
    Currently each user looks like :                       c:0ǹ.t|Identity Token Issuer1|user1
    Post the change the user will look like:          c:0ǹ.t|Identity Token Issuer New|user1
    I am looking for a powershell script which can handle this operation.
    Thanks, Bivsworld

    Bivsworld,
    Below link should give you a start.
    http://www.sptechlearn.com/2014/10/delete-users-from-user-information-list.html

  • How to remove all scripts on object instances?

    I'm looking for any kind of solution here, besides disabling the warning.
    I hate it when I'm converting someone else's AS2 project to AS3, and there's code buried on an onstage instance somewhere, which gives me the warning:
    "Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored."
    How can I:
         A) Find which instances have code on them.
              or
         B) Remove all code on all instances.
    Idea:
    Can I save as a different format/version/something and lose this data somehow. Then I could convert it back its current FLA format?

    YES!!! So awesome!!  Thanks

  • Powershell script for removing some users from a particular Site Collection

    Hi,
    I am looking for a PowerShell script to delete a few users from a particular Site Collection. I am unable to delete them from/_catalogs/Users/simple.aspx page therefore need some other medium to
    delete users from the site collection.
    My ultimate aim is to have no user profile with "tp_deleted" field's value as 0 in the USERINFO table. Currently there are about 40 odd users with this field's value as 0 and this is affecting my crawling of this content database.

    Thanks for the reply Alex & eHaze,
    I have a content source of root site which crawls all the site collections under it. Out of the 9 site collections, only 8 are getting crawled and 1 doesn't get crawled at all. The error in the crawl logs is 
    The SharePoint item being crawled returned an error when requesting data from the web service. ( Error from SharePoint site: Value does not fall within the expected range. )
    I tried a lot of things, searched over the net and finally found
    this which helped me solve the same issue in my development environment. I deleted these users from userInfo table and ran a full crawl. And the issue was fixed.
    Now since I cannot delete the users from userInfo table directly from PROD environment, I used .../_catalogs/Users/simple.aspx list
    to delete users from this site collection. While some of the users I could delete, quite a few I could not. Clicking on the profile redirected me to the home page rather than the info page of the profile. 
    This
    is why I have to delete these users from the site collection.
    Alex - the link you shared, I guess it is for a web application level.
    eHaze - the script you shared throws this error:
    Get-SPSite : Cannot find an SPSite object with Id or Url: http://dev-apps/divisions/BT. At C:\PowerShell Scripts\DeleteUserFromSiteCollection1.ps1:4 char:19
    + $site = get-spsite <<<< $siteURL
    + CategoryInfo : InvalidData: (Microsoft.Share...SPCmdletGetSite:
    SPCmdletGetSite) [Get-SPSite], SPCmdletPipeBindException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetSite
    You cannot call a method on a null-valued expression.
    At C:\PowerShell Scripts\DeleteUserFromSiteCollection1.ps1:9 char:27
    + $site.SiteUsers.Remove <<<< ($LoginName)
    + CategoryInfo : InvalidOperation: (Remove:String) [], RuntimeExc
    eption
    + FullyQualifiedErrorId : InvokeMethodOnNull
    hope this info helps.

  • Outlook remove empty pst folders from stores with powershell script

    I created a script that finds all pst folders in the My Documents folder of a user, moves those PST files and attaches the PST to outlook after they've been moved.
    If PSTs in a user's my documents folder was attached to Outlook before the script is run. after the script runs successfully in the outlook profile those PSTs would have two entries in the stores, an old reference that is because the PSTs have been moved
    those folders can no longer be opened in outlook and each time a user attempts to open the folder it prompts you to browse for the new location of the PST. Then the new entries in the stores which were added via the script.
    I want to add removing those empty folders or rather those folders with broken file paths from outlook to my script. Because of these broken folders i can't enumerate through the list of attached folders in outlook, the script errors outlook.
    I need help scripting (PowerShell) the task of removing broken folders from the outlook stores
    thanks

    Here is a sample of the kind of code you need to work with:
    $ol=New-Object -ComObject Outlook.Application
    $ns=$ol.GetNamespace('MAPI')
    foreach($store in $ns.Stores){
    if($store.IsDatFileStore){$ns.RemoveStores($store)}
    # use $ns.AddStore() to reattache a store.
    # inbox dor account must be retrieved and maintained.
    If you are not sure how to proceed then post in the Outlook Developer forum.  They should have many examples of how to move PSTs given different versions and scenarios.
    You can also find many examples here:
    http://gallery.technet.microsoft.com/site/search?f%5B0%5D.Type=RootCategory&f%5B0%5D.Value=Office&f%5B0%5D.Text=Office&f%5B1%5D.Type=SubCategory&f%5B1%5D.Value=Microsoft%20Outlook&f%5B1%5D.Text=Microsoft%20Outlook
    ¯\_(ツ)_/¯

  • PowerShell script to check permissions given to "NT Authority\All Authenticated Users" and..

    Hi there,
    On my SharePoint site - some places (Sites/Lists etc) have given permissions to "NT Authority\All Authenticated Users"
    We need to remove these permissions and instead give permissions to "Forest1\Domain Users" and "Forest1\Domain Users"
    PowerSHell script to do above will be appreciated.
    Thank you so much.

    Hello,
    In order to check whether "NT Authority\All Authenticated Users" are present in your site use this reference - Link
    Remove permission script reference - Link
    Finally grant permission script reference - link
    Kindly mark it as answer if it helps you.
    -Hatim

  • Script to remove all printers

    I'm trying to find a script to remove all current and stale printers on some TS sessions.  I've tried a couple of scripts but they all seem to error one way or another.  Firstly I've tried
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colInstalledPrinters = objWMIService.ExecQuery _
    ("Select * From Win32_Printer Where Network = True")
    For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
    Next
    But I get an invalid parameters on Line 6 with code 80041008 and source SWbemObjectEx.  I've also tried
    'Define Variables and Objects.
    Set WshShell = CreateObject("Wscript.Shell")
    Const NETWORK = 22
    Set objNetwork = CreateObject("WScript.Network")
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
    For Each objPrinter in colPrinters
    If objPrinter.Attributes And NETWORK Then
    strPrinter = objPrinter.Name
    objNetwork.RemovePrinterConnection strPrinter
    End If
    Next
    'Note: Gpupdate command has to be run twice as the ECHO command can't answer more than one question.
    'Refresh the USER policies and also answer no to logoff if asked.
    Result = WshShell.Run("cmd /c echo n | gpupdate /target:user /force",0,true)
    'Refresh the Computer policies and answer no to reboot.
    Result = WshShell.Run("cmd /c echo n | gpupdate /target:computer /force",0,true)
    'Hand back the errorlevel
    Wscript.Quit(Result)
    But with this one I get an error on line 16 with 'This network connection does not exist' and code 800708CA and source WSHNetwork.RemoveNetworkDrive.
    Only solution at the moment I can think of is to just remove them all from the registry but would rather do it user based via script.

    hmmmm.  The ones set by GPO are fine as they are the ones that are meant to stay it's just that there are a lot of rubbish printers sat on peoples user profiles that are old and non-existent so we just want to wipe all the old and just keep the new

  • My ITunes got corrupted and I kept getting a message when updating iTunes64msi missing so I uninstalled all files and I thought I removed all registry values but  when reinstalling I get an older version is installed and cannot be removed. I need a soluti

    My ITunes got corrupted and I kept getting a message when updating iTunes64msi missing so I uninstalled all files and I thought I removed all registry values but  when reinstalling I get an older version is installed and cannot be removed. I need a solution.

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any Bonjour entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • HT204406 I purchased the additional Icloud storage for my ipod touch.  Since it removes all my music from the touch and stores it in Icloud, I find that when I am not at my wifi location or another one,I can't access my music.Is there a solution for that?

    I purchasedhe additional Icloud storage for my ipod touch.  That removes all my music from the ipod and putsd it in Icloud.  I find that when I am away from my wifi connection, like when walking or working out, I can't access my music. Is there a solution for this?

    Download the music to your ipod when you are in a wi-fi area.
    It will be stored on your ipod.

  • Powershell script to change the a column value of all documents in a site.

    Hi,
    I need a powershell script to change the value of a column (a site column which has been added to all document libraries) in all documents in a site,
    For example: 
    -column 1 is a site column added to all libraries
    the value of column 1 of all documents under this site: http://intranet.doman/ex1 should be equal to V1
    the value of column 1 of all documents under this site: http://intranet.doman/ex2 should be equal to V2
    So, if I can write a powershell script to change the value of all documents in a site, I can modify it for different site that I have and run it for each of them individually,

    cls
    # Is dev version?
    $dev = $false
    # Configuration
    $termStore = "Managed Metadata Service"
    $group = "G1"
    $subjectMatterTermSetName = "Subject Matter"
    # Check if SharePoint Snapin is loaded
    if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
         Add-PSSnapin Microsoft.SharePoint.PowerShell
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Taxonomy") | Out-Null
    function GetTermStore($site, $termStore, $group, $termSet) {    
        $session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
        $termStore = $session.TermStores[$termStore]
        $group = $termStore.Groups[$group]
        $termSet = $group.TermSets[$termSet]
        return $termSet
    if($dev) {
        Write-Host "Running DEV version..."
        $webUrl = "http://Site1"   
        $libraryName = "L1"
        $subjectMatter = "C1"
    } else {
        $webUrl = Read-Host "Enter Site URL" 
        $libraryName = Read-Host "Enter Document Library name"
    $subjectMatter = Read-Host "Enter Subject Matter"
    try {
        $web = Get-SPWeb $webUrl
        $site = $web.Site
        $library = $web.Lists[$libraryName]
        $items = $library.GetItems()
        $subjectMatterTermSet = GetTermStore $site $termStore $group $subjectMatterTermSetName
        $subjectMatterTerm = $subjectMatterTermSet.GetTerms($subjectMatter,$true) | select -First 1
        foreach($item in $items) {
            if([string]::IsNullOrEmpty($item["Subject Matter"])) {     
                #Write-Host "Filename: $filename / Keywords: $keywords / Subject Matter: $subjectMatter / Document Type: $documentType"        
                Write-Host "Updating $($item["ows_FileLeafRef"])..."           
                # Set Subject Matter column
                $subjectMatterField = [Microsoft.SharePoint.Taxonomy.TaxonomyField]$item.Fields["Subject Matter"]
                $subjectMatterField.SetFieldValue($item,$subjectMatterTerm)
                # Update Item
                $item.SystemUpdate()
    catch
        $ErrorMessage = $_.Exception.Message
        Write-Host "Something went wrong. Error: $ErrorMessage" -ForegroundColor Red

  • I have removed all music/movies/etc. from iTunes due to duplicates. I have connected iTunes to a NEW library only to have the same problem, duplicates (2 or 3 of every song). I need a solution.

    I have removed all music/movies/etc. from iTunes due to duplicates. I have connected iTunes to a NEW library (38.33 GB) only to have the same problem, duplicates (2 or 3 of every song or 63.80 GB). I did not have this problem until syncing my library with the new Macbook Pro. I need a solution (a solution IS NOT sifting through my iTunes song by song and deleting the duplicates).

    Try disabling the computer's antivirus and firewall.
    - Next try the manual install method of:
    iDevice Troubleshooting 101 :: iPhone, iPad, iPod touch
    Place the iPod in recovery mode after the firmware download is complete and then restore using the instructions in the article. Sometimes recovery mode timeouts and returns to disabled before the firmware download is complete.
    - Then try on another computer

Maybe you are looking for