Total Pageviews

Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

22 Jun 2018

Determine if SharePoint has enough memory allocated to the distributed cache service

After reading half a dozen articles explaining how to eyeball and calculate the distributed cache size I was wondering: Why no one suggests just to check the current consumption before changing anything? Here is a scary thought: What if we have a ton of memory and we don't need to add any more? I know, this sounds revolutionary.

This is a quick script that I've slapped together to show 1) maximum allocated memory for  the Distributed cache. 2) current usage for all AppFabric caches on the current server.

So, before bumping the Distributed cache, test the current consumption with the script below.


###### DETERMINE IF YOU HAVE ENOUGH MEMORY ALLOCATED TO DISTRIBUTED CACHE:
Add-PSSnapin Microsoft.SharePoint.Powershell
Use-CacheCluster
$hostname = hostname
$configuration = Get-AFCacheHostConfiguration -ComputerName $hostname -CachePort "22233"
Write-host Maximum Size: $($configuration.size)MB HostName: $($configuration.HostName) -ForegroundColor Blue
# Get-AFCache | % {Get-AFCacheConfiguration -CacheName $_.CacheName}
$caches = Get-AFCache | % {Get-AFCacheConfiguration -CacheName $_.CacheName}

 foreach($cache in $caches){
  $stats = Get-AFCacheStatistics $cache.CacheName
  Write-host $cache.CacheName -ForegroundColor Green Cache.
  Write-host Usage: $($stats.Size / 1MB) MB
  Write-host
 }

###### DETERMINE IF YOU HAVE ENOUGH MEMORY ALLOCATED TO DISTRIBUTED CACHE END

Here is the sample result:


7 Oct 2016

PowerShell script for monitoring SharePoint WFE's and SQL Server back-ends​​​​

#counters.txt contains a list of performance counters
#collect 
$fileName = "test{0:yyyyMMdd-HHmmss}.xml" -f (Get-Date) 
​get-counter -content (get-content counters.txt) -MaxSamples 2 -sampleinterval 5 |  Export-clixml $fileName

#save the results to the blg format. This will allow opening it with Performance Monitor
$fileName = "test{0:yyyyMMdd-HHmmss}.blg" -f (Get-Date) 
​get-counter -content (get-content counters.txt) -MaxSamples 2 -sampleinterval 5 |  Export-Counter $fileName
counters.txt contents:
\.NET CLR Memory(*)\% Time in GC 
\ASP.NET\Application Restarts 
\ASP.NET\Request Execution Time 
\ASP.NET\Requests Rejected 
\ASP.NET\Requests Queued 
\ASP.NET\Worker Process Restarts 
\ASP.NET\Request Wait Time 
\ASP.NET Applications(*)\Requests/Sec 
\LogicalDisk(*)\% Idle Time 
\Memory\Available MBytes 
\Memory\% Committed Bytes In Use 
\Memory\Page Faults/sec 
\Memory\Pages Input/sec 
\Memory\Page Reads/sec 
\Memory\Pages/sec 
\Memory\Pool Nonpaged Bytes 
\Network Interface(*)\Bytes Total/sec 
\Network Interface(*)\Packets/sec 
\Paging File(*)\% Usage 
\PhysicalDisk(*)\Current Disk Queue Length 
\PhysicalDisk(*)\% Disk Time 
\PhysicalDisk(*)\Disk Transfers/sec 
\PhysicalDisk(*)\Avg. Disk sec/Transfer 
\Process(*)\% Processor Time 
\Process(*)\Page Faults/sec 
\Process(*)\Page File Bytes Peak 
\Process(*)\Page File Bytes 
\Process(*)\Private Bytes 
\Process(*)\Virtual Bytes Peak 
\Process(*)\Virtual Bytes 
\Process(*)\Working Set Peak 
\Process(*)\Working Set 
\Processor(*)\% Processor Time 
\Processor(*)\Interrupts/sec 
\Redirector\Server Sessions Hung 
\Server\Work Item Shortages 
\System\Context Switches/sec 
\System\Processor Queue Length 
\Web Service(*)\Bytes Received/sec 
\Web Service(*)\Bytes Sent/sec 
\Web Service(*)\Total Connection Attempts (all instances) 
\Web Service(*)\Current Connections 
\Web Service(*)\Get Requests/sec

