Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.
Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.

Blog

MS Teams Purge Dormant Profiles

Wanted to automate Windows 10 desktop clean up process where we remove dormant local user profiles holding “Microsoft Teams” cache data.

Considering how local cache for Microsoft Teams may contain confidential data, removal for dormant users provides higher security. PowerShell automation below. Cheers.

Code

https://github.com/spjeff/office365/blob/master/MS-Teams-Purge-Profile.ps1

# Discover all local users
$profile    = $env:USERPROFILE
$root       = (Get-ChildItem $profile)[0].Parent.Parent.FullName
$allUsers   = $root | Get-ChildItem -Directory -Exclude "Public"

# Compare to Active Directory
foreach ($u in $allUsers) {
	# Define scope
	$name       = $u.Name
	$ldap       = "(&(ObjectCategory=Person)(ObjectClass=User)(SamAccountName=" + $name + "))"
	$search     = [adsisearcher]$ldap
	$results    = $search.FindAll()

	# Search Active Directory
	if ($results.Count -eq 0) {
		Write-Host "NOT FOUND [" + $name + "] IN AD.  DELETE FOLDER." -ForegroundColor "Yellow"
		Remove-Item "$root\$name" -Force
	} else {
		Write-Host "FOUND [" + $name + "] IN AD" -ForegroundColor "Green"
	}
}

Screenshot

References

VIDEO – MS Flow Grant Site Collection Admin (SCA) with HTTP to REST api

Demo for how to grant SharePoint Site Collection Admin (SCA) permission to by Ensure SPUser ID number. PowerAutomate (MS Flow) provides an action step for sending HTTP POST to SharePoint with all needed authentication headers. Works better than generic HTTP POST flow action when communicating over SharePoint REST api.

SharePoint users have ID numbers we can embed in the REST URL with “getuserbyid()” to grant SCA permission. We leverage Chrome F12 “fetch()” function to run test cases, view JSON reply, and copy JSON into MS Flow “Parse JSON” step instead of classic Fiddler or Postman technique. Simpler and brings full SharePoint authentication context with “X-RequestDigest.”

Cheers.

VIDEO

CODE

fetch(‘https://spjeff.sharepoint.com/_api/web/ensureuser’, {
method: ‘POST’,
body: JSON.stringify({
‘logonName’: ‘spjeff@spjeff.com’
}),
headers: {
‘Content-type’: ‘application/json; charset=UTF-8’,
‘Accept’: ‘application/json;odata=verbose’,
‘X-RequestDigest’: $(‘#__REQUESTDIGEST’).value
}
})
.then(res => res.json())
.then(console.log)

REFERENCES

VIDEO – MS Flow Bypass Until Go Live Date

Wanted to record brief demo video showing how to add “Bypass” step for MS Flow (PowerAutomate).   Simple conditional step with Terminate action to cancel flow execute before planned future Go Live date.    Terminate  will return “Cancelled” status if today’s date is less than fixed Go Live date.  Cheers.

VIDEO

SCREENSHOT

CODE

formatDateTime(utcNow(), ‘yyyy-mm-dd’)

is less than

formatDateTime(’08/13/2021′)

REFERENCE

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