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

PowerShell

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

PowerShell – Cache AD User Lookup

Given a filter value, this PowerShell function will query Active Directory to find a matching user object and store results in a memory cache.  By default “samAccountName” is used for filter.  Optional field name can be provided to filter by any field such as Manager, Mail, or DN. 

Cheers!  

shades_smile

 

 

Source Code

https://github.com/spjeff/spadmin/blob/master/lookupADUser.ps1

 

 

Screenshot

2017-01-27_14-18-07

Replace CE / SE Web Part Content PS1

Managing front end code (HTML/JS) embedded within Script and Content Editor Web Parts can be a hassle.   With multiple instances scattered across ASPX pages, web part galleries, and many sites quickly becomes untenable.

The below PowerShell script gives SharePoint admins a new way to search/replace the internal text of CEWP/SEWP web parts within a target site collection.    Updating a URL reference or DNS name can now be done across potentially hundreds  of WP in just a few minutes.

For example, a team site having 1 CEWP and 1 SEWP with the world “hello” can be quickly replaced with “hola” by running this script.

Cheers! 

shades_smile

 

Source Code

 

Screenshot – Before

1

 

3

 

Screenshot – After

5
6
7

 

8

PowerShell – Create SharePoint Alert remotely (CSOM)

I want to migrate user alerts to Office 365 from SharePoint 2013 on-prem and was surprised to learn there is no client side API for creating Alerts.   Not SOAP, not REST, nothing but the web browser ASPX web form GUI.

So I took Fiddler and inspected the HTTP POST traffic when you click “OK” on the SharePoint “SubNew.aspx” page in the browser.   Lots of great detail!    You can see all the ASPX web form controls and internal values.   Clicking the “OK” button posts that event back to the server side Dot Net for processing with Request Digest, ViewState, and lots of cool stuff.

So …. could we simulate sending that same HTTP traffic?   From somewhere else?    Like PowerShell??    That’d be awesome!

 

Below is the working concept. PowerShell function with a handful of sample calls. Immediate alert, Daily, Weekly scheduled, etc. With various recipients and filters. Enjoy! 

shades_smile

 

Screenshots

image
image
image
image
image
image

 

Code  (CreateSPAlert.ps1)

 

 

References

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