Question Fonction d'audite en Powershell

Plus d'informations
il y a 9 ans 10 mois #17571 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.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 9 ans 10 mois #17579 par Nicolas Guerin
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.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
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+

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
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.

Plus d'informations
il y a 9 ans 10 mois #17584 par Laurent Dardenne
salut,
Fernandes écrit:

Oups !!! manque les AntiSlash...

Ajoute les balises code<br><br>Message édité par: Laurent Dardenne, à: 6/06/14 10:58

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
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 \&quot;Feuil2\&quot;}
$S3 = $objexcel.sheets | where {$_.name -eq \&quot;Feuil3\&quot;}
}
else
{
$S2 = $objexcel.sheets | where {$_.name -eq \&quot;Sheet2\&quot;}
$S3 = $objexcel.sheets | where {$_.name -eq \&quot;Sheet3\&quot;}
}
$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 += \&quot;$Server,\&quot;
}
$Compteur++
}

#$Script:FileName = \&quot;$File.xlsx\&quot;
$Ligne = 2

$ObjExcel.Cells.Item($Ligne,4) = \&quot;GET-LOCALUSER\&quot;
$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) = \&quot;Scan on Server(s) :\&quot;
$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) = \&quot;Server\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,1).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,2) = \&quot;UserName\&quot;
$ObjExcel.Cells.Item($Ligne,2).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,2).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,3) = \&quot;Groups\&quot;
$ObjExcel.Cells.Item($Ligne,3).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,3).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,4) = \&quot;AccountType\&quot;
$ObjExcel.Cells.Item($Ligne,4).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,4).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,5) = \&quot;PswdExpires\&quot;
$ObjExcel.Cells.Item($Ligne,5).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,5).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,6) = \&quot;AcctDisabled\&quot;
$ObjExcel.Cells.Item($Ligne,6).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,6).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,7) = \&quot;PswdLastSetTimeInDay\&quot;
$ObjExcel.Cells.Item($Ligne,7).Font.Bold = $True
$ObjExcel.Cells.Item($Ligne,7).Interior.ColorIndex = 15
$ObjExcel.Cells.Item($Ligne,8) = \&quot;Remote Control\&quot;
$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) = \&quot;$Element was not reachable !\&quot;
$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) = \&quot;$Element was not reachable !\&quot;
$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 = \&quot;$Source\LocalUser-$Type-$List-$Date\&quot;
}
elseif($NbrSrv -eq '1')
{
$File = \&quot;$Source\LocalUser-$ServersOK-$Date\&quot;
}
elseif($NbrSrv -eq '0')
{
$File = \&quot;$Source\LocalUser-NoServer-$Date\&quot;
}
else
{
$File = \&quot;$Source\LocalUser-List-$Date\&quot;
}

$Cpt=1
}

Process
{
foreach($Element in $ServersOK) #Scan of each reachable servers
{
Write-Progress -Activity \&quot;Get-LocalUser\&quot; -status \&quot;Server $Cpt/$NbrSrv\&quot; -percentComplete ($Cpt/$NbrSrv*100) -Id 1

$adsi = [ADSI]\&quot;WinNT://$Element\&quot;
$User = $adsi.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {
$groups = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember(\&quot;Name\&quot;, '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 \&quot;Get-LocalUser\&quot; -status \&quot;Account $Cpt2/$y\&quot; -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(\&quot;A6\&quot;,\&quot;H$Ligne\&quot;«»)
$ligne += 2
$ObjExcel.Cells.Item($Ligne,7) = \&quot;#Export made by PoWerShellDoNe\&quot;
$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) = \&quot;APPS Manager review and approval\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \&quot;Name :\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \&quot;Date :\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \&quot;Signature :\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
$ObjExcel.Cells.Item($Ligne,1) = \&quot;Name :\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \&quot;Date :\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \&quot;Signature :\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 3
$ObjExcel.Cells.Item($Ligne,1) = \&quot;OPS Manager review and approval\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$ligne += 2
$ObjExcel.Cells.Item($Ligne,1) = \&quot;Name :\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \&quot;Date :\&quot;
$ObjExcel.Cells.Item($Ligne,1).Font.Bold = $True
$Ligne++
$ObjExcel.Cells.Item($Ligne,1) = \&quot;Signature :\&quot;
$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.079 secondes
Propulsé par Kunena