Monday, March 23, 2015

Read file in Powershell line by line

Reading  file in Powershell line by line can be helpful if you want do some operation on file

Example

Perform same operation for each line of file

1. Searching for specific words in line
2. navigating to different urls to check response
3. etc

I wrote this piece of code to update SharePoint Site logo for multiple site


$file= Get-Content("FileName")
foreach ($line in $file)
{
    Write-Host "One line from file"
    Write-Host $line
}

Monday, March 16, 2015

Update Sharepoint site logo image using powershell

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint")
# Provide Site URL
$Url="https://mySharepointSite.Company.com/sites/demo/default.aspx"
$site = new-object Microsoft.SharePoint.SPSite($Url)
$web=$site.OpenWeb();
$web.SiteLogoUrl = "/demo/shared documents/logo.gif"
$web.Update()
$web.Close()
$site.Dispose()