Retrive account password powershell

Start SharePoint Service Application Proxy using Powershell

If your Usage and Health Data Collection Proxy is in a stopped state here is a quick bit of PowerShell to to get it started:

$sap = Get-SPServiceApplicationProxy | where-object {$_.TypeName -eq “Usage and Health Data Collection Proxy”}
$sap.Provision()

The above can easily be adapted to allow you to start any Service Application Proxy

Advertisements
Retrive account password powershell

Content databases contain orphaned Apps SharePoint 2013

SharePoint Health Analyzer rule “Content databases contain orphaned Apps.”

Some situation content database may become corrupted. The corrupted database may contain orphaned apps. Orphaned apps are not accessible, which causes unnecessary resource and license consumption and may result in failures in SharePoint upgrade.

Solution:

Remove app for SharePoint instances from a SharePoint 2013 site.

A user must have the Manage Web site permission to remove an app for SharePoint. By default, this permission is only available to users with the Full Control permission level or who are in the site Owners group.

To remove an app from a SharePoint site

  1. Verify that the user account that is performing this procedure is a member of the Site owners group.
  2. On the site, on the Settings menu, click View Site Contents.
    In the Apps section, point to the app that you want to remove, click …, and then 3. click Remove.
  3. Click OK to confirm that you want to remove the app.

To remove an app by using Windows PowerShell

Verify that you have the following memberships:

a. securityadmin fixed server role on the SQL Server instance.
b. db_owner fixed database role on all databases that are to be updated.
c. Administrators group on the server on which you are running the Windows PowerShell cmdlets.
d. Site Owners group on the site collection to which you want to install the app.

An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint 15 Products cmdlets.

On the Start screen, click SharePoint 2013 Management Shell.

type the following commands, and press ENTER after each one:

$instances = Get-SPAppInstance -Web
#Gets all apps installed to the subsite you specify.

$instance = $instances | where {$_.Title -eq ”}
#Sets the $instance variable to the app with the title you supply.

Uninstall-SPAppInstance -Identity $instance
#Uninstalls the app from the subsite.

is the path site collection or subsite that contains the app.
is the title of the app you want to remove.

At the question “Are you sure you want to perform this action?”,
type Y to uninstall the app.

Locate and remove app instances in all locations

An app for SharePoint in the App Catalog is available for users to install.Users can install apps for SharePoint on many sites.

Below two Windows PowerShell scripts can be used to find all locations for a specific app and then uninstall all instances from every location.

First script to locate all instances of a specific app in a SharePoint environment. Then use the second script to uninstall all instances of the app from the SharePoint environment.

To locate specific apps by using Windows PowerShell (save as script and run script)

Verify that you have the following memberships:

a. securityadmin fixed server role on the SQL Server instance.
b. db_owner fixed database role on all databases that are to be updated.
c. Administrators group on the server on which you are running Windows PowerShell cmdlets.

An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint 2013 cmdlets

1. save the below script as “Get-AppInstances.ps1”

This Windows PowerShell script gets all app instances from your SharePoint 2013 farm for a specified App ID on a specified web application. You specify the App ID and the web application URL and the script will remove all of the instances of the App for all webs in that web application.

param(
[Parameter(Mandatory=$true)] [Guid] $productId,
[Parameter(Mandatory=$true)] [String] $webAppUrl
)

function GetAllInstances($productId = $null, $webAppUrl = $null)
{
$outAppName = “”;
$sites = Get-SPSite -WebApplication $webAppUrl
$outWebs = @()
foreach($site in $sites){
if($site.AdministrationSiteType -ne “None”){
continue;
}
$webs = Get-SPWeb -site $site
foreach($web in $webs) {
$appinstances = Get-SPAppInstance -Web $web
foreach($instance in $appinstances) {
if($productId -eq $instance.App.ProductId) {
if ($outAppName -eq “”) {
$outAppName = $instance.Title;
}
$outWebs += $web;
}
}
}
}
return ($outAppName,$outWebs)
}
Write-Host “This script will search all the sites in the webAppUrl for installed instances of the App.”
$confirm = Read-Host “This can take a while. Proceed? (y/n)”
if($confirm -ne “y”){
Exit
}

$global:appName = $null;
$global:webs = $null;

{
$returnvalue = GetAllInstances -productId $productId -webAppUrl $webAppUrl;
$global:appName = $returnvalue[0];
$global:webs = $returnvalue[1];
}
);

$count = $global:webs.Count;
if($count -gt 0){
Write-Host “App Name:” $global:appName;
Write-Host “Product Id: $productId”;
Write-Host “Number of instances: $count”;
Write-Host “”;
Write-Host “Urls:”;

foreach($web in $global:webs) {
Write-Host $web.Url;
}
}
else {
Write-Host “No instances of the App with Product Id $productId found.”;
}
return;

  1. Now Open “SharePoint 2013 Management Shell”
  2. Change to the directory where you saved the file.

  3. At the Windows PowerShell command prompt, type the following command:

