Created
June 1, 2020 14:06
-
-
Save pedroppinheiro/8f5cf1ded0a537335218a3418a45713a to your computer and use it in GitHub Desktop.
Script para obter informações de conta expirada dos usuários (ad_check): usando o comando de "net users <usuario> /domain"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const Promise = require('bluebird'); | |
const cmd = require('node-cmd'); | |
const [,, ...args] = process.argv | |
if(!args[0]) { | |
console.log("Informe um nome de usuário") | |
return | |
} | |
const getUserInfo = Promise.promisify(cmd.get, { context: cmd }) | |
async function printUserInfo() { | |
try { | |
const userInfo = await getUserInfo("net users " + args[0] + " /domain"); | |
console.log(userInfo); | |
const whenExpire = getWhenExpire(userInfo); | |
console.log("A conta expira em: " + whenExpire); | |
} catch(error) { | |
console.log(error); | |
} | |
} | |
function getWhenExpire(userInfo) { | |
const regex = /Conta expira em\s+(.+)/; | |
let m; | |
if ((m = regex.exec(userInfo)) !== null) { | |
// The result can be accessed through the `m`-variable. | |
return m[1]; | |
} | |
} | |
printUserInfo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment