Question Get-Childitem ???

Plus d'informations
il y a 12 ans 10 mois #14859 par darphboubou
Get-Childitem ??? a été créé par darphboubou
Bonjour,

Voila j'aimerai obtenir les nom de répertoire jusqu'à la troisième sous arboraissance.

La commande Get-childitem -recurse ne me satisfait pas puisqu'elle me liste la totalité de l'arboraissance \"tant qu'il y a des sous répertoire\".

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

Plus d'informations
il y a 12 ans 10 mois #14860 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:Get-Childitem ???
Salut,
consultes les dernières pages de ce forum tu y trouveras une solution à ton pb. Regarde également dans la biblio de scripts.

Tutoriels PowerShell

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

Plus d'informations
il y a 12 ans 10 mois #14861 par darphboubou
Réponse de darphboubou sur le sujet Re:Get-Childitem ???
merci j'y cours

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

Plus d'informations
il y a 12 ans 10 mois #14863 par stas
Réponse de stas sur le sujet Re:Get-Childitem ???
hello voila ce que j'ai trouve sur le net.

je pense que cela peux t'aider.

[code:1]

#################################################################################
################################# Les variables #################################
#################################################################################

# on récupère la date du jour
$temps = Get-Date -UFormat %y%m%d%H%M%S

# on variabilise le chemin du repertoire d'execution du script
$courant = split-path $myinvocation.mycommand.path

# repertoire de logs
$RepLog = \"$courant\Logs\"

#################################################################################
################################# Import #####################################
#################################################################################

# importation du module de listage (Arnaud Petitjean - Powershell-scripting.com)
import-module $courant\Get-ChildItemToDepth.psm1



#################################################################################
################################# Fonctions #####################################
#################################################################################

################################# Paramatres ####################################

# Arborescence à tester
function Arbo ($FicLog)
{

# Quelle arborescence ?
$Global:Arbo = \"\"
# Format DFS (\\[domaine]\...) ou format lecteur connecté (Z:\)
$Global:Arbo = Read-host \"Quelle est l'arborescence à tester (Format \\[serveur]\... ou lecteur reseau connecté) ?\"

ControlArbo $Global:Arbo $FicLog

}

# Profondeur du test
Function Profondeur ($FicLog)
{
$Global:«»Profondeur = \"\"
# Profondeur de recherche : le nombre de niveaux maximum de sous repertoires
$ProfondBrut = Read-host \"Quelle est la limte de profondeur (Format numerique, Ex : 3 => on test l'arborescence sur la racine + 2 niveaux de sous repertoires) ?\"
$Global:«»Profondeur = $ProfondBrut - 1

ControlProfon $ProfondBrut $Global:«»Profondeur $FicLog

}

# On veut seulement les repertoires ou les repertoires ET les fichiers ?
Function DirFic($FicLog)
{
$Global:RepOuFic = \"\"
$Global:RepOuFic = Read-Host \"On liste seulement les repertoires(Rep) ou les Repertoires ET les fichiers(RepFic) ?\"
ContolDirFic $Global:RepOuFic $FicLog
}

# Quel type de fichier en sortie ?
Function FicSortie($FicLog)
{
$Global:NomSortie = \"\"
$Global:NomSortie = Read-Host \"Format de sortie, TXT ou CSV ?\"
ControlFicSortie $Global:NomSortie $FicLog
}



######################## Controle des parametres saisis #########################

# Controle Arbo
Function ControlArbo ($Arbo,$FicLog)
{
if(test-path $Arbo )
{
write-output \"Ok pour L'arbo a tester ($Arbo)\" >> $FicLog
}
Else
{
Write-host \"L'arbo a tester ($Arbo) n'existe pas\" -Foregroundcolor red
Write-output \"L'arbo a tester ($Arbo) n'existe pas\" >> $FicLog

Arbo $FicLog
}
}


# Controle Profondeur
Function ControlProfon ($ProfondBrut,$Profondeur,$FicLog)
{
$ColProf = 1,2,3,4,5,6,7,8,9

if ($ColProf -like $profondeur)
{
Write-Output \"Profondeur de la recherche : $ProfondBrut\" >> $FicLog
}
else
{
Write-Host \"Profondeur de la recherche incorrecte (1 à 9) : $ProfondBrut\" -Foregroundcolor red
Write-Output \"Profondeur de la recherche incorrecte : $ProfondBrut\" >> $FicLog

Profondeur $FicLog
}
}


