Skip to content

Instantly share code, notes, and snippets.

@pedroppinheiro
Created June 1, 2020 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedroppinheiro/8f5cf1ded0a537335218a3418a45713a to your computer and use it in GitHub Desktop.
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"
#!/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