Olá,
Dessa vez vamos fazer algo um pouco diferente. Seu Chefe já lhe solicitou uma relação de usuarios inativos no Active Directory por mais de 3 meses por exemplo? Com esse script voce pode mandar o relatorio diretamente por email em formato HTML com formatação em CSS.
<# .SYNOPSIS Gets the recent users and groups from Active Directory created within a month. .DESCRIPTION Gets the recent users and groups from Active Directory created within a month. .PARAMETER No parameters required .EXAMPLE #> #Setting Date of One month Back $month = (Get-Date).AddMonths(-3) #CSS Style for the HTML page $style = @' body { font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; color: #4f6b72; background: #E6EAE9; } a { color: #c75f3e; } #mytable { width: 700px; padding: 0; margin: 0; } caption { padding: 0 0 5px 0; width: 700px; font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; text-align: right; } th { font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; color: #4f6b72; border-right: 1px solid #C1DAD7; border-bottom: 1px solid #C1DAD7; border-top: 1px solid #C1DAD7; letter-spacing: 2px; text-transform: uppercase; text-align: left; padding: 6px 6px 6px 12px; background: #CAE8EA url(images/bg_header.jpg) no-repeat; } th.nobg { border-top: 0; border-left: 0; border-right: 1px solid #C1DAD7; background: none; } td { border-right: 1px solid #C1DAD7; border-bottom: 1px solid #C1DAD7; background: #fff; padding: 6px 6px 6px 12px; color: #4f6b72; } td.alt { background: #F5FAFA; color: #797268; } th.spec { border-left: 1px solid #C1DAD7; border-top: 0; background: #fff url(images/bullet1.gif) no-repeat; font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; } th.specalt { border-left: 1px solid #C1DAD7; border-top: 0; background: #f5fafa url(images/bullet2.gif) no-repeat; font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; color: #797268; } '@ # Email Variables $smtp = "smtp.mail.com" $to = "[email protected]" $from = "System Reports" $subject = "Inactive Users Report" # Import Module of Active Directory Import-Module -Name ActiveDirectory # Run Command $Users = Search-ADAccount -AccountInactive -DateTime ((Get-Date).AddMonths(-6)) -UsersOnly | Get-ADUser -Properties * | Where-Object { $_.DistinguishedName -notlike "*CN=Users,DC=NETSHOES,DC=LOCAL" } | ` Select-Object -Property @{ Name = 'Nome'; Expression = {$_.name} }, ` @{ Name = "Login" ; Expression = { $_.SamAccountName } }, ` @{ Name = "E-mail" ; Expression = { $_.mail }}, ` @{ Name = "Departamento" ; Expression = { $_.Department } }, ` @{ Name = "Unidade" ; Expression = { $_.Office } }, ` @{ Name = "Endereço" ; Expression = { $_.StreetAddress } }, ` @{ Name = "Empresa" ; Expression = { $_.Company } }, ` @{ Name = "Cidade" ; Expression = { $_.City } }, ` @{ Name = "Equipe" ; Expression = { $_.Description } }, ` @{ Name= "Criação" ; Expression = { $_.WhenCreated }} , ` @{ Name= "Ultimo Logon" ; Expression = { $_.LastLogonTimeStamp }} | ConvertTo-html -Fragment | Out-String [string]$btitle = "<H1>Usuários Inativos desde: $month</H1>"
$message = ConvertTo-Html -Head $style -PreContent "$btitle $Users" | Out-String Send-MailMessage -SmtpServer $smtp -To $to -Body $message -From $from -Subject $subject -BodyAsHtml -Encoding UTF8
Dúvidas? Sugestões? Comente!
Até a próxima!
1 Comments
up