Thursday, September 11, 2014

Powershell to view Secure Store Credentials

If you've forgotten your secure store credentials, just use this powershell script to retrieve them. Thanks to Ajeet's blog

$serviceCntx = Get-SPServiceContext -Site http://<SharePoint host>

$sssProvider = New-Object Microsoft.Office.SecureStoreService.Server.SecureStoreProvider

$sssProvider.Context = $serviceCntx

$marshal = [System.Runtime.InteropServices.Marshal]


try

 {
      $applicationlications = $sssProvider.GetTargetApplications()
      foreach ($application in $applicationlications)
      {
           Write-Output "`n$($application.Name)"
           Write-Output "$('-'*100)"
           try
           {
                $sssCreds = $sssProvider.GetCredentials($application.Name)
                foreach ($sssCred in $sssCreds)
                {
                     $ptr = $marshal::SecureStringToBSTR($sssCred.Credential)
                     $str = $marshal::PtrToStringBSTR($ptr)
                    Write-Output "$($sssCred.CredentialType): $($str)"
                }
           }
           catch
           {
                Write-Output "(Something went wrong) - Error getting credentials!"
           }
           Write-Output "$('-'*100)"
      }
 }
 catch
 {
      Write-Output "(Something went wrong) - Error getting Target Applications."
 }

$marshal::ZeroFreeBSTR($ptr)

Monday, June 23, 2014

How to sync internet time in Server 2008/ 2012

I found this nice blog on the interwebs which explains how to Configure Windows Server 2008/2012 To Sync With Internet Time Servers.

Basically just execute the following commands on the command line as an administrator

net stop w32time

w32tm /config /syncfromflags:manual /manualpeerlist:"time-a.nist.gov, time-b.nist.gov, time-c.nist.gov, time-d.nist.gov"

w32tm /config /reliable:yes

net start w32time


That will configure the time service to sync with the list of servers (time-*.nist.gov in the above example) and it also tells the server that it is a reliable time source that client machines on your domain can sync with (i.e., w32tm /config /reliable:yes).

If you need to view the NTP configuration, type the following command from a prompt:

w32tm /query /configuration

Wednesday, June 4, 2014

Svchost.exe high CPU usage and WBEM issues

Recently my windows 7 desktop at work felt painfully slow and any file access on my local drives would crawl, & explorer would constantly flash "Not Responding". Looking at task manager & resource monitor I saw a high cpu usage with svchost.exe and excessive disk usage with something similar to

C:\Windows\System32\wbem\Repository\MAPPING3

This basically means the WMI respository is hosed and causes major performance issues within windows, rendering the machine practically unusable. After googling the interwebs I came across this solution from Scott Hanselman.

Lately I've been seeing one particular svchost.exe sucking CPU. There always a number of in-proc running inside of each of the many svchost (Service Host) instances. Using ProcEx, I figured out the PID of the specific instance. Then, I right clicked within ProcEx, hit Properties, and under the Threads tab noticed that wbemcore.dll was working REALLY hard.

Crap, time to re-schmutz WMI's repository. So, I stop WMI from the command line with :

net stop winmgmt

Then I deleted the Repository directory in c:\windows\system32\wbem\ then started again with

net start winmgmt

Then I re-stored/compiled all the .mof (Managed Object Format) files with a batch file containing this one line:

for %%i in (*.mof,*.mfl) do Mofcomp.exe %%i

Now I'm back in business.



These steps fixed my performance issues and everything's back to normal.