Question
Fonction d'audite en Powershell
- Eric
- Auteur du sujet
- Hors Ligne
- Membre junior
Réduire
Plus d'informations
- Messages : 20
- Remerciements reçus 0
il y a 9 ans 10 mois #17571
par Eric
Fonction d'audite en Powershell a été créé par Eric
Bonjour à tous,
Je suis admin sys et en raison d'un audite dans mon entreprise j'ai créé une petite appli contenant plusieurs fonctions d'extraction de données :
Get-LocalUser : Extraction des utilisateurs locaux de plusieurs serveurs. La fonction extrait dans un rapport excel le nom et plusieurs attributs concernant le compte.
Get-LocalADMGroup : qui extrait tous les groupes ou utilisateurs qui sont situés dans le groupe administrators des serveurs. Et chaque groupe est ensuite détaillè(listing des comptes) dans un second onglet.
Get-Share : qui extrait tous les partages des serveurs en indiquant les share permissions et NTFS permissions de chaque partage.
Get-ACLFromFolder : qui extrait tous les groupes et comptes utilisateurs d'un répertoire et de ses sous répertoires. Avec niveau de scan et les informations sur les droits des groupes.
J'aurais voulu savoir si lors d'audites vous auriez rencontré d'autre demandes sur l'infra afin de pouvoir compléter mon appli perso.
Merci d'avance à ceux qui prendront le temps de me lire et de me répondre.
Je suis admin sys et en raison d'un audite dans mon entreprise j'ai créé une petite appli contenant plusieurs fonctions d'extraction de données :
Get-LocalUser : Extraction des utilisateurs locaux de plusieurs serveurs. La fonction extrait dans un rapport excel le nom et plusieurs attributs concernant le compte.
Get-LocalADMGroup : qui extrait tous les groupes ou utilisateurs qui sont situés dans le groupe administrators des serveurs. Et chaque groupe est ensuite détaillè(listing des comptes) dans un second onglet.
Get-Share : qui extrait tous les partages des serveurs en indiquant les share permissions et NTFS permissions de chaque partage.
Get-ACLFromFolder : qui extrait tous les groupes et comptes utilisateurs d'un répertoire et de ses sous répertoires. Avec niveau de scan et les informations sur les droits des groupes.
J'aurais voulu savoir si lors d'audites vous auriez rencontré d'autre demandes sur l'infra afin de pouvoir compléter mon appli perso.
Merci d'avance à ceux qui prendront le temps de me lire et de me répondre.
Connexion ou Créer un compte pour participer à la conversation.
- Nicolas Guerin
- Hors Ligne
- Membre junior
Réduire
Plus d'informations
- Messages : 33
- Remerciements reçus 0
il y a 9 ans 10 mois #17579
par Nicolas Guerin
Réponse de Nicolas Guerin sur le sujet Re:Fonction d'audite en Powershell
Bonjour,
Si tu t'occupe aussi des serveur de fichier, tu pourrais faire un script pour détecter tout les doublons.
Ou même de voir si tout les groupes de fichiers ont une utilités.
Liste des OU, utilisateur, groupes ordinateurs ... C'est utile pour ce faire une idée de l'ampleur d'un domaine.
Je ne vois pas grand chose en plus.
Par contre je suis intéressé, comptes tu partager certaines de tes création?
Cordialement Nicolas.
Si tu t'occupe aussi des serveur de fichier, tu pourrais faire un script pour détecter tout les doublons.
Ou même de voir si tout les groupes de fichiers ont une utilités.
Liste des OU, utilisateur, groupes ordinateurs ... C'est utile pour ce faire une idée de l'ampleur d'un domaine.
Je ne vois pas grand chose en plus.
Par contre je suis intéressé, comptes tu partager certaines de tes création?
Cordialement Nicolas.
Connexion ou Créer un compte pour participer à la conversation.
- Eric
- Auteur du sujet
- Hors Ligne
- Membre junior
Réduire
Plus d'informations
- Messages : 20
- Remerciements reçus 0
il y a 9 ans 10 mois #17581
par Eric
Réponse de Eric sur le sujet Re:Fonction d'audite en Powershell
Merci pour ta réponse. Les doublons de répertoire dans les grandes infra ne posent pas de problèmes aux auditeurs.
Pour le partage voila la fonction Get-LocalUser :
Il te faudra PS V3 et excel d'installé sur ta machine.
Si tu lance le script sur windows 7 il te manquera les infos de la colonne Remote controle. Par contre si tu lance le script à partir de Server 2008 tu auras le rapport excel complet.
#***************************************************************************************#
# #
# #### #### # # #### #### #### # # #### # # ### #### ## # #### #
# # # # # # # # # # # # # # # # # # # # # # # # # #
# #### # # # # # ### #### #### #### ### # # # # # # # # # ### #
# # # # # # # # # # # # # # # # # # # # # ## # #
# # #### # # #### # # #### # # #### #### #### ### #### # ## #### #
# #
#***************************************************************************************#
# #
# Name : Get-LocalUser #
# Date : 1/07/2013 #
# Author : Eric Fernandes #
# M@il : fernandes_eric*hotmail*fr #
# Subject : This Function will extract all local Users From Servers. #
# #
#********************************************************************#
Function Get-LocalUser
{
[CmdletBinding()]
param(
[parameter(Mandatory=$true,ValueFromPipeline=$False)]
[String]$Target,
[parameter(Mandatory=$true,ValueFromPipeline=$False)]
[String]$Source,
[parameter(Mandatory=$False,ValueFromPipeline=$False)]
[String]$List,
[parameter(Mandatory=$False,ValueFromPipeline=$False)]
[String]$Type
)
Begin
{
#Excel Object
$ObjExcel = New-Object -ComObject Excel.application
$ObjExcel.Workbooks.add()
$Objexcel.Worksheets.Item(1).Name = 'LocalUsers'
if($PSCulture -eq 'fr-FR')
{
$S2 = $objexcel.sheets | where {$_.name -eq \"Feuil2\"}
$S3 = $objexcel.sheets | where {$_.name -eq \"Feuil3\"}
}
else
{
$S2 = $objexcel.sheets | where {$_.name -eq \"Sheet2\"}
$S3 = $objexcel.sheets | where {$_.name -eq \"Sheet3\"}
}
$S3.delete()
$S2.delete()
$Servers = get-content $Target
$NbrTabSrv = $Servers | measure
$NbrTabSrv = $NbrTabSrv.count
$Compteur = 1
foreach($Server in $Servers)
{
if($Compteur -eq $NbrTabSrv)
{
$TabServer += $Server
}
else
{
$TabServer += \"$Server,\"
}
$Compteur++
}
#$Script:FileName = \"$File.xlsx\"
$Ligne = 2
$ObjExcel.Cells.Item($Ligne,4) = \"GET-LOCALUSER\"
$ObjExcel.Cells.Item($Ligne,4).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,4).Font.size = 20
$ObjExcel.Cells.Item($Ligne,4).Font.color = 15123099
$Ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Scan on Server(s) :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2) = $TabServer
#$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne+= 2
$ObjExcel.Cells.Item($Ligne,1) = \"Server\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,2) = \"UserName\"
$ObjExcel.Cells.Item($Ligne,2).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,3) = \"Groups\"
$ObjExcel.Cells.Item($Ligne,3).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,3).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,4) = \"AccountType\"
$ObjExcel.Cells.Item($Ligne,4).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,4).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,5) = \"PswdExpires\"
$ObjExcel.Cells.Item($Ligne,5).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,6) = \"AcctDisabled\"
$ObjExcel.Cells.Item($Ligne,6).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,7) = \"PswdLastSetTimeInDay\"
$ObjExcel.Cells.Item($Ligne,7).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,7).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,8) = \"Remote Control\"
$ObjExcel.Cells.Item($Ligne,8).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 15
$Ligne++
$Date= Get-Date -Format 'yyyyMMdd'
#Test if all servers are reachable
$ping = new-object System.Net.NetworkInformation.Ping
foreach($element in $Servers)
{
$Reply = $(try{$ping.Send($element)}catch{$null})
if($Reply -ne $null)
{
if($Reply.status –eq “Success”)
{
#If servers are reachable
[String[]]$ServersOK += $element
}
else
{
#If servers are not reachable
$ObjExcel.Cells.Item($Ligne,1) = \"$Element was not reachable !\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 3
$Ligne++
}
}
else
{
#If servers are not reachable
$ObjExcel.Cells.Item($Ligne,1) = \"$Element was not reachable !\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 3
$Ligne++
}
}
#Number of server where the ping worked
$NbrSrv = $ServersOK | measure
$NbrSrv = $NbrSrv.count
#Name of the Excel File
if($List -ne '')
{
$File = \"$Source\LocalUser-$Type-$List-$Date\"
}
elseif($NbrSrv -eq '1')
{
$File = \"$Source\LocalUser-$ServersOK-$Date\"
}
elseif($NbrSrv -eq '0')
{
$File = \"$Source\LocalUser-NoServer-$Date\"
}
else
{
$File = \"$Source\LocalUser-List-$Date\"
}
$Cpt=1
}
Process
{
foreach($Element in $ServersOK) #Scan of each reachable servers
{
Write-Progress -Activity \"Get-LocalUser\" -status \"Server $Cpt/$NbrSrv\" -percentComplete ($Cpt/$NbrSrv*100) -Id 1
$adsi = [ADSI]\"WinNT://$Element\"
$User = $adsi.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {
$groups = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember(\"Name\", 'GetProperty', $null, $_, $null)}
$_ | Select-Object @{n='UserName';e={$_.Name}},@{n='Groups';e={$groups -join ';'}},@{n='AccountType';e={$_.SchemaClassName}},@{n='PwdExpires';e={-not (($_.UserFlags.Item(0) -band 64) -or ($_.UserFlags.Item(0) -band 65536))}},@{n='AccDisabled';e={$_.accountdisabled}},@{n='PwdLastSetTime';e={($_.PasswordAge.value/86400)}},@{n='RemoteControl';e={$_.EnableRemoteControl}}
}
$Cpt2 = 1
$y = $User | measure
$y = $y.Count
for($i=0 ;$i -lt $y;$i++) #Extraction of data for each user
{
Write-Progress -Activity \"Get-LocalUser\" -status \"Account $Cpt2/$y\" -percentComplete ($Cpt2/$y*100) -Id 2
$Name = $User[$i].UserName
$Groups = $User[$i].Groups
$AccountType = $User[$i].AccountType
$PwdExpires = $User[$i].PwdExpires
$AccDisabled = $User[$i].AccDisabled
$PwdLastSetTime = $User[$i].PwdLastSetTime
$PwdLastSetTime = [math]::round($PwdLastSetTime,0)
$RemoteControl = $User[$i].RemoteControl
$ObjExcel.Cells.Item($Ligne,1) = $Element
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 46
$ObjExcel.Cells.Item($Ligne,2) = $Name
$ObjExcel.Cells.Item($Ligne,2).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,3) = $Groups
$ObjExcel.Cells.Item($Ligne,3).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,4) = $AccountType
$ObjExcel.Cells.Item($Ligne,4).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,5) = $PwdExpires
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,6) = $AccDisabled
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,7) = $PwdLastSetTime
$ObjExcel.Cells.Item($Ligne,7).Interior.ColorIndex = 35
if($PwdExpires -eq 'True')
{
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 10
}
else
{
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 3
}
if($AccDisabled -eq 'False')
{
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 3
}
else
{
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 10
}
if($RemoteControl -eq '1')
{
$ObjExcel.Cells.Item($Ligne,8) = 'Activated'
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 35
}
elseif($RemoteControl -eq '0')
{
$ObjExcel.Cells.Item($Ligne,8) = 'Not Activated'
$ObjExcel.Cells.Item($Ligne,8).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 3
}
else
{
$ObjExcel.Cells.Item($Ligne,8) = ''
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 35
}
$Ligne++
$Cpt2++
}
$Ligne++
$Cpt++
}
}
End
{
$Ligne -= 2
$Range = $ObjExcel.Range(\"A6\",\"H$Ligne\")
$ligne += 2
$ObjExcel.Cells.Item($Ligne,7) = \"#Export made by PoWerShellDoNe\"
$ObjExcel.Cells.Item($Ligne,7).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,7).Font.size = 14
$ObjExcel.Cells.Item($Ligne,7).Font.color = 15123099
$Ligne ++
$ObjExcel.Cells.Item($Ligne,1) = \"APPS Manager review and approval\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
$ObjExcel.Cells.Item($Ligne,1) = \"OPS Manager review and approval\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
#End of Excel object
$Range.Borders.Weight = 2
$range.HorizontalAlignment = 3
$ObjExcel.Columns.autofit()
$ObjExcel.ActiveWorkbook._SaveAs($File)
$ObjExcel.WorkBooks.close()
$ObjExcel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel)
}
}
Get-LocalUser -Target c:\users\TonCompte\Desktop\ListeDesServeursAScanner.txt -Source c:\users\TonCompte\Desktop
Je suis très loing d'être un expert mais bonne chance à toi.
a+
Pour le partage voila la fonction Get-LocalUser :
Il te faudra PS V3 et excel d'installé sur ta machine.
Si tu lance le script sur windows 7 il te manquera les infos de la colonne Remote controle. Par contre si tu lance le script à partir de Server 2008 tu auras le rapport excel complet.
#***************************************************************************************#
# #
# #### #### # # #### #### #### # # #### # # ### #### ## # #### #
# # # # # # # # # # # # # # # # # # # # # # # # # #
# #### # # # # # ### #### #### #### ### # # # # # # # # # ### #
# # # # # # # # # # # # # # # # # # # # # ## # #
# # #### # # #### # # #### # # #### #### #### ### #### # ## #### #
# #
#***************************************************************************************#
# #
# Name : Get-LocalUser #
# Date : 1/07/2013 #
# Author : Eric Fernandes #
# M@il : fernandes_eric*hotmail*fr #
# Subject : This Function will extract all local Users From Servers. #
# #
#********************************************************************#
Function Get-LocalUser
{
[CmdletBinding()]
param(
[parameter(Mandatory=$true,ValueFromPipeline=$False)]
[String]$Target,
[parameter(Mandatory=$true,ValueFromPipeline=$False)]
[String]$Source,
[parameter(Mandatory=$False,ValueFromPipeline=$False)]
[String]$List,
[parameter(Mandatory=$False,ValueFromPipeline=$False)]
[String]$Type
)
Begin
{
#Excel Object
$ObjExcel = New-Object -ComObject Excel.application
$ObjExcel.Workbooks.add()
$Objexcel.Worksheets.Item(1).Name = 'LocalUsers'
if($PSCulture -eq 'fr-FR')
{
$S2 = $objexcel.sheets | where {$_.name -eq \"Feuil2\"}
$S3 = $objexcel.sheets | where {$_.name -eq \"Feuil3\"}
}
else
{
$S2 = $objexcel.sheets | where {$_.name -eq \"Sheet2\"}
$S3 = $objexcel.sheets | where {$_.name -eq \"Sheet3\"}
}
$S3.delete()
$S2.delete()
$Servers = get-content $Target
$NbrTabSrv = $Servers | measure
$NbrTabSrv = $NbrTabSrv.count
$Compteur = 1
foreach($Server in $Servers)
{
if($Compteur -eq $NbrTabSrv)
{
$TabServer += $Server
}
else
{
$TabServer += \"$Server,\"
}
$Compteur++
}
#$Script:FileName = \"$File.xlsx\"
$Ligne = 2
$ObjExcel.Cells.Item($Ligne,4) = \"GET-LOCALUSER\"
$ObjExcel.Cells.Item($Ligne,4).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,4).Font.size = 20
$ObjExcel.Cells.Item($Ligne,4).Font.color = 15123099
$Ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Scan on Server(s) :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2) = $TabServer
#$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne+= 2
$ObjExcel.Cells.Item($Ligne,1) = \"Server\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,2) = \"UserName\"
$ObjExcel.Cells.Item($Ligne,2).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,3) = \"Groups\"
$ObjExcel.Cells.Item($Ligne,3).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,3).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,4) = \"AccountType\"
$ObjExcel.Cells.Item($Ligne,4).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,4).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,5) = \"PswdExpires\"
$ObjExcel.Cells.Item($Ligne,5).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,6) = \"AcctDisabled\"
$ObjExcel.Cells.Item($Ligne,6).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,7) = \"PswdLastSetTimeInDay\"
$ObjExcel.Cells.Item($Ligne,7).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,7).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,8) = \"Remote Control\"
$ObjExcel.Cells.Item($Ligne,8).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 15
$Ligne++
$Date= Get-Date -Format 'yyyyMMdd'
#Test if all servers are reachable
$ping = new-object System.Net.NetworkInformation.Ping
foreach($element in $Servers)
{
$Reply = $(try{$ping.Send($element)}catch{$null})
if($Reply -ne $null)
{
if($Reply.status –eq “Success”)
{
#If servers are reachable
[String[]]$ServersOK += $element
}
else
{
#If servers are not reachable
$ObjExcel.Cells.Item($Ligne,1) = \"$Element was not reachable !\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 3
$Ligne++
}
}
else
{
#If servers are not reachable
$ObjExcel.Cells.Item($Ligne,1) = \"$Element was not reachable !\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 3
$Ligne++
}
}
#Number of server where the ping worked
$NbrSrv = $ServersOK | measure
$NbrSrv = $NbrSrv.count
#Name of the Excel File
if($List -ne '')
{
$File = \"$Source\LocalUser-$Type-$List-$Date\"
}
elseif($NbrSrv -eq '1')
{
$File = \"$Source\LocalUser-$ServersOK-$Date\"
}
elseif($NbrSrv -eq '0')
{
$File = \"$Source\LocalUser-NoServer-$Date\"
}
else
{
$File = \"$Source\LocalUser-List-$Date\"
}
$Cpt=1
}
Process
{
foreach($Element in $ServersOK) #Scan of each reachable servers
{
Write-Progress -Activity \"Get-LocalUser\" -status \"Server $Cpt/$NbrSrv\" -percentComplete ($Cpt/$NbrSrv*100) -Id 1
$adsi = [ADSI]\"WinNT://$Element\"
$User = $adsi.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {
$groups = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember(\"Name\", 'GetProperty', $null, $_, $null)}
$_ | Select-Object @{n='UserName';e={$_.Name}},@{n='Groups';e={$groups -join ';'}},@{n='AccountType';e={$_.SchemaClassName}},@{n='PwdExpires';e={-not (($_.UserFlags.Item(0) -band 64) -or ($_.UserFlags.Item(0) -band 65536))}},@{n='AccDisabled';e={$_.accountdisabled}},@{n='PwdLastSetTime';e={($_.PasswordAge.value/86400)}},@{n='RemoteControl';e={$_.EnableRemoteControl}}
}
$Cpt2 = 1
$y = $User | measure
$y = $y.Count
for($i=0 ;$i -lt $y;$i++) #Extraction of data for each user
{
Write-Progress -Activity \"Get-LocalUser\" -status \"Account $Cpt2/$y\" -percentComplete ($Cpt2/$y*100) -Id 2
$Name = $User[$i].UserName
$Groups = $User[$i].Groups
$AccountType = $User[$i].AccountType
$PwdExpires = $User[$i].PwdExpires
$AccDisabled = $User[$i].AccDisabled
$PwdLastSetTime = $User[$i].PwdLastSetTime
$PwdLastSetTime = [math]::round($PwdLastSetTime,0)
$RemoteControl = $User[$i].RemoteControl
$ObjExcel.Cells.Item($Ligne,1) = $Element
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 46
$ObjExcel.Cells.Item($Ligne,2) = $Name
$ObjExcel.Cells.Item($Ligne,2).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,3) = $Groups
$ObjExcel.Cells.Item($Ligne,3).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,4) = $AccountType
$ObjExcel.Cells.Item($Ligne,4).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,5) = $PwdExpires
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,6) = $AccDisabled
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,7) = $PwdLastSetTime
$ObjExcel.Cells.Item($Ligne,7).Interior.ColorIndex = 35
if($PwdExpires -eq 'True')
{
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 10
}
else
{
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 3
}
if($AccDisabled -eq 'False')
{
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 3
}
else
{
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 10
}
if($RemoteControl -eq '1')
{
$ObjExcel.Cells.Item($Ligne,8) = 'Activated'
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 35
}
elseif($RemoteControl -eq '0')
{
$ObjExcel.Cells.Item($Ligne,8) = 'Not Activated'
$ObjExcel.Cells.Item($Ligne,8).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 3
}
else
{
$ObjExcel.Cells.Item($Ligne,8) = ''
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 35
}
$Ligne++
$Cpt2++
}
$Ligne++
$Cpt++
}
}
End
{
$Ligne -= 2
$Range = $ObjExcel.Range(\"A6\",\"H$Ligne\")
$ligne += 2
$ObjExcel.Cells.Item($Ligne,7) = \"#Export made by PoWerShellDoNe\"
$ObjExcel.Cells.Item($Ligne,7).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,7).Font.size = 14
$ObjExcel.Cells.Item($Ligne,7).Font.color = 15123099
$Ligne ++
$ObjExcel.Cells.Item($Ligne,1) = \"APPS Manager review and approval\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
$ObjExcel.Cells.Item($Ligne,1) = \"OPS Manager review and approval\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
#End of Excel object
$Range.Borders.Weight = 2
$range.HorizontalAlignment = 3
$ObjExcel.Columns.autofit()
$ObjExcel.ActiveWorkbook._SaveAs($File)
$ObjExcel.WorkBooks.close()
$ObjExcel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel)
}
}
Get-LocalUser -Target c:\users\TonCompte\Desktop\ListeDesServeursAScanner.txt -Source c:\users\TonCompte\Desktop
Je suis très loing d'être un expert mais bonne chance à toi.
a+
Connexion ou Créer un compte pour participer à la conversation.
- Eric
- Auteur du sujet
- Hors Ligne
- Membre junior
Réduire
Plus d'informations
- Messages : 20
- Remerciements reçus 0
il y a 9 ans 10 mois #17582
par Eric
Réponse de Eric sur le sujet Re:Fonction d'audite en Powershell
Oups !!! manque les AntiSlash...
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
Réduire
Plus d'informations
- Messages : 6302
- Remerciements reçus 68
il y a 9 ans 10 mois #17584
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Fonction d'audite en Powershell
salut,
Fernandes écrit:
Fernandes écrit:
Ajoute les balises code<br><br>Message édité par: Laurent Dardenne, à: 6/06/14 10:58Oups !!! manque les AntiSlash...
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- Eric
- Auteur du sujet
- Hors Ligne
- Membre junior
Réduire
Plus d'informations
- Messages : 20
- Remerciements reçus 0
il y a 9 ans 10 mois #17588
par Eric
Réponse de Eric sur le sujet Re:Fonction d'audite en Powershell
[code:1]
#***************************************************************************************#
# #
# #### #### # # #### #### #### # # #### # # ### #### ## # #### #
# # # # # # # # # # # # # # # # # # # # # # # # # #
# #### # # # # # ### #### #### #### ### # # # # # # # # # ### #
# # # # # # # # # # # # # # # # # # # # # ## # #
# # #### # # #### # # #### # # #### #### #### ### #### # ## #### #
# #
#***************************************************************************************#
# #
# Name : Get-LocalUser #
# Date : 1/07/2013 #
# Author : Eric Fernandes #
# M@il : fernandes_eric*hotmail*fr #
# Subject : This Function will extract all local Users From Servers. #
# #
#********************************************************************#
Function Get-LocalUser
{
[CmdletBinding()]
param(
[parameter(Mandatory=$true,ValueFromPipeline=$False)]
[String]$Target,
[parameter(Mandatory=$true,ValueFromPipeline=$False)]
[String]$Source,
[parameter(Mandatory=$False,ValueFromPipeline=$False)]
[String]$List,
[parameter(Mandatory=$False,ValueFromPipeline=$False)]
[String]$Type
)
Begin
{
#Excel Object
$ObjExcel = New-Object -ComObject Excel.application
$ObjExcel.Workbooks.add()
$Objexcel.Worksheets.Item(1).Name = 'LocalUsers'
if($PSCulture -eq 'fr-FR')
{
$S2 = $objexcel.sheets | where {$_.name -eq \"Feuil2\"}
$S3 = $objexcel.sheets | where {$_.name -eq \"Feuil3\"}
}
else
{
$S2 = $objexcel.sheets | where {$_.name -eq \"Sheet2\"}
$S3 = $objexcel.sheets | where {$_.name -eq \"Sheet3\"}
}
$S3.delete()
$S2.delete()
$Servers = get-content $Target
$NbrTabSrv = $Servers | measure
$NbrTabSrv = $NbrTabSrv.count
$Compteur = 1
foreach($Server in $Servers)
{
if($Compteur -eq $NbrTabSrv)
{
$TabServer += $Server
}
else
{
$TabServer += \"$Server,\"
}
$Compteur++
}
#$Script:FileName = \"$File.xlsx\"
$Ligne = 2
$ObjExcel.Cells.Item($Ligne,4) = \"GET-LOCALUSER\"
$ObjExcel.Cells.Item($Ligne,4).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,4).Font.size = 20
$ObjExcel.Cells.Item($Ligne,4).Font.color = 15123099
$Ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Scan on Server(s) :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2) = $TabServer
#$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne+= 2
$ObjExcel.Cells.Item($Ligne,1) = \"Server\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,2) = \"UserName\"
$ObjExcel.Cells.Item($Ligne,2).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,3) = \"Groups\"
$ObjExcel.Cells.Item($Ligne,3).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,3).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,4) = \"AccountType\"
$ObjExcel.Cells.Item($Ligne,4).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,4).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,5) = \"PswdExpires\"
$ObjExcel.Cells.Item($Ligne,5).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,6) = \"AcctDisabled\"
$ObjExcel.Cells.Item($Ligne,6).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,7) = \"PswdLastSetTimeInDay\"
$ObjExcel.Cells.Item($Ligne,7).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,7).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,8) = \"Remote Control\"
$ObjExcel.Cells.Item($Ligne,8).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 15
$Ligne++
$Date= Get-Date -Format 'yyyyMMdd'
#Test if all servers are reachable
$ping = new-object System.Net.NetworkInformation.Ping
foreach($element in $Servers)
{
$Reply = $(try{$ping.Send($element)}catch{$null})
if($Reply -ne $null)
{
if($Reply.status –eq “Success”)
{
#If servers are reachable
[String[]]$ServersOK += $element
}
else
{
#If servers are not reachable
$ObjExcel.Cells.Item($Ligne,1) = \"$Element was not reachable !\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 3
$Ligne++
}
}
else
{
#If servers are not reachable
$ObjExcel.Cells.Item($Ligne,1) = \"$Element was not reachable !\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 3
$Ligne++
}
}
#Number of server where the ping worked
$NbrSrv = $ServersOK | measure
$NbrSrv = $NbrSrv.count
#Name of the Excel File
if($List -ne '')
{
$File = \"$Source\LocalUser-$Type-$List-$Date\"
}
elseif($NbrSrv -eq '1')
{
$File = \"$Source\LocalUser-$ServersOK-$Date\"
}
elseif($NbrSrv -eq '0')
{
$File = \"$Source\LocalUser-NoServer-$Date\"
}
else
{
$File = \"$Source\LocalUser-List-$Date\"
}
$Cpt=1
}
Process
{
foreach($Element in $ServersOK) #Scan of each reachable servers
{
Write-Progress -Activity \"Get-LocalUser\" -status \"Server $Cpt/$NbrSrv\" -percentComplete ($Cpt/$NbrSrv*100) -Id 1
$adsi = [ADSI]\"WinNT://$Element\"
$User = $adsi.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {
$groups = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember(\"Name\", 'GetProperty', $null, $_, $null)}
$_ | Select-Object @{n='UserName';e={$_.Name}},@{n='Groups';e={$groups -join ';'}},@{n='AccountType';e={$_.SchemaClassName}},@{n='PwdExpires';e={-not (($_.UserFlags.Item(0) -band 64) -or ($_.UserFlags.Item(0) -band 65536))}},@{n='AccDisabled';e={$_.accountdisabled}},@{n='PwdLastSetTime';e={($_.PasswordAge.value/86400)}},@{n='RemoteControl';e={$_.EnableRemoteControl}}
}
$Cpt2 = 1
$y = $User | measure
$y = $y.Count
for($i=0 ;$i -lt $y;$i++) #Extraction of data for each user
{
Write-Progress -Activity \"Get-LocalUser\" -status \"Account $Cpt2/$y\" -percentComplete ($Cpt2/$y*100) -Id 2
$Name = $User[$i].UserName
$Groups = $User[$i].Groups
$AccountType = $User[$i].AccountType
$PwdExpires = $User[$i].PwdExpires
$AccDisabled = $User[$i].AccDisabled
$PwdLastSetTime = $User[$i].PwdLastSetTime
$PwdLastSetTime = [math]::round($PwdLastSetTime,0)
$RemoteControl = $User[$i].RemoteControl
$ObjExcel.Cells.Item($Ligne,1) = $Element
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 46
$ObjExcel.Cells.Item($Ligne,2) = $Name
$ObjExcel.Cells.Item($Ligne,2).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,3) = $Groups
$ObjExcel.Cells.Item($Ligne,3).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,4) = $AccountType
$ObjExcel.Cells.Item($Ligne,4).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,5) = $PwdExpires
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,6) = $AccDisabled
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,7) = $PwdLastSetTime
$ObjExcel.Cells.Item($Ligne,7).Interior.ColorIndex = 35
if($PwdExpires -eq 'True')
{
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 10
}
else
{
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 3
}
if($AccDisabled -eq 'False')
{
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 3
}
else
{
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 10
}
if($RemoteControl -eq '1')
{
$ObjExcel.Cells.Item($Ligne,8) = 'Activated'
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 35
}
elseif($RemoteControl -eq '0')
{
$ObjExcel.Cells.Item($Ligne,8) = 'Not Activated'
$ObjExcel.Cells.Item($Ligne,8).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 3
}
else
{
$ObjExcel.Cells.Item($Ligne,8) = ''
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 35
}
$Ligne++
$Cpt2++
}
$Ligne++
$Cpt++
}
}
End
{
$Ligne -= 2
$Range = $ObjExcel.Range(\"A6\",\"H$Ligne\"«»)
$ligne += 2
$ObjExcel.Cells.Item($Ligne,7) = \"#Export made by PoWerShellDoNe\"
$ObjExcel.Cells.Item($Ligne,7).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,7).Font.size = 14
$ObjExcel.Cells.Item($Ligne,7).Font.color = 15123099
$Ligne ++
$ObjExcel.Cells.Item($Ligne,1) = \"APPS Manager review and approval\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
$ObjExcel.Cells.Item($Ligne,1) = \"OPS Manager review and approval\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
#End of Excel object
$Range.Borders.Weight = 2
$range.HorizontalAlignment = 3
$ObjExcel.Columns.autofit()
$ObjExcel.ActiveWorkbook._SaveAs($File)
$ObjExcel.WorkBooks.close()
$ObjExcel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel)
}
}
Get-LocalUser -Target C:\Users\TonCompte\Desktop\ListeDesServeursAScanner.txt -Source C:\Users\TonCompte\Desktop
[/code:1]
Voila,
#***************************************************************************************#
# #
# #### #### # # #### #### #### # # #### # # ### #### ## # #### #
# # # # # # # # # # # # # # # # # # # # # # # # # #
# #### # # # # # ### #### #### #### ### # # # # # # # # # ### #
# # # # # # # # # # # # # # # # # # # # # ## # #
# # #### # # #### # # #### # # #### #### #### ### #### # ## #### #
# #
#***************************************************************************************#
# #
# Name : Get-LocalUser #
# Date : 1/07/2013 #
# Author : Eric Fernandes #
# M@il : fernandes_eric*hotmail*fr #
# Subject : This Function will extract all local Users From Servers. #
# #
#********************************************************************#
Function Get-LocalUser
{
[CmdletBinding()]
param(
[parameter(Mandatory=$true,ValueFromPipeline=$False)]
[String]$Target,
[parameter(Mandatory=$true,ValueFromPipeline=$False)]
[String]$Source,
[parameter(Mandatory=$False,ValueFromPipeline=$False)]
[String]$List,
[parameter(Mandatory=$False,ValueFromPipeline=$False)]
[String]$Type
)
Begin
{
#Excel Object
$ObjExcel = New-Object -ComObject Excel.application
$ObjExcel.Workbooks.add()
$Objexcel.Worksheets.Item(1).Name = 'LocalUsers'
if($PSCulture -eq 'fr-FR')
{
$S2 = $objexcel.sheets | where {$_.name -eq \"Feuil2\"}
$S3 = $objexcel.sheets | where {$_.name -eq \"Feuil3\"}
}
else
{
$S2 = $objexcel.sheets | where {$_.name -eq \"Sheet2\"}
$S3 = $objexcel.sheets | where {$_.name -eq \"Sheet3\"}
}
$S3.delete()
$S2.delete()
$Servers = get-content $Target
$NbrTabSrv = $Servers | measure
$NbrTabSrv = $NbrTabSrv.count
$Compteur = 1
foreach($Server in $Servers)
{
if($Compteur -eq $NbrTabSrv)
{
$TabServer += $Server
}
else
{
$TabServer += \"$Server,\"
}
$Compteur++
}
#$Script:FileName = \"$File.xlsx\"
$Ligne = 2
$ObjExcel.Cells.Item($Ligne,4) = \"GET-LOCALUSER\"
$ObjExcel.Cells.Item($Ligne,4).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,4).Font.size = 20
$ObjExcel.Cells.Item($Ligne,4).Font.color = 15123099
$Ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Scan on Server(s) :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2) = $TabServer
#$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne+= 2
$ObjExcel.Cells.Item($Ligne,1) = \"Server\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,2) = \"UserName\"
$ObjExcel.Cells.Item($Ligne,2).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,3) = \"Groups\"
$ObjExcel.Cells.Item($Ligne,3).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,3).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,4) = \"AccountType\"
$ObjExcel.Cells.Item($Ligne,4).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,4).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,5) = \"PswdExpires\"
$ObjExcel.Cells.Item($Ligne,5).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,6) = \"AcctDisabled\"
$ObjExcel.Cells.Item($Ligne,6).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,7) = \"PswdLastSetTimeInDay\"
$ObjExcel.Cells.Item($Ligne,7).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,7).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,8) = \"Remote Control\"
$ObjExcel.Cells.Item($Ligne,8).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 15
$Ligne++
$Date= Get-Date -Format 'yyyyMMdd'
#Test if all servers are reachable
$ping = new-object System.Net.NetworkInformation.Ping
foreach($element in $Servers)
{
$Reply = $(try{$ping.Send($element)}catch{$null})
if($Reply -ne $null)
{
if($Reply.status –eq “Success”)
{
#If servers are reachable
[String[]]$ServersOK += $element
}
else
{
#If servers are not reachable
$ObjExcel.Cells.Item($Ligne,1) = \"$Element was not reachable !\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 3
$Ligne++
}
}
else
{
#If servers are not reachable
$ObjExcel.Cells.Item($Ligne,1) = \"$Element was not reachable !\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 3
$Ligne++
}
}
#Number of server where the ping worked
$NbrSrv = $ServersOK | measure
$NbrSrv = $NbrSrv.count
#Name of the Excel File
if($List -ne '')
{
$File = \"$Source\LocalUser-$Type-$List-$Date\"
}
elseif($NbrSrv -eq '1')
{
$File = \"$Source\LocalUser-$ServersOK-$Date\"
}
elseif($NbrSrv -eq '0')
{
$File = \"$Source\LocalUser-NoServer-$Date\"
}
else
{
$File = \"$Source\LocalUser-List-$Date\"
}
$Cpt=1
}
Process
{
foreach($Element in $ServersOK) #Scan of each reachable servers
{
Write-Progress -Activity \"Get-LocalUser\" -status \"Server $Cpt/$NbrSrv\" -percentComplete ($Cpt/$NbrSrv*100) -Id 1
$adsi = [ADSI]\"WinNT://$Element\"
$User = $adsi.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {
$groups = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember(\"Name\", 'GetProperty', $null, $_, $null)}
$_ | Select-Object @{n='UserName';e={$_.Name}},@{n='Groups';e={$groups -join ';'}},@{n='AccountType';e={$_.SchemaClassName}},@{n='PwdExpires';e={-not (($_.UserFlags.Item(0) -band 64) -or ($_.UserFlags.Item(0) -band 65536))}},@{n='AccDisabled';e={$_.accountdisabled}},@{n='PwdLastSetTime';e={($_.PasswordAge.value/86400)}},@{n='RemoteControl';e={$_.EnableRemoteControl}}
}
$Cpt2 = 1
$y = $User | measure
$y = $y.Count
for($i=0 ;$i -lt $y;$i++) #Extraction of data for each user
{
Write-Progress -Activity \"Get-LocalUser\" -status \"Account $Cpt2/$y\" -percentComplete ($Cpt2/$y*100) -Id 2
$Name = $User[$i].UserName
$Groups = $User[$i].Groups
$AccountType = $User[$i].AccountType
$PwdExpires = $User[$i].PwdExpires
$AccDisabled = $User[$i].AccDisabled
$PwdLastSetTime = $User[$i].PwdLastSetTime
$PwdLastSetTime = [math]::round($PwdLastSetTime,0)
$RemoteControl = $User[$i].RemoteControl
$ObjExcel.Cells.Item($Ligne,1) = $Element
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 46
$ObjExcel.Cells.Item($Ligne,2) = $Name
$ObjExcel.Cells.Item($Ligne,2).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,3) = $Groups
$ObjExcel.Cells.Item($Ligne,3).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,4) = $AccountType
$ObjExcel.Cells.Item($Ligne,4).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,5) = $PwdExpires
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,6) = $AccDisabled
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 35
$ObjExcel.Cells.Item($Ligne,7) = $PwdLastSetTime
$ObjExcel.Cells.Item($Ligne,7).Interior.ColorIndex = 35
if($PwdExpires -eq 'True')
{
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 10
}
else
{
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 3
}
if($AccDisabled -eq 'False')
{
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 3
}
else
{
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 10
}
if($RemoteControl -eq '1')
{
$ObjExcel.Cells.Item($Ligne,8) = 'Activated'
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 35
}
elseif($RemoteControl -eq '0')
{
$ObjExcel.Cells.Item($Ligne,8) = 'Not Activated'
$ObjExcel.Cells.Item($Ligne,8).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 3
}
else
{
$ObjExcel.Cells.Item($Ligne,8) = ''
$ObjExcel.Cells.Item($Ligne,8).Interior.ColorIndex = 35
}
$Ligne++
$Cpt2++
}
$Ligne++
$Cpt++
}
}
End
{
$Ligne -= 2
$Range = $ObjExcel.Range(\"A6\",\"H$Ligne\"«»)
$ligne += 2
$ObjExcel.Cells.Item($Ligne,7) = \"#Export made by PoWerShellDoNe\"
$ObjExcel.Cells.Item($Ligne,7).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,7).Font.size = 14
$ObjExcel.Cells.Item($Ligne,7).Font.color = 15123099
$Ligne ++
$ObjExcel.Cells.Item($Ligne,1) = \"APPS Manager review and approval\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
$ObjExcel.Cells.Item($Ligne,1) = \"OPS Manager review and approval\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \"Name :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Date :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \"Signature :\"
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
#End of Excel object
$Range.Borders.Weight = 2
$range.HorizontalAlignment = 3
$ObjExcel.Columns.autofit()
$ObjExcel.ActiveWorkbook._SaveAs($File)
$ObjExcel.WorkBooks.close()
$ObjExcel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel)
}
}
Get-LocalUser -Target C:\Users\TonCompte\Desktop\ListeDesServeursAScanner.txt -Source C:\Users\TonCompte\Desktop
[/code:1]
Voila,
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.082 secondes
- Vous êtes ici :
- Accueil
- forum
- PowerShell
- Discussions générales
- Fonction d'audite en Powershell