Script Powershell AD – Scanner et Ajouter

image002Mettre a jour le champ email

 

Aujourd’hui, je vous propose un script powershell assez simple que j’ai du mettre en place pour mettre à jour les champs email des comptes utilisateurs d’un active directory.

Il affiche un choix de menu que l’on peut aisément agrandir et adapter à d’autres traitements. Basé sur QAD et en admettant que vous avez les droits admin (sinon il faut faire un get-credential et le stocker dans une variable, vous pouvez facilement le modifier).

De plus, il vous permet de voir une structure composée de commandes imbriquées telles que do-until-switch-foreach-for assez astucieuse je trouve. Les logs sont générés pour être adapter a la structure mais on pourrait très bien le faire en try-catch pour mettre en place une gestion des erreurs si le script venait a grandir et effectuer d’autres traitements. Vous découvrirez également la notion de $tableau, bref que du bonheur 😀

 

Cls
 $log = "result.log"
 $scriptpath = get-location
 $date = get-date
 "*** Debut *** a $date" >> $log
$req = get-qaduser -searchroot 'votre domaine ici' -enabled | select samaccountname,mail,givenname,userprincipalname

$tableau = @()

[Int]$nbr = 0 | Out-Null
[Int]$nbr2 = 0 | out-null

do {
do {
Write-Host ""
Write-Host "A - Scanner et Ajouter les emails aux utilisateurs du domaine"
Write-Host "Q - Quitter"
Write-Host ""
write-host -nonewline "Entrer votre choix (A/Q) puis entrée : "
$choix = read-host
write-host ""
$ok = @("A","Q") -contains $choix
if ( -not $ok) { Write-Host "Choix pas disponible" -fore Red }
}
until ( $ok )
switch ( $choix ) {
"A" {
Write-Host "Vous avez choisi 'A'"
cls

foreach ($user in $req) {

write-host "***************" -BackgroundColor black -ForegroundColor White
write-host $user.samaccountname

if(Get-QADMemberOf $user.samaccountname -Indirect -Name Posh_ID){

# comptes non valide pour creation email

write-host "Compte de service trouvés" -foregroundcolor red
write-host "MAJ Email IGNOREE... $user" -foregroundcolor red
$nbr++

}else{

if($user.mail -eq $null){

# comptes valides on continue

write-host "Ce compte n'a pas d'email et va etre mis a jour" -ForegroundColor Yellow
set-aduser -identity $user.samaccountname -EmailAddress $user.UserPrincipalName
write-host "MAJ Email ... $user" -ForegroundColor Green
$nbr2++
"MAJ Email ... $user" >> $log

}
}
$tableau += $user
}

for ($count = 0; $count -le $tableau.Length; $count++){
$user = $tableau[$count]}
#cls
Write-host "Il y a $nbr comptes ignores" -ForegroundColor red
Write-host "Il y a $nbr2 comptes a modifier" -ForegroundColor Green
"Terminé ! Nbre comptes ignores $nbr et nombre comptes modifies $nbr2" >> $log
write-host "Terminé voir $scriptpath\$log" -ForegroundColor Green
# $tableau >> $log
"*** Fin *** a $date" >> $log
}
"Q" {
cls
Write-Host "Bye" -fore yellow
"Aucun changement effectue $date" >> $log
break
}
}
}
until ( $choix -eq "Q" )

Bon on va détailler tout ca et le réecrire car il ya eu une conversion malheureuse de plugin wordpress sur la syntaxe du code et vlan, patatra…

Modifier Prompt Powershell – Fonction pour ajouter dossier / sous dossier

Un bout de code intéressant, voir indispensable 😉

[codesyntax lang=”powershell”]

function prompt {
 $cwd = (get-location).Path

[array]$cwdt=$()
$cwdi=-1
do {
$cwdi=$cwd.indexofany(”\\”,$cwdi+1)
[array]$cwdt+=$cwdi} until($cwdi -eq -1)

if ($cwdt.count -gt 3) {
$cwd = $cwd.substring(0,$cwdt[0]) + “\..” + $cwd.substring($cwdt[$cwdt.count-3])
}

” $cwd>_ ”
}
# The above sets prompt to the current drive letter, immediate sub directory and current directory.
#     Example: C:\..\drivers\etc>_

Import-Module Pscx #-arg ~\Pscx.UserPreferences.ps1

[/codesyntax]

Wordfence Plugin – Php7 – WordPress 4.4 : OK

image002Installation et configuration de Wordfence sous php7 et wordpress 4.4 : CHECK

Plutôt pas mal ce plugin et tout est compatible visiblement avec WordPress 4.4 sous php7, ca bosse bien 😉

On lance un scan depuis l’interface admin de Wordfence :