# Type d'ojets à lister
Function ContolDirFic($RepOuFic,$FicLog)
{
if(($RepOuFic -eq \"Rep\"«») -or ($RepOuFic -eq \"RepFic\"«»))
{
Write-Output \"Type d'objet recherché : $RepOuFic\" >> $FicLog
}
else
{
Write-Host \"Type d'objet recherché n'est ni Rep ni RepFic : $RepOuFic\" -Foregroundcolor red
Write-Output \"Type d'objet recherché n'est ni Rep ni RepFic : $RepOuFic\" >> $FicLog

DirFic $FicLog
}
}


# type de fichier en sortie ?
Function ControlFicSortie($NomSortie,$FicLog)
{
if(($NomSortie -eq \"txt\"«») -or ($NomSortie -eq \"csv\"«»))
{
# Fichier de log
Write-Output \"Le fichier de sortie sera au format $NomSortie\" >> $FicLog
$FicSortie = ($RepLog+\"ListArbo-$temps.$NomSortie\"«»)
}
else
{
Write-Host \"Le fichier de sortie doit etre au format txt ou csv\" -Foregroundcolor red
Write-Output \"Le format du fichier de sortie est incorrect $NomSortie. Soit txt soit csv\" >> $FicLog

FicSortie $FicLog
}
}


################################## listage ######################################

# Choix du type de recherche
Function choix($RepOuFic,$Arbo,$profondeur,$NomSortie,$FicLog)
{
switch($RepOuFic)
{
\"Rep\" {ListRepRep $Arbo $profondeur $NomSortie}

\"RepFic\" {ListRepRepFic $Arbo $profondeur $NomSortie}
}

}




# Liste repertoires uniquement
Function ListRepRep($Arbo,$profondeur,$NomSortie)
{
Write-output \"Inventaire des repertoires à partir de la racine $Arbo\" >> $FicLog
Get-ChildItemToDepth $Arbo -todepth $profondeur | where {$_.psiscontainer} | Format-table -Auto -property LastAccessTime,FullName >> $RepLog\ArboRep$temps.$NomSortie
Write-output \"Fichier de sortie : $RepLog\ArboRep$temps.$NomSortie\" >> $FicLog
invoke-item \"$RepLog\ArboRep$temps.$NomSortie\"
}


# Liste repertoires et Fichiers
Function ListRepRepFic($Arbo,$profondeur,$NomSortie)
{
Write-output \"Inventaire des repertoires ET des fichiers à partir de la racine $Arbo\" >> $FicLog
Get-ChildItemToDepth $Arbo -todepth $profondeur | Format-table -Auto -property LastAccessTime,FullName >> $RepLog\ArboRepFic$temps.$NomSortie
Write-output \"Fichier de sortie : $RepLog\ArboRepFic$temps.$NomSortie\" >> $FicLog
invoke-item \"$RepLog\ArboRepFic$temps.$NomSortie\"
}


#################################################################################
#################################### Action #####################################
#################################################################################

# On test l'existence du repertoire de Log. S'il n'existe pas on le cré.
if(test-path $replog )
{
$FicLog = ($RepLog+\"\Log-$temps.txt\"«»)
write-Output \"le repertoire Log existe\" >> $FicLog
}
Else
{
new-item $replog -type directory
$FicLog = ($RepLog+\"\Log-$temps.txt\"«»)
Write-output \"le repertoire Log a ete créé\" >> $FicLog
}

# Top depart du traitement
$DebTrait = Get-date
Write-Output \"Debut de traitement $DebTrait\" >> $FicLog


write-host \"le fichier de sortie est $FicLog\"
Arbo $FicLog
Profondeur $FicLog
DirFic $FicLog
FicSortie $FicLog
choix $RepOuFic $Arbo $profondeur $NomSortie $FicLog

# Top Fin du traitement
$FinTrait = Get-date
Write-Output \"Fin de traitement $FinTrait\" >> $FicLog

invoke-item \"$FicLog\"
[/code:1]
tu as le choix pour le nombre de niveaux

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

Plus d'informations
il y a 12 ans 10 mois #14864 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:Get-Childitem ???
fabgr écrit:

hello voila ce que j'ai trouve sur le net.

:blink:
Il est parfois préférable de ne pas déterrer les cadavres du net.
;)

Tutoriels PowerShell

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

Plus d'informations
il y a 12 ans 10 mois #14867 par stas
Réponse de stas sur le sujet Re:Get-Childitem ???
Hello,

Pourquoi?

si on trouve qlq chose qui est déjà écrit et que surtout on le comprend.

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

Temps de génération de la page : 0.106 secondes
Propulsé par Kunena