Delete Pending Accounts

%3CLINGO-SUB%20id%3D%22lingo-sub-13209%22%20slang%3D%22en-US%22%3EDelete%20Pending%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-13209%22%20slang%3D%22en-US%22%3E%3CP%3EI%20wrote%20a%20little%20powershell%20app%20to%20remove%20pending%20users.%20I%20manually%20run%20a%20user%20export%2C%20and%20then%20in%20Excel%20I%20sort%20by%20status%2C%20then%20deleted_at%2C%20and%20then%20ID.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESee%2C%20when%20someone%20is%20invited%2C%20that%20account%20is%20in%20a%20pre-active%20state%20until%20the%20account%20is%20verified%20by%20the%20user%20responding%20to%20the%20invitation%20email.%20If%20that%20person%20never%20activates%20or%20never%20uses%20Yammer%2C%20then%20the%20account%20will%20stay%20in%20pending%20status%20for%20a%20very%20long%20time.%20Additionally%2C%20that%20pending%20user%20will%20be%20suggested%20in%20the%20right%20navigation%20in%20the%20second%20slot%2C%20as%20an%20engagement%20feature%20of%20Yammer%20(encouraging%20the%20tentative%20to%20be%20invited%20again).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20normal%20admin%20function%20is%20to%20clean%20this%20list%20out%20from%20time%20to%20time.%20You%20don't%20want%20to%20delete%20the%20fresh%20invitations%2C%20so%20you%20choose%20to%20get%20rid%20of%20the%20older%20ones%20who%20have%20been%20hanging%20out%20for%20a%20while.%20These%20are%20listed%20in%20your%20user%20export%20as%20any%20accounts%20with%20a%20status%20of%20soft_delete%20and%20have%20a%20blank%20deleted_at%20date.%20The%20third%20sort%20by%20ID%20is%20to%20get%20the%20older%20ones%2C%20since%20ID%20is%20assigned%20sequentially.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECouple%20ways%20to%20use%20this%20script.%20You%20can%20take%20your%20indicated%20accounts%20and%20put%20them%20into%20a%20text%20file%3B%20just%20make%20sure%20the%20first%20line%20says%20%22id%22%20(no%20quotes).%20Or%20you%20can%20delete%20the%20lines%20of%20your%20export%20of%20users%20you%20want%20to%20keep%20and%20just%20use%20the%20export%20file.%20I%20don't%20recommend%20this%2C%20because%20of%20the%20next%20paragraph.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EANY%20USER%20IDs%20IN%20THIS%20LIST%20ARE%20DELETED%20FOREVER.%20There%20is%20no%20getting%20them%20back%2C%20even%20by%20Microsoft.%20No%20amount%20of%20begging%2C%20pleading%2C%20or%20bribery%20will%20get%20them%20back.%20They're%20gone.%20Test%20test%20test.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20use%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.)%20Build%20your%20target%20list%20as%20above%20(screenshot%20below).%20In%20the%20script%2C%20I%20saved%20the%20file%20as%20C%3A%5CData%5CYammer%5CPowershell%5CAncientPenders.csv.%20Welcome%20to%20use%20this%20path%2C%20as%20long%20as%20you%20make%20sure%20the%20path%20exists%20and%20the%20file%20is%20in%20that%20directory.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2.)%20Update%20%3CYOUR%20token%3D%22%22%3E%20with%20your%20actual%20token.%20If%20you%20don't%20know%20how%20to%20get%20one%2C%20go%20to%20%3CA%20href%3D%22https%3A%2F%2Fdeveloper.yammer.com%2Fdocs%2Ftest-token%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.yammer.com%2Fdocs%2Ftest-token%3C%2FA%3E.%20It's%20a%20little%20bit%20confusing%2C%20good%20luck.%3C%2FYOUR%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E3.)%20Save%20this%20script%20as%20a%20text%20file%20(below)%20with%20the%20.ps1%20file%20extension.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E4.)%20Open%20up%20Windows%20PowerShell%20and%20run%20the%20script%20by%20typing%20.%5C%3CFILENAME%3E.%3C%2FFILENAME%3E%3C%2FP%3E%3CPRE%3E%20%24token%20%3D%20%22%26lt%3BYour%20Token%26gt%3B%22%0A%0A%20%24Headers%20%3D%20%40%7B%0A%20%22Accept%22%20%3D%20%22*%2F*%22%0A%20%22Authorization%22%20%3D%20%22Bearer%20%22%2B%24token%0A%20%22accept-encoding%22%20%3D%20%22gzip%22%0A%20%22content-type%22%3D%22application%2Fjson%22%0A%20%22content-length%22%20%3D%20%222%22%0A%20%7D%0A%0A%23import%20User%20ID's%20that%20need%20removed.%0A%20%24users%20%3D%20import-csv%20C%3A%5CData%5CYammer%5CPowershell%5CAncientPenders.csv%0A%20%24users%20%3D%20%24users.id%0A%0A%23loop%20through%20all%20User%20ID's%0A%20foreach%20(%24user%20in%20%24users)%7B%0A%0A%20%24uri%20%3D%20%22https%3A%2F%2Fwww.yammer.com%2Fapi%2Fv1%2Fusers%2F%24user.json%3Fdelete%3Dtrue%22%0A%0AWrite-Host%20%24uri%0A%0A(Invoke-WebRequest%20-Uri%20%24uri%20-Method%20Delete%20-Headers%20%24Headers).content%20%7C%20ConvertFrom-Json%0A%0A%20%7D%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20612px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F4114i1A4CA834CA1BFFAE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22DOP1.png%22%20title%3D%22DOP1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E(Originally%20posted%20on%20the%20Office%20365%20Network%26nbsp%3B29%20January%2C%202016.)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-13209%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ECommunity%20Management%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EEnterprise%20Social%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EYammer%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-127337%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20Pending%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-127337%22%20slang%3D%22en-US%22%3E%3CP%3EYes%3B%20the%20user%20messages%20are%20kept.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-68826%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20Pending%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-68826%22%20slang%3D%22en-US%22%3EThanks%2C%20awesome!%3CBR%20%2F%3E%3CBR%20%2F%3EDoes%20this%20method%20of%20deletion%20keep%20the%20user%20messages%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-50125%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20Pending%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-50125%22%20slang%3D%22en-US%22%3E%3CP%3EWow%2C%20no%2C%20that%20is%20strange.%20%26nbsp%3BHowever%2C%20I%20have%26nbsp%3Bwondered%20at%20the%20completeness%20of%20the%20user%20export.%20%26nbsp%3BWhenever%20I%20think%20I%20see%20a%20deficiency%2C%20I%20re-check%20and%20it%20turns%20out%20that%20it's%20my%20error%20(limiting%20the%20date%20range)%2C%20but%20still...%20%26nbsp%3BSo%20what%20I%20do%20now%20is%20I%20do%20a%20full%20export%20(no%20attachments)%2C%20and%20I%20set%20the%20date%20to%20something%20like%201%2F1%2F1970%2C%20to%20ensure%20that%20I%20get%20all%20the%20data.%20%26nbsp%3BThe%20user%20export%20in%20that%20usually%20is%20completely%20solid.%20%26nbsp%3BMight%20want%20to%20give%20that%20a%20go.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENice%20find%20with%20that%20API.%20%26nbsp%3B%3A)%3C%2Fimg%3E%20%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-50098%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20Pending%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-50098%22%20slang%3D%22en-US%22%3E%3CP%3EAlright%2024hrs%20have%20come%20and%20gone%2C%20so%20far%20so%20good%20-%20all%20of%20the%20users%20I%20deleted%20no%20longer%20show%20up.%3C%2FP%3E%3CP%3EBut%3A%20There%20are%20still%20users%20showing%20up%20in%20the%20%22Suggested%20People%22%20widget%20who%20I%20don't%20want%20to%20show%20up.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20API%20endpoint%20providing%20those%20items%20seems%20to%20be%20this%3A%20%3CA%20href%3D%22https%3A%2F%2Fwww.yammer.com%2Fapi%2Fv1%2Fsuggestions.json%3Ftype%3Dcontact_invite%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.yammer.com%2Fapi%2Fv1%2Fsuggestions.json%3Ftype%3Dcontact_invite%3C%2FA%3E%3C%2FP%3E%3CP%3EThe%20parameter%20%22type%22%20is%20important%20-%20it%20leads%20to%20the%20result%20being%20a%20couple%20of%20users%20with%20the%20state%20%22pending%22.%3C%2FP%3E%3CP%3EWhat's%20interesting%20about%20them%20is%20they%20don't%20show%20up%20in%20the%20user%20export!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDid%20you%20come%20across%20this%20phenomenon%20as%20well%3F%3C%2FP%3E%3CP%3EI%20would%20go%20ahead%20and%20just%20delete%20those%20by%20the%20ID%20provided%20in%20the%20response%20JSON.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-49957%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20Pending%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-49957%22%20slang%3D%22en-US%22%3E%3CP%3EYou're%20very%20welcome.%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20noticed%20some%20administrative%20actions%20in%20Yammer%20take%20a%20little%20bit%20of%20time%20to%20%22take%22.%20%26nbsp%3BIf%20the%20account%20is%20still%20showing%20up%20after%2024%20hours%2C%20then%20there%20probably%20is%20an%20additional%20account%20to%20delete%2C%20or%20else%20they%20were%20re-added.%20%26nbsp%3BSometimes%20I've%20had%20to%20block%20the%20account%20to%20prevent%20them%20from%20being%20re-invited.%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EShould%20only%20be%20a%20few%20minutes%2C%20but%20if%20it's%20a%20few%20hours%2C%20you're%20still%20within%20the%20realm%20of%20normalcy%2C%20at%20least%20in%20my%20experience.%20%26nbsp%3BI%20use%2024%20hours%20as%20my%20measuring%20stick.%20%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-49817%22%20slang%3D%22en-US%22%3ERe%3A%20Delete%20Pending%20Accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-49817%22%20slang%3D%22en-US%22%3E%3CP%3ETom%20-%20thanks%20for%20this%20great%20little%20script!%3C%2FP%3E%3CP%3EOne%20question%3A%20From%20your%20experience%20-%20how%20long%20does%20it%20take%20until%20the%20removed%20user%20no%20longer%20appear%20in%20the%20%22Suggested%20People%22%20widget%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Regular Contributor

