Ads

Tuesday, 28 March 2017

Powershell script to read CSV file to do any automation

Lets we have one csv file with column SiteUrl. Below is the script which will read from csv file
 
 
# Power shell Read the rows from CSV file   

$CSVFile = Import-CSV -path "C:\DataHere.csv"  

foreach($row in $CSVFile)
{ 
    write-host "Read Site " + $row.SiteUrl        
    Write-host ""
    Write-host "Pausing for 200 seconds..."
    Sleep 200
} 

----------------------- or --------------

Here we are dismounting DBs by reading from CSV file as shown here


Import-CSV C:\DataHere.csv -Header Server, DatabaseName | Foreach-Object{
   if($_.DatabaseName -ne "DatabaseName")
   {       
        Dismount-SPContentDatabase $_.DatabaseName.Trim() -confirm:$false       
   }  
}


No comments:

Post a Comment

Ads