Show IIS Pool passwords in clear text

Windows 2012+ Solution:

Method #1


Add-WindowsFeature Web-WMI | Format-List
Get-CimInstance -Namespace root/MicrosoftIISv2 -ClassName IIsApplicationPoolSetting -Property Name, WAMUserName, WAMUserPass |
select Name, WAMUserName, WAMUserPass

 

Method #2


(Get-Item website).ProcessModel
(Get-Item website).ProcessModel.username
(Get-Item website).ProcessModel.password​

 

Windows 2008/R2 Solution


cd C:\Windows\system32\inetsrv
.\appcmd.exe list apppool /text:* ​

Add super user and super reader via PowerShell


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

####SET ACCOUNT NAMES (Replace Domain and UserName)
#SUPER USER ACCOUNT – Use your own Account (NB: NOT A SHAREPOINT ADMIN)
$sOrigUser= "domain\SP_SuperUser"
$sUserName = "SP_SuperUser"

#SUPER READER ACCOUNT – Use your own Account (NB: NOT A SHAREPOINT ADMIN)
$sOrigRead = "domain\SP_SuperRead"
$sReadName = "SP_SuperRead"

$apps = get-spwebapplication 
foreach ($app in $apps) {
   #DISPLAY THE URL IT IS BUSY WITH
   $app.Url
   if ($app.UseClaimsAuthentication -eq $true)
   {
    # IF CLAIMS THEN SET THE IDENTIFIER
    $sUser = "I:0#.w|" + $sOrigUser
    $sRead = "I:0#.w|" + $sOrigRead
   }
   else
   {
   # CLASSIC AUTH USED
     $sUser = $sOrigUser
     $sRead = $sOrigRead
   }
   
   # ADD THE SUPER USER ACC – FULL CONTROL (Required for writing the Cache)
   $policy = $app.Policies.Add($sUser, $sUserName)
   $policyRole = $app.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullControl) 
   $policy.PolicyRoleBindings.Add($policyRole)

   $app.Properties["portalsuperuseraccount"] = $sUser
   $app.Update()

   # ADD THE SUPER READER ACC – READ ONLY
   $policy = $app.Policies.Add($sRead, $sReadName)
   $policyRole = $app.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullRead) 
   $policy.PolicyRoleBindings.Add($policyRole)

   $app.Properties["portalsuperreaderaccount"] = $sRead
   $app.Update()
 }

29 Aug 2013

Get features grouped by solution package

foreach ($grp in Get-SPFeature | Group-Object SolutionId) {
    $sol = Get-SPSolution -Identity $grp.Name
    Write-Host $sol.Name '(ID:' $grp.Name '), Count:' $grp.Count -ForegroundColor Blue
    foreach ($fd in $grp.Group | sort DisplayName ) {
        Write-Host $fd.DisplayName '(' $fd.Scope ')'
    }
    Write-Host
}

5 Jun 2013

Run C# Code from Powershell that uses SharePoint DLL's

Here is a very nice article
http://blogs.technet.com/b/stefan_gossner/archive/2010/05/07/using-csharp-c-code-in-powershell-scripts.aspx

For example:

Code:
$Assem = ( 

"Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" , 

"Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" 

) 


$Source = @" 

using Microsoft.SharePoint.Publishing.Administration; 

using System; 


namespace StefanG.Tools 

{ 

public static class CDRemoteTimeout 

{ 

public static void Get() 

{ 

ContentDeploymentConfiguration cdconfig = ContentDeploymentConfiguration.GetInstance(); 

Console.WriteLine("Remote Timeout: "+cdconfig.RemoteTimeout); 

} 


public static void Set(int seconds) 

{ 

ContentDeploymentConfiguration cdconfig = ContentDeploymentConfiguration.GetInstance(); 

cdconfig.RemoteTimeout = seconds;

cdconfig.Update();

} 

} 

} 

"@ 


Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp 


[StefanG.Tools.CDRemoteTimeout]::Get()


[StefanG.Tools.CDRemoteTimeout]::Set(600)