./ Get-AppInstances.ps1 -productId -webAppUrl

is the GUID ID of the App
and is the full URL of the web application.

To uninstall specific apps from all locations by using Windows PowerShell (save as script and run script)

1. Verify that you have the following memberships:

a. securityadmin fixed server role on the SQL Server instance.
b. db_owner fixed database role on all databases that are to be updated.
c. Administrators group on the server on which you are running Windows PowerShell cmdlets.

An administrator can use the Add-SPShellAdmin cmdlet to grant permissions to use SharePoint 2013 cmdlets

2. save the below script as “Remove-App.ps1”

This Windows PowerShell script removes all app instances from your SharePoint 2013 farm for a specified App ID on a specified web application. You specify the App ID and the web application URL and the script will remove all of the instances of the App for all webs in that web application.

param(
[Parameter(Mandatory=$true)] [Guid] $productId,
[Parameter(Mandatory=$true)] [String] $webAppUrl
)

function RemoveInstances($productId = $null, $webAppUrl = $null)
{
$outAppName = “”;
$sites = Get-SPSite -WebApplication $webAppUrl
$outWebs = @()
foreach($site in $sites){
if($site.AdministrationSiteType -ne “None”){
continue;
}
$webs = Get-SPWeb -site $site
foreach($web in $webs) {
$appinstances = Get-SPAppInstance -Web $web
foreach($instance in $appinstances) {
if($productId -eq $instance.App.ProductId) {
if ($outAppName -eq “”) {
$outAppName = $instance.Title;
}
$outWebs += $web;
Write-Host “Uninstalling from” $web.Url;
Uninstall-SPAppInstance -Identity $instance -confirm:$false
}
}
}
}
return ($outAppName,$outWebs)
}

$confirm = Read-Host “This will uninstall all instances of the App and is irreversible. Proceed? (y/n)”
if($confirm -ne “y”){
Exit
}

$global:appName = $null;
$global:webs = $null;

{
$returnvalue = RemoveInstances -productId $productId -webAppUrl $webAppUrl;
$global:appName = $returnvalue[0];
$global:webs = $returnvalue[1];
}
);

