Posts

Showing posts with the label PowerShell

PowerShell to list Active Directory groups membership

Problem I need a list of AD groups of my colleague's who has left the company so that I can request for similar groups membership. Solution Run the following command on Windows PowerShell Console or PowerShell ISE: (New-Object System.DirectoryServices.DirectorySearcher("(&(objectCategory=User)(samAccountName=$($env:username)))")).FindOne().GetDirectoryEntry().memberOf or (New-Object System.DirectoryServices.DirectorySearcher("(&(objectCategory=User)(samAccountName= YourWindowsLogin ))")).FindOne().GetDirectoryEntry().memberOf

PowerShell to backup SPWeb and its children

Problem In line with previous article I wrote about restoring SPWeb backup using PowerShell script, I've written another one to perform backup of SPWeb and children. Solution # Created by Ben - 7 March 2019 # PowerShell script to export SPWeb and nested SPWebs ($webUrlPattern) to $exportToFolder # -IncludeVersions 4 = All versions for files and list items # 3 = Last major and last minor version for files and list items # 2 = The current version, either the last major version or the last minor version # 1 = Last major version for files and list items (default) # Supported by SharePoint 2010, 2013, 2016, 2019 # Note: this script can be adjusted to support SPSite or SPList Start-Transcript clear $startTime = ( Get-Date ) $exportToFolder = 'Exported' + $startTime .ToString("yyyyMMdd-HHmmss") $webUrl = "http://your-site-url/cases" $webUrlPattern = $webUrl +'/..../' $currentPs1F...

PowerShell to restore *.cmp backup of SPWeb

Problem I need to restore *.cmp file that contains SPWeb backup. Solution # Creating case sites and import backup files # Created by Ben - 7 March 2019 Start-Transcript clear if ((gsnp "*sharepoint*" -ErrorAction SilentlyContinue) -eq $null ){asnp *sharepoint*} $caseSiteUrlUniquePattern = 'Exporting Web http://pacman' $truncateStart = '.intranet' $targetSite = 'http://pacman-test' $importLogFilename = 'Import.txt' $currentPs1Filename = $MyInvocation .MyCommand.Name $currentPs1FilePath = $MyInvocation .MyCommand.Definition $backupFolder = $currentPs1FilePath .SubString(0, $currentPs1FilePath .indexOf( $currentPs1Filename )) $importLogFilePath = $backupFolder + $importLogFilename $processedFolder = $backupFolder +'Restored\' if (!( Test-Path $importLogFilePath )) { New-item -Path $backupFolder -Name $importLogFilename -ItemType 'file' } Get-ChildItem $backupFolder -Filter *.log | Foreach ...

Scheduling PowerShell to import SPListItem version history into CSV file

Image
Problem I need to populate SQL table to store permanent and temporary address changes from SPList item version history. I need to store the first version and subsequent versions only if the address is updated. All will be stored as CSV file with latest address (version) first. Since the following script will be run as Windows Scheduled Task, it will also rename $csvFileName with original date/time stamp before creating a new one. Solution # Import list item version history of RP content type to CSV file / SQL table # Created by Ben - 7 March 2019 clear start-transcript if ((gsnp '*sharepoint*' -ErrorAction SilentlyContinue) -eq $null ){asnp *sharepoint*} $currentPs1Filename = $MyInvocation .MyCommand.Name $currentPs1FilePath = $MyInvocation .MyCommand.Definition $currentPs1Folder = $currentPs1FilePath .SubString(0, $currentPs1FilePath .indexOf( $currentPs1Filename )) $siteUrl = 'http://your-target-site-url' $csvFileName = 'RPAddressHistory.csv...