SharePoint, Office 365, Azure, and Front end JS geek. – Chicago IL
SharePoint, Office 365, Azure, and Front end JS geek. – Chicago IL

PowerShell

PowerShell – Split CSV in 1000 line batches

I recently needed to parse a large CSV text file and break it into smaller batches.  Parsing text with PowerShell can easily be done.  The trick here was to manage two pointers $line (within original large text file) and $i (iterate current up to next break threshold).  The first CSV line with column headers from the original parent text file is preserved in all child CSV files. 

Cheers! 

shades_smile

Source Code

MySite – Export user Quick Links to CSV

When migrating from MySite on-premise to OneDrive in the cloud, Quick Links are not included by third party utilities (i.e. ShareGate).  However, with PowerShell we can export the original raw CSV data and provide a list of links to end users.  They can bookmark or add to Office 365.

Cheers! 

shades_smile

 

Code

 

Screenshot

image

 

image

Clone Content Database – SQL Copy + Generate SPSite GUID

Tried of waiting for Backup-SPSite / Restore-SPSite?  Me too.  Why not clone the SQL content database with SQL backup and restore?  

 

Well, SharePoint requires every Site Collection on a given to have a unique GUID.  When we clone a SQL content database and attempt Mount-SPContentDatabase an error comes up that the GUID already exists on the local farm.  No bueno.

Why not generate and replace the GUID?   In theory, we can UDPATE the SQL database internally with fresh new GUID numbers and SharePoint would recognize as new site collections.  No conflict.  That is exactly what the PowerShell below does.  By walking the schema, finding “SiteID” and “tp_SiteID” columns, and replacing the old GUID with a new GUID.

The larger the site collection, the better this works on time savings.  SQL internally can backup and restore a database much faster than waiting for Backup-SPSite/Restore-SPSite to export/import binary data across the wire to the SharePoint front end file system.

In the example below you can see a brand new team site created with GUID “82dad5a8-aa6e-4480-a10e-16cd2597c18b” in a dedicated SQL content database, taken offline, updated with PowerShell to replace old GUID with new GUID “0f59c302-92ea-4fac-b32b-799f3dd41264” and then successfully consumed again.

 

  • NOTE – You still need a unique URL, so be sure to run Mount-SPContentDatabase against a secondary web application.
  • NOTE – This is completely unsupported.  Use at your own risk.   Worked well on Dev and Test environments for me.

 

PowerShell Source Code

 

Context Diagram

image

Screenshots

image
image
image
image
image
image
image
image
image

 

 

References

Many ways to query AD users

There are multiple good PowerShell options to query an Active Directory user object.   Below are three code snippets which all locate an AD user.   Cheers!

 

Option 1- Get-ADUser Login

 

Option 2- Get-ADUser Filter

 

Option 3 – LDAP Directory Searcher

 

Option 4 – DSA.MSC

  1. Open Active Directory Users and Computers.
  2. Right-click the domain object and select Find.
IC125695
  1. Active Directory Users and Computers Select Find
  2. Click the drop-down list next to Find, and then select Custom Search.
IC25246
  1. From the next screen, select the Advanced tab.
  2. Type the appropriate LDAP statement under Enter LDAP query.

 

Option 5 – LDP.EXE

  1. Download from https://www.microsoft.com/en-us/download/details.aspx?id=15326
  2. On the Browse menu, click Search.
  3. The Search dialog box opens.
  4. To search for all users that have a first name of John and a last name of either Smith or Jones, type the following in the Filter field:
  5. (&(objectClass=user)(givenName=John)(|(sn=Smith)(sn=Jones))))
Image result for ldp.exe

 

 

References

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