Read data from CSV and create hashtable in PowerShell

Let us assume we have a CSV file with data in two columns and we need to read the data and create a hashtable for use in PowerShell. The first row in CSV is a header row with values as "Feature" and "Type".

First step is to read the CSV file using the line below
$t = Import-Csv -Path 'C:\Temp\features.csv' -Header "Feature","Type"

Now create a blank hashtable
$HashTable = @{}

Iterate through the CSV rows and add the corresponding data to hashtable as following
foreach($r in $t)
{
    Write-Host $r.Feature $r.Type
    $HashTable.Add($r.Feature,$r.Type)
}


Powershell for creating mysite in SharePoint

Following script can be used to create mysite programatically using PowerShell

$site = new-object Microsoft.SharePoint.SPSite("http://mysite"); 
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site); 

$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext); 
$AllProfiles = $ProfileManager.GetEnumerator();

foreach($profile in $AllProfiles) 
{  
    $DisplayName = $profile.DisplayName
        $UserName = $profile.UserName
        $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value
   
    if($Accountname -match "domain\user")
    {
        $profile.CreatePersonalSite();
    }
}

How to clear timer job cache in SharePoint

Follow following steps to clear SharePoint timer job cache

1. Stop the Windows SharePoint Services Timer service (Found in Windows Services)

2. Navigate to the cache folder

In Windows Server 2008, the configuration cache is in the following location:
Drive:\ProgramData\Microsoft\SharePoint\Config

In Windows Server 2003, the configuration cache is in the following location:
Drive:\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config
Locate the folder that has the file "Cache.ini"
(Note: The Application Data folder may be hidden. To view the hidden folder, change the folder options as required)

3. Back up the Cache.ini file.

4. Delete all the XML configuration files in the GUID folder. Do this so that you can verify that the GUID folder is replaced by new XML configuration files when the cache is rebuilt.

5. Note When you empty the configuration cache in the GUID folder, make sure that you do not delete the GUID folder and the Cache.ini file that is located in the GUID folder.

6. Double-click the Cache.ini file.

7. On the Edit menu, click Select All. On the Edit menu, click Delete. Type 1, and then click Save on the File menu. On the File menu, click Exit.

8. Start the Windows SharePoint Services Timer service

9. Note The file system cache is re-created after you perform this procedure. Make sure that you perform this procedure on all servers in the server farm.

10.    Make sure that the Cache.ini file in the GUID folder now contains its previous value. For example, make sure that the value of the Cache.ini file is not 1.


How to download wsp solution files from Central Admin in SharePoint

In case there is a need to download a single solution from Central Admin, following PowerShell script can be used to download wsp file

$farm = Get-SPFarm
$file = $farm.Solutions.Item("SampleSolution.wsp").SolutionFile
$file.SaveAs("c:\temp\SampleSolution.wsp")


To download all solutions files deployed to a SharePoint server farm, use following script

$farm = Get-SPFarm
$SavedPath = "c:\temp\"   
$mySolutions = $farm.Solutions

foreach($mySolution in $mySolutions)
{
    [string]$myOutputPath = $SavedPath + $mySolution.Name
    $mySolution.SolutionFile.SaveAs($myOutputPath);
}