I wrote a little powershell app to remove pending users. I manually run a user export, and then in Excel I sort by status, then deleted_at, and then ID.

 

See, when someone is invited, that account is in a pre-active state until the account is verified by the user responding to the invitation email. If that person never activates or never uses Yammer, then the account will stay in pending status for a very long time. Additionally, that pending user will be suggested in the right navigation in the second slot, as an engagement feature of Yammer (encouraging the tentative to be invited again).

 

A normal admin function is to clean this list out from time to time. You don't want to delete the fresh invitations, so you choose to get rid of the older ones who have been hanging out for a while. These are listed in your user export as any accounts with a status of soft_delete and have a blank deleted_at date. The third sort by ID is to get the older ones, since ID is assigned sequentially.

 

Couple ways to use this script. You can take your indicated accounts and put them into a text file; just make sure the first line says "id" (no quotes). Or you can delete the lines of your export of users you want to keep and just use the export file. I don't recommend this, because of the next paragraph.

 

ANY USER IDs IN THIS LIST ARE DELETED FOREVER. There is no getting them back, even by Microsoft. No amount of begging, pleading, or bribery will get them back. They're gone. Test test test.

 

To use:

 

1.) Build your target list as above (screenshot below). In the script, I saved the file as C:\Data\Yammer\Powershell\AncientPenders.csv. Welcome to use this path, as long as you make sure the path exists and the file is in that directory.

 

