Showing posts from May, 2018

Delete Sub sites Using PowerShell SharePoint 2013

Delete Sub sites Using PowerShell SharePoint 2013 Recently I had to delete 50plus sub sites from one of my site collection which was created through script specified here. All my sites had a naming conversion with a number which helped me to select the site dynamically. Add-PSSnapin Microsoft.SharePoint.PowerShell [System.Reflection.Assembly] ::LoadWithPartialName ( "Microsoft.SharePoint" ) > $null $ sequencestart = 3000 ; $ maxNumber = 3100 ; $ deleteCount = 0 ; $ siteURLPrefix = "" ; for ($ i = $ sequencestart ; $ i -lt $ maxNumber ; $ i ++ ) {     $ url = $ siteURLPrefix + $ i ;     Write-Host $ url ;     #Gets the Sub site in to vairable, If Site is not existing Error Action parameter will not throw an exception     $ web = Get-SPWeb -Identity $ url -ErrorAction SilentlyContinue ;         IF ($ web )         {             Write-Host "Site Exists..."  

How to Search a Text file for a word using PowerShell

Today I had to find a way to search for specific values in set of text files. I had around 200 files with each has 6000+ records as pipe ( | ) separated File. This is how I managed to find the file(s) which was  the text. Check each file for the existence of the word or phrase which I'm looking for. If word is existing, dig deeper in to the file to find to find the record which is having search word in particular column (in my case it was NTID [windows login name of the user].  Same ID might available in different fields manage ID but I wanted to check the User Login ID I used PowerShell Contains() method and iterate the file data as | separated csv file. #Source File Path $ filePath = "C:\script\CSV" ; $ timeStamp = Get-Date ; $ ExecutionID = $ timeStamp .ToString ( "yyyyMMddHHmm" ); #All files names which contains the word will be writen in to this file $ NameSearchLogFilePath = "C:\script\logs\NameVerification- $