wordfence-scan

On peut suivre le scan dans l’interface, ou le laisser continuer, étape par étape puis constater le résultat.

2

Enfin, on a un détail des actions a mener sur les fichiers incriminés ou pas (comme là) 😀

3

Vous pouvez le trouver directement sur le repo WP

Description complète :

THE MOST DOWNLOADED WORDPRESS SECURITY PLUGIN

Wordfence starts by checking if your site is already infected. We do a deep server-side scan of your source code comparing it to the Official WordPress repository for core, themes and plugins. Then Wordfence secures your site and makes it up to 50 times faster.

Wordfence Security is 100% free and open source. We also offer a Premium API key that gives you Premium Support, Country Blocking, Scheduled Scans, Password Auditing and we even check if your website IP address is being used to Spamvertize. Click here to sign-up for Wordfence Premium now or simply install Wordfence free and start protecting your website.

You can find our official documentation at docs.wordfence.com and our Frequently Asked Questions on our support portal at support.wordfence.com. We are also active in our community support forums on wordpress.org if you are one of our free users. Our Premium Support Ticket System is at support.wordfence.com.

This is a brief introductory video for Wordfence:

Wordfence Security is now Multi-Site compatible and includes Cellphone Sign-in which permanently secures your website from brute force hacks.

WORDFENCE WORDPRESS SECURITY FEATURES

Blocking Features

  • Real-time blocking of known attackers. If another site using Wordfence is attacked and blocks the attacker, your site is automatically protected.
  • Block entire malicious networks. Includes advanced IP and Domain WHOIS to report malicious IP’s or networks and block entire networks using the firewall. Report security threats to network owner.
  • Rate limit or block security threats like aggressive crawlers, scrapers and bots doing security scans for vulnerabilities in your site.
  • Choose whether you want to block or throttle users and robots who break your security rules.
  • Premium users can also block countries and schedule scans for specific times and a higher frequency.

Login Security

  • Sign-in using your password and your cellphone to vastly improve login security. This is called Two Factor Authentication and is used by banks, government agencies and military world-wide for highest security authentication.
  • Includes two-factor authentication, also referred to as cellphone sign-in.
  • Enforce strong passwords among your administrators, publishers and users. Improve login security.
  • Checks the strength of all user and admin passwords to enhance login security.
  • Includes login security to lock out brute force hacks and to stop WordPress from revealing info that will compromise security.

Security Scanning

  • Scans for the HeartBleed vulnerability – included in the free scan for all users.
  • Scans core files, themes and plugins against WordPress.org repository versions to check their integrity. Verify security of your source.
  • See how files have changed. Optionally repair changed files that are security threats.
  • Scans for signatures of over 44,000 known malware variants that are known security threats.
  • Scans for many known backdoors that create security holes including C99, R57, RootShell, Crystal Shell, Matamu, Cybershell, W4cking, Sniper, Predator, Jackal, Phantasma, GFS, Dive, Dx and many many more.
  • Continuously scans for malware and phishing URL’s including all URL’s on the Google Safe Browsing List in all your comments, posts and files that are security threats.
  • Scans for heuristics of backdoors, trojans, suspicious code and other security issues.

WordPress Firewall

  • Includes a firewall to block common security threats like fake Googlebots, malicious scans from hackers and botnets.

Monitoring Features

  • See all your traffic in real-time, including robots, humans, 404 errors, logins and logouts and who is consuming most of your content. Enhances your situational awareness of which security threats your site is facing.
  • A real-time view of all traffic including automated bots that often constitute security threats that Javascript analytics packages never show you.
  • Real-time traffic includes reverse DNS and city-level geolocation. Know which geographic area security threats originate from.
  • Monitor your DNS security for unauthorized DNS changes.
  • Monitors disk space which is related to security because many DDoS attacks attempt to consume all disk space to create denial of service.

Multi-Site Security

  • Wordfence Security for multi-site also scans all posts and comments across all blogs from one admin panel.
  • WordPress Multi-Site (or WordPress MU in the older parlance) compatible.

Caching Features

  • Includes Falcon Engine, the fastest WordPress caching engine available today. Falcon is faster because it reduces your web server disk and database activity to a minimum.
  • Wordfence includes two caching modes for compatability and has cache management features like the ability to clear the cache and monitor cache usage.

IPv6 Compatible

  • Fully IPv6 compatible including all whois lookup, location, blocking and security functions.

Major Theme and Plugins Supported

  • Includes support for other major plugins and themes like WooCommerce.

The Wordfence WordPress security plugin is full-featured and constantly updated by our team to incorporate the latest security features and to hunt for the newest security threats to your WordPress website.

Bonne lecture ! Bonne installation 😉