2.) Update <Your Token> with your actual token. If you don't know how to get one, go to https://developer.yammer.com/docs/test-token. It's a little bit confusing, good luck.

 

3.) Save this script as a text file (below) with the .ps1 file extension.

 

4.) Open up Windows PowerShell and run the script by typing .\<filename>.

 $token = "<Your Token>"

 $Headers = @{
 "Accept" = "*/*"
 "Authorization" = "Bearer "+$token
 "accept-encoding" = "gzip"
 "content-type"="application/json"
 "content-length" = "2"
 }

#import User ID's that need removed.
 $users = import-csv C:\Data\Yammer\Powershell\AncientPenders.csv
 $users = $users.id

#loop through all User ID's
 foreach ($user in $users){

 $uri = "https://www.yammer.com/api/v1/users/$user.json?delete=true"

Write-Host $uri

(Invoke-WebRequest -Uri $uri -Method Delete -Headers $Headers).content | ConvertFrom-Json

 }

 

DOP1.png

(Originally posted on the Office 365 Network 29 January, 2016.)

6 Replies

Tom - thanks for this great little script!

One question: From your experience - how long does it take until the removed user no longer appear in the "Suggested People" widget?

Highlighted

You're very welcome.  

 

I've noticed some administrative actions in Yammer take a little bit of time to "take".  If the account is still showing up after 24 hours, then there probably is an additional account to delete, or else they were re-added.  Sometimes I've had to block the account to prevent them from being re-invited.  

 

Should only be a few minutes, but if it's a few hours, you're still within the realm of normalcy, at least in my experience.  I use 24 hours as my measuring stick.  

Highlighted

Alright 24hrs have come and gone, so far so good - all of the users I deleted no longer show up.

But: There are still users showing up in the "Suggested People" widget who I don't want to show up.

 

The API endpoint providing those items seems to be this: https://www.yammer.com/api/v1/suggestions.json?type=contact_invite

The parameter "type" is important - it leads to the result being a couple of users with the state "pending".

What's interesting about them is they don't show up in the user export!

 

Did you come across this phenomenon as well?

I would go ahead and just delete those by the ID provided in the response JSON.

Highlighted

Wow, no, that is strange.  However, I have wondered at the completeness of the user export.  Whenever I think I see a deficiency, I re-check and it turns out that it's my error (limiting the date range), but still...  So what I do now is I do a full export (no attachments), and I set the date to something like 1/1/1970, to ensure that I get all the data.  The user export in that usually is completely solid.  Might want to give that a go.

 

Nice find with that API.  :)  

Highlighted
Thanks, awesome!

Does this method of deletion keep the user messages?
Highlighted

Yes; the user messages are kept.