$count = $global:webs.Count;
if($count -gt 0){
Write-Host “All the instances of the following App have been uninstalled:”;
Write-Host “App Name:” $global:appName;
Write-Host “Product Id: $productId”;
Write-Host “Number of instances: $count”;
Write-Host “”;
Write-Host “Urls:”;

foreach($web in $global:webs) {
Write-Host $web.Url;
}
}
else {
Write-Host “No instances of the App with Product Id $productId found.”;
}
return;

  1. Open SharePoint 2013 Management Shell
  • Change to the directory where you saved the file.

  • At the Windows PowerShell command prompt, type the following command:

  • ./ Remove-App.ps1 -productId -webAppUrl

    is the GUID ID of the App
    is the full URL of the web application.

    If the issue still persists like as below

    If you have an orphaned app in the initialized state on a site and you delete the site, Health Analyzer reports that there’s an error and the auto-fix doesn’t work.”

    Apply CU November 2016 which will 100% resolve the issue

    SharePoint Server 2013 (KB3127933)
    SharePoint Foundation 2013 (KB3127930)

    Repairing distributed cache with PowerShell

    • Recently we had issues with our distributed cache system that was set up on are farm quite some time ago when I built it with SPAuto-Installer.  This could have been from rolling out cumulative updates or what have you.  There is very little documentation on the web for this.

    *  In our case we had 4 servers (2 web front-ends and 2 application servers)  all with the distributed cache enabled.  Only one server was running the distributed cache.

    *  The correct topology for distributed cache is for it to exist on the web front-ends.  So we made some changes to the farm.

    Clean up all 4 Servers using the following commands:

    #Stopping the service on local host

    Stop-SPDistributedCacheServiceInstance -Graceful

    #Removing the service from SharePoint on local host.

    Remove-SPDistributedCacheServiceInstance

    #Cleanup left over pieces from SharePoint

    $instanceName =”SPDistributedCacheService Name=AppFabricCachingService”

    $serviceInstance = Get-SPServiceInstance | ? {($.service.tostring()) -eq $instanceName -and ($.server.name) -eq $env:computername}

    $serviceInstance.delete()

    Then we added the cache host back to WEB01:

    #Re-add the server back to the cluster

    Add-SPDistributedCacheServiceInstance

    We then checked the SPDistributedCacheClientSettings and found that “MaxConnectionsToServer” was set to 16 for all containers.

    $DLTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache

    $DLTC

    We used the following script to change  “MaxConnectionsToServer” back to 1 and increase the timeout for each container.

    Add-PSSnapin Microsoft.Sharepoint.Powershell

    #DistributedLogonTokenCache

    $DLTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache

    $DLTC.MaxConnectionsToServer = 1

    $DLTC.requestTimeout = “3000”

    $DLTC.channelOpenTimeOut = “3000”

    Set-SPDistributedCacheClientSetting -ContainerType DistributedLogonTokenCache -DistributedCacheClientSettings $DLTC

    #DistributedViewStateCache

    $DVSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache

    $DVSC.MaxConnectionsToServer = 1

    $DVSC.requestTimeout = “3000”

    $DLTC.channelOpenTimeOut = “3000”

    Set-SPDistributedCacheClientSetting -ContainerType DistributedViewStateCache $DVSC

    #DistributedAccessCache

    $DAC = Get-SPDistributedCacheClientSetting -ContainerType DistributedAccessCache

    $DAC.MaxConnectionsToServer = 1

    $DAC.requestTimeout = “3000”

    $DAC.channelOpenTimeOut = “3000”

    Set-SPDistributedCacheClientSetting -ContainerType DistributedAccessCache $DAC

    #DistributedAccessCache

    $DAF = Get-SPDistributedCacheClientSetting -ContainerType DistributedAccessCache

    $DAF.MaxConnectionsToServer = 1

    $DAF.requestTimeout = “3000”

    $DAF.channelOpenTimeOut = “3000”

    Set-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedCache $DAF

    #DistributedActivityFeedLMTCache

    $DAFC = Get-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedLMTCache

    $DAFC.MaxConnectionsToServer = 1

    $DAFC.requestTimeout = “3000”

    $DAFC.channelOpenTimeOut = “3000”

    Set-SPDistributedCacheClientSetting -ContainerType DistributedActivityFeedLMTCache $DAFC

    #DistributedBouncerCache

    $DBC = Get-SPDistributedCacheClientSetting -ContainerType DistributedBouncerCache

    $DBC.MaxConnectionsToServer = 1

    $DBC.requestTimeout = “3000”

    $DBC.channelOpenTimeOut = “3000”

    Set-SPDistributedCacheClientSetting -ContainerType DistributedBouncerCache $DBC

    #DistributedDefaultCache

    $DDC = Get-SPDistributedCacheClientSetting -ContainerType DistributedDefaultCache

    $DDC.MaxConnectionsToServer = 1

    $DDC.requestTimeout = “3000”

    $DDC.channelOpenTimeOut = “3000”

    Set-SPDistributedCacheClientSetting -ContainerType DistributedDefaultCache $DDC

    #DistributedSearchCache

    $DSC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSearchCache

    $DSC.MaxConnectionsToServer = 1

    $DSC.requestTimeout = “3000”

    $DSC.channelOpenTimeOut = “3000”

    Set-SPDistributedCacheClientSetting -ContainerType DistributedSearchCache $DSC

    #DistributedSecurityTrimmingCache

    $DTC = Get-SPDistributedCacheClientSetting -ContainerType DistributedSecurityTrimmingCache

    $DTC.MaxConnectionsToServer = 1

    $DTC.requestTimeout = “3000”

    $DTC.channelOpenTimeOut = “3000”

    Set-SPDistributedCacheClientSetting -ContainerType DistributedSecurityTrimmingCache $DTC

    #DistributedServerToAppServerAccessTokenCache

    $DSTAC = Get-SPDistributedCacheClientSetting -ContainerType DistributedServerToAppServerAccessTokenCache

    $DSTAC.MaxConnectionsToServer = 1

    $DSTAC.requestTimeout = “3000”

    $DSTAC.channelOpenTimeOut = “3000”

    Set-SPDistributedCacheClientSetting -ContainerType DistributedServerToAppServerAccessTokenCache $DSTAC

    • We then stopped and restarted Distributed Cache from Central Admin on WEB01
    • We then attempted to start “Distributed Cache” on WEB02 and received error “failed to connect to hosts in the cluster”
    • Performing a TRACERT from WEB01 to WEB02, we can see a device is in the middle (10.21.1.5).
    • Installed Telnet

    Import-Module servermanager

    Add-WindowsFeature telnet-client

    • Telnet from WEB01 to WEB02 on port 22233 and the connection was established.
  • We then stopped, cleaned and added WEB02 back to the cache farm
  • #Stopping the service on local host

    Stop-SPDistributedCacheServiceInstance -Graceful

    #Removing the service from SharePoint on local host.

    Remove-SPDistributedCacheServiceInstance

    #Cleanup left over pieces from SharePoint

    $instanceName =”SPDistributedCacheService Name=AppFabricCachingService”

    $serviceInstance = Get-SPServiceInstance | ? {($.service.tostring()) -eq $instanceName -and ($.server.name) -eq $env:computername}

    $serviceInstance.delete()

    Then we added the cache host back to WEB02:

    #Re-add the server back to the cluster

    Add-SPDistributedCacheServiceInstance

    This time it started!

    • Now we have WEB01 and WEB02 servicing distributed Cache
  • We checked the ULS Logs with ULSViewer and found all successful events for Distributed Cache.
  • Status

    =======

    Distributed cache is now healthy and in a working state on both WFE Servers.