Block sign-in and remove licenses for Graduates

%3CLINGO-SUB%20id%3D%22lingo-sub-1623987%22%20slang%3D%22en-US%22%3EBlock%20sign-in%20and%20remove%20licenses%20for%20Graduates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1623987%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20there%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20not%20great%20with%20Powershell%2C%20and%20I've%20been%20trying%20to%20take%20my%20CSV%20of%20grad%20emails%2C%20and%20block%20the%20sign%20in%2C%20and%20remove%20the%20A3%2FA1%20for%20student%20use%20licenses%20from%20the%20uses.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20a%20available%20script%20that%20I%20can%20use%20to%20do%20this%2C%20i%20cant%20seem%20to%20find%20one%20that%20works.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1623987%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eblock%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Elicenses%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1626346%22%20slang%3D%22en-US%22%3ERe%3A%20Block%20sign-in%20and%20remove%20licenses%20for%20Graduates%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1626346%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F632818%22%20target%3D%22_blank%22%3E%40MarcW64%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20nothing%20to%20hand%2C%20but%20I've%20butchered%20a%20script%20I%20used%20last%20year%20to%20remove%20and%20readd%20licences%20for%20a%20bunch%20of%20students.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20should%20work%2C%20but%20try%20it%20on%20a%20single%20user%20to%20start%20off%20with.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24students%20%3D%20import-csv%20%22C%3A%5Csupport%5Cstudent_disable.csv%22%20-delimiter%20%22%2C%22%0Aforeach%20(%24student%20in%20%24students)%0A%7B%0A%0A%20%20%20%20%24ObjectID%3D%24student.ObjectID%0A%20%20%20%20%24sku%3D%24student.sku%0A%20%20%20%20%0A%20%20%20%20Set-MsolUserLicense%20-ObjectID%20%24ObjectID%20-RemoveLicenses%20%24sku%20-Verbose%0A%20%20%20%20Set-MsolUser%20-ObjectID%20%24ObjectID%20%20-BlockCredential%20%24true%20%20%20%20%0A%0A%7D%20%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20csv%20looks%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22csvexample.png%22%20style%3D%22width%3A%20815px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F215926iC53A3489583085EC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22csvexample.png%22%20alt%3D%22csvexample.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20your%20csv%20has%20upn%20rather%20than%20ObjectID%2C%20then%20you%20can%20use%20the%20-UserPrincipalName%20switch%20instead%20of%20-objectid%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUse%26nbsp%3B%3CSTRONG%3EGet-MsolAccountSku%26nbsp%3B%3C%2FSTRONG%3Eto%20get%20the%20correct%20licence%20name%20for%20your%20tenant.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20helps%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello there,

 

I'm not great with Powershell, and I've been trying to take my CSV of grad emails, and block the sign in, and remove the A3/A1 for student use licenses from the uses. 

 

Is there a available script that I can use to do this, i cant seem to find one that works. 

1 Reply

Hi @MarcW64 

 

I have nothing to hand, but I've butchered a script I used last year to remove and readd licences for a bunch of students.

 

It should work, but try it on a single user to start off with.

 

 

$students = import-csv "C:\support\student_disable.csv" -delimiter ","
foreach ($student in $students)
{

    $ObjectID=$student.ObjectID
    $sku=$student.sku
    
    Set-MsolUserLicense -ObjectID $ObjectID -RemoveLicenses $sku -Verbose
    Set-MsolUser -ObjectID $ObjectID  -BlockCredential $true    

} 

 

 

The csv looks like this:

 

csvexample.png

 

If your csv has upn rather than ObjectID, then you can use the -UserPrincipalName switch instead of -objectid

 

Use Get-MsolAccountSku to get the correct licence name for your tenant. 

 

Hope this helps,

www.000webhost.com