Skip to content

搞英语 → 看世界

翻译英文优质信息和名人推特

Menu
  • 首页
  • 作者列表
  • 独立博客
  • 专业媒体
  • 名人推特
  • 邮件列表
  • 关于本站
Menu

在您的 Google Workspace 网域中查找并移除非活跃用户

Posted on 2022-03-07

您可以使用 Google Apps 脚本查找您的 Google Workspace 域中的所有非活动用户帐户。该脚本将查找一段时间内(例如 6 个月)未登录域的所有用户。您还可以选择从 Workspace 域中删除休眠帐户并节省每月账单。

查找 Google Workspace 域中的非活跃用户

我们可以使用 Apps Script 的 Admin Directory 服务列出 Google Workspace 域中的所有用户(活动和非活动)。打开一个新脚本,转到服务部分并启用管理目录服务。

接下来,转到与您的 Apps 脚本项目关联的 Google Cloud 项目。切换到库部分,搜索 Admin SDK 并启用 API。所需的 OAuth 范围是https://www.googleapis.com/auth/admin.directory.user ,它应该列在您的appsscript.json文件中。

 { "timeZone" : "Asia/Kolkata" , "dependencies" : { "enabledAdvancedServices" : [ { "userSymbol" : "AdminDirectory" , "version" : "directory_v1" , "serviceId" : "admin" } ] } , "exceptionLogging" : "STACKDRIVER" , "oauthScopes" : [ "https://www.googleapis.com/auth/admin.directory.user" ] , "runtimeVersion" : "V8" }

Enable Admin Directory SDK

该脚本将列出域中的所有用户,并根据上次登录日期查找休眠帐户。如果用户在过去(例如 6 个月)内没有登录他或她的帐户,则该用户被认为是不活跃的并且可能会被删除。

 const getInactiveAccounts = ( ) => { let accounts = [ ] ; let pageToken = null ; // Replace example.com with your domain name. do { const { users , nextPageToken = null } = AdminDirectory . Users . list ( { domain : 'example.com' , customer : 'my_customer' , maxResults : 100 , orderBy : 'email' , pageToken , } ) ; pageToken = nextPageToken ; accounts = [ ... accounts , ... users ] ; } while ( pageToken !== null ) ; // delete users who haven't logged in the last 6 months const MONTHS = 6 ; const cutOffDate = new Date ( ) ; cutOffDate . setMonth ( cutOffDate . getMonth ( ) - MONTHS ) ; const inactiveAccounts = accounts . filter ( ( { isAdmin } ) => isAdmin === false ) // Skip users with admin priveleges . filter ( ( { lastLoginTime } ) => { const lastLoginDate = new Date ( lastLoginTime ) ; return lastLoginDate < cutOffDate ; } ) . const ( ( { primaryEmail } ) => primaryEmail ) ; // Get only the email address Logger . log ( ` We found ${ inactiveAccounts . length } inactive accounts in the domain. ` ) ; Logger . log ( ` The list is: ${ inactiveAccounts . join ( ', ' ) } ` ) ; // Set this to true if you really want to delete the inactive accounts const DELETE_USER = false ; if ( DELETE_USER ) { // Remove the users from the domain inactiveAccounts . forEach ( ( userEmail ) => { AdminDirectory . Users . remove ( userEmail ) ; Logger . log ( ` Deleted Google Workspace account for ${ userEmail } ` ) ; } ) ; } } ;

来源: https://www.labnol.org/remove-inactive-workspace-users-220307

发表回复 取消回复

要发表评论,您必须先登录。

本站文章系自动翻译,站长会周期检查,如果有不当内容,请点此留言,非常感谢。
  • Abhinav
  • Abigail Pain
  • Adam Fortuna
  • Alberto Gallego
  • Alex Wlchan
  • Answer.AI
  • Arne Bahlo
  • Ben Carlson
  • Ben Kuhn
  • Bert Hubert
  • Bits about Money
  • Brian Krebs
  • ByteByteGo
  • Chip Huyen
  • Chips and Cheese
  • Christopher Butler
  • Cool Infographics
  • Dan Sinker
  • David Walsh
  • Dmitry Dolzhenko
  • Elad Gil
  • Ellie Huxtable
  • Ethan Marcotte
  • Exponential View
  • FAIL Blog
  • Founder Weekly
  • Geoffrey Huntley
  • Geoffrey Litt
  • Greg Mankiw
  • Henrique Dias
  • Hypercritical
  • IEEE Spectrum
  • Investment Talk
  • Jaz
  • Jeff Geerling
  • Jonas Hietala
  • Josh Comeau
  • Lenny Rachitsky
  • Lou Plummer
  • Luke Wroblewski
  • Matt Stoller
  • Mert Bulan
  • Mostly metrics
  • News Letter
  • NextDraft
  • Non_Interactive
  • Not Boring
  • One Useful Thing
  • Phil Eaton
  • Product Market Fit
  • Readwise
  • ReedyBear
  • Robert Heaton
  • Ruben Schade
  • Sage Economics
  • Sam Altman
  • Sam Rose
  • selfh.st
  • Shtetl-Optimized
  • Simon schreibt
  • Slashdot
  • Small Good Things
  • Taylor Troesh
  • Telegram Blog
  • The Macro Compass
  • The Pomp Letter
  • thesephist
  • Thinking Deep & Wide
  • Tim Kellogg
  • 英文媒体
  • 英文推特
  • 英文独立博客
©2025 搞英语 → 看世界 | Design: Newspaperly WordPress Theme