IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Permissions NTFS de répertoires [PowerShell]


Sujet :

Scripts/Batch

  1. #1
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut Permissions NTFS de répertoires
    Bonjour,

    J'ai scripté en PowerShell, un script me permettant de paresser un répertoire et sous répertoire en m'affichant les utilisateurs/groupes avec les droits d'accès NTFS lié au répertoire dans un fichier Excel :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    # FONCTIONS #
    
    # Fenêtre de sélection dossier
    function Select-Folder($message='Select a folder', $path = 0) { 
    	$object = New-Object -comObject Shell.Application  
    	 
    	$folder = $object.BrowseForFolder(0, $message, 0, $path) 
    	if ($folder -ne $null) { 
    		$folder.self.Path 
    	} 
    }
    
    # MAIN #
    
    # Effacer page #
    clear
    
    # Création du fichier Excel avec les entêtes #
    $a = New-Object -comobject Excel.Application
    $a.Visible = $True
    $b = $a.Workbooks.Add()
    $d = $b.Worksheets.Item(1)
    $d.name = "Droits NTFS"
    $ligne=1
    $col=1
    $d.Cells.Item($ligne,$col)= "Fullname"
    $col++
    $d.Cells.Item($ligne,$col)= "Identity" 
    $col++
    $d.Cells.Item($ligne,$col)= "Rights" 
    $col++
    $d.Cells.Item($ligne,$col)= "IsInherited" 
    $Ligne++
    
    # Sélectionner un dossier de recherche #
    $RootPath = Select-Folder 
    
    # Pareser les répertoires et sous répertoires #
    $Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}
    foreach ($Folder in $Folders)
    {
    	$ACL = Get-Acl $Folder.Fullname
    	foreach($acl in $acl)
    	{
    		$path = $acl.path
    		$owner = $ACL.owner
    		$access = $acl.Access
    		foreach($access in $access)
    		{
    			$Col=1
    			$d.Cells.Item($ligne,$col)= $Folder.Fullname -replace "\r\n","" #répertoire#
    			$Col++
    			
    			$d.Cells.Item($ligne,$col)= $access.IdentityReference.Value -replace "\r\n","" #groupe#
    			$Col++
    			
    			$ObjRow = out-string -InputObject $access.FileSystemRights #Accès NTFS#
    			$d.Cells.Item($ligne,$col)= $ObjRow -replace "\r\n",""
    			$Col++
    
    			$ObjRow = out-string -InputObject $access.IsInherited #Héritage : Yes/no#
    			$d.Cells.Item($ligne,$col)= $ObjRow -replace "\r\n",""
    			$ligne++		
    		}
    	}
    }
    # Message box : fin de traitement#
    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    $oReturn=[System.Windows.Forms.Messagebox]::Show("Traitement termine")
    
    $Resize=$d.UsedRange
    $Resize.EntireColumn.AutoFilter()
    $Resize.EntireColumn.AutoFit()
    $b.SaveAs("D:\Bureau\NTFS.xlsx")
    $a.Quit()
    Dont voici le résultat :

    Nom : ScreenShot004.jpg
Affichages : 2297
Taille : 220,1 Ko

    Q1. Je ne sais pas pourquoi, mais mon paresseur de répertoire ne prend pas en compte le dossier parent et commence l'exploration au dossier enfant. Comment remédier à cela ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    $Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}
    foreach ($Folder in $Folders){
    ...
    }
    Q2. Comme vous pouvez le voir, dans la colonne "Rights", j'ai des numéros et je ne sais pas à quoi cela correspond.
    Y a t-il possibilité d'améliorer cela ?
    L'idéal serait d'avoir l'information la plus explicite possible : contrôle total, modification, Lecture, exécution, affichage du contenu du dossier, écriture, spéciales

    Merci d'avance pour votre aide.

  2. #2
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Salut,
    Q1: Ajoute le nom dans la collection :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $Folders = @(dir $RootPath -recurse | where {$_.psiscontainer -eq $true})+(Get-Item $RootPath)
    Q2: Coder la transformation du champ ou utiliser Sddl :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     $Acl=get-acl c:\temp\
     ConvertFrom-SDDL $acl.Sddl|select -ExpandProperty access

  3. #3
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    Merci beaucoup pour ces éléments.

    Q1 : J'ai écris le code comme cela pour avoir le répertoire racine en 1er dans mon Excel :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $Folders = @(Get-Item $RootPath) + (dir $RootPath -recurse | where {$_.psiscontainer -eq $true})
    Q2. Merci pour cet article : http://blog.cjwdev.co.uk/2011/06/28/...emrights-enum/. Je comprend mieux maintenant.
    Mais le mieux est d'utilisé SDDL ?

    Je ne sais comment intégré cette élément de réponse dans mon script :

    J'ai copier/collé la class ConvertFrom-SDDL dans mon script.

    J'ai ensuite ajouté :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $ACL = Get-Acl $Folder.Fullname
    ConvertFrom-SDDL $acl.Sddl|select -ExpandProperty access
    En sortie j'ai par exemple :

    InheritanceFlags : None
    IsInherited : True
    Rights : ReadData,ReadExtendedAttributes,ReadAttributes,ReadPermissions,Synchronize,ExecuteFile,Read,ReadAnd
    Execute
    AccessControlType : Allow
    IdentityReference : BUILTIN\Utilisateurs
    PropagationFlags : None
    J'aurai voulu récupérer les informations de "Rights" dans mon

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    	foreach($acl in $acl)
    	{
    		$path = $acl.path
    		$owner = $ACL.owner
    		$access = $acl.Access
    		foreach($access in $access)
    		{
    			$Col=1
    			$d.Cells.Item($ligne,$col)= $Folder.Fullname -replace "\r\n","" #répertoire#
    			$Col++
    			
    			$d.Cells.Item($ligne,$col)= $access.IdentityReference.Value -replace "\r\n","" #groupe#
    			$Col++
    			
    			$ObjRowFileSystemRights = out-string -InputObject $access.FileSystemRights #Accès NTFS#
    			$d.Cells.Item($ligne,$col)= $ObjRowFileSystemRights -replace "\r\n",""
    			$Col++
    
    			$ObjRowIsInherited = out-string -InputObject $access.IsInherited #Héritage : Yes/no#
    			$d.Cells.Item($ligne,$col)= $ObjRowIsInherited -replace "\r\n",""
    			$ligne++			
    		}
    	}
    Comment faire ?




    Pouvez-vous me donner plus d'explications ?

    Encore merci

  4. #4
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    J'ai réussi (en tout cas j'ai le résultat attendu) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    # FONCTIONS #
    
    # Fenêtre de sélection dossier
    function Select-Folder($message='Select a folder', $path = 0) { 
    	$object = New-Object -comObject Shell.Application  
    	 
    	$folder = $object.BrowseForFolder(0, $message, 0, $path) 
    	if ($folder -ne $null) { 
    		$folder.self.Path 
    	} 
    }
    
    filter ConvertFrom-SDDL
    {
    	<#
    	.SYNOPSIS
    	 
    		Convert a raw security descriptor from SDDL form to a parsed security descriptor.
    	 
    		Author: Matthew Graeber (@mattifestation)
    	 
    	.DESCRIPTION
    	 
    		ConvertFrom-SDDL generates a parsed security descriptor based upon any string in raw security descriptor definition language (SDDL) form. ConvertFrom-SDDL will parse the SDDL regardless of the type of object the security descriptor represents.
    	 
    	.PARAMETER RawSDDL
    	 
    		Specifies the security descriptor in raw SDDL form.
    	 
    	.EXAMPLE
    	 
    		ConvertFrom-SDDL -RawSDDL 'D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)'
    	 
    	.EXAMPLE
    	 
    		'O:BAG:SYD:(D;;0xf0007;;;AN)(D;;0xf0007;;;BG)(A;;0xf0005;;;SY)(A;;0x5;;;BA)', 'O:BAG:SYD:PAI(D;OICI;FA;;;BG)(A;OICI;FA;;;BA)(A;OICIIO;FA;;;CO)(A;OICI;FA;;;SY)' | ConvertFrom-SDDL
    	 
    	.INPUTS
    	 
    		System.String
    	 
    		ConvertFrom-SDDL accepts SDDL strings from the pipeline
    	 
    	.OUTPUTS
    	 
    		System.Management.Automation.PSObject
    	 
    	.LINK
    	 
    		http://www.exploit-monday.com
    	#>
     
    	Param (
    		[Parameter( Position = 0, Mandatory = $True, ValueFromPipeline = $True )]
    		[ValidateNotNullOrEmpty()]
    		[String[]]
    		$RawSDDL
    	)
     
    	Set-StrictMode -Version 2
     
    	# Get reference to sealed RawSecurityDescriptor class
    	$RawSecurityDescriptor = [Int].Assembly.GetTypes() | ? { $_.FullName -eq 'System.Security.AccessControl.RawSecurityDescriptor' }
     
    	# Create an instance of the RawSecurityDescriptor class based upon the provided raw SDDL
    	try
    	{
    		$Sddl = [Activator]::CreateInstance($RawSecurityDescriptor, [Object[]] @($RawSDDL))
    	}
    	catch [Management.Automation.MethodInvocationException]
    	{
    		throw $Error[0]
    	}
     
    	if ($Sddl.Group -eq $null)
    	{
    		$Group = $null
    	}
    	else
    	{
    		$SID = $Sddl.Group
    		$Group = $SID.Translate([Security.Principal.NTAccount]).Value
    	}
       
    	if ($Sddl.Owner -eq $null)
    	{
    		$Owner = $null
    	}
    	else
    	{
    		$SID = $Sddl.Owner
    		$Owner = $SID.Translate([Security.Principal.NTAccount]).Value
    	}
     
    	$ObjectProperties = @{
    		Group = $Group
    		Owner = $Owner
    	}
     
    	if ($Sddl.DiscretionaryAcl -eq $null)
    	{
    		$Dacl = $null
    	}
    	else
    	{
    		$DaclArray = New-Object PSObject[](0)
     
    		$ValueTable = @{}
     
    		$EnumValueStrings = [Enum]::GetNames([System.Security.AccessControl.CryptoKeyRights])
    		$CryptoEnumValues = $EnumValueStrings | % {
    				$EnumValue = [Security.AccessControl.CryptoKeyRights] $_
    				if (-not $ValueTable.ContainsKey($EnumValue.value__))
    				{
    					$EnumValue
    				}
    	   
    				$ValueTable[$EnumValue.value__] = 1
    			}
     
    		$EnumValueStrings = [Enum]::GetNames([System.Security.AccessControl.FileSystemRights])
    		$FileEnumValues = $EnumValueStrings | % {
    				$EnumValue = [Security.AccessControl.FileSystemRights] $_
    				if (-not $ValueTable.ContainsKey($EnumValue.value__))
    				{
    					$EnumValue
    				}
    	   
    				$ValueTable[$EnumValue.value__] = 1
    			}
     
    		$EnumValues = $CryptoEnumValues + $FileEnumValues
     
    		foreach ($DaclEntry in $Sddl.DiscretionaryAcl)
    		{
    			$SID = $DaclEntry.SecurityIdentifier
    			$Account = $SID.Translate([Security.Principal.NTAccount]).Value
     
    			$Values = New-Object String[](0)
     
    			# Resolve access mask
    			foreach ($Value in $EnumValues)
    			{
    				if (($DaclEntry.Accessmask -band $Value) -eq $Value)
    				{
    					$Values += $Value.ToString()
    				}
    			}
     
    			$Access = "$($Values -join ',')"
     
    			$DaclTable = @{
    				Rights = $Access
    				IdentityReference = $Account
    				IsInherited = $DaclEntry.IsInherited
    				InheritanceFlags = $DaclEntry.InheritanceFlags
    				PropagationFlags = $DaclEntry.PropagationFlags
    			}
     
    			if ($DaclEntry.AceType.ToString().Contains('Allowed'))
    			{
    				$DaclTable['AccessControlType'] = [Security.AccessControl.AccessControlType]::Allow
    			}
    			else
    			{
    				$DaclTable['AccessControlType'] = [Security.AccessControl.AccessControlType]::Deny
    			}
     
    			$DaclArray += New-Object PSObject -Property $DaclTable
    		}
     
    		$Dacl = $DaclArray
    	}
     
    	$ObjectProperties['Access'] = $Dacl
     
    	$SecurityDescriptor = New-Object PSObject -Property $ObjectProperties
     
    	Write-Output $SecurityDescriptor
    }
    
    # MAIN #
    
    # Effacer page #
    clear
    
    # Création du fichier Excel avec les entêtes #
    $a = New-Object -comobject Excel.Application
    $a.Visible = $True
    $b = $a.Workbooks.Add()
    $d = $b.Worksheets.Item(1)
    $d.name = "Droits NTFS"
    $ligne=1
    $col=1
    $d.Cells.Item($ligne,$col)= "Fullname"
    $col++
    $d.Cells.Item($ligne,$col)= "Identity" 
    $col++
    $d.Cells.Item($ligne,$col)= "Rights" 
    $col++
    $d.Cells.Item($ligne,$col)= "IsInherited" 
    $Ligne++
    
    # Sélectionner un dossier de recherche #
    $RootPath = Select-Folder 
    
    # Paresser les répertoires et sous répertoires #
    $Folders = @(Get-Item $RootPath) + (dir $RootPath -recurse | where {$_.psiscontainer -eq $true})
    
    foreach ($Folder in $Folders)
    {
    	$ACL = Get-Acl $Folder.Fullname
    	$access = ConvertFrom-SDDL $acl.Sddl|select -ExpandProperty access
    	foreach($acl in $acl)
    	{
    		foreach($access in $access)
    		{
    			$Col=1
    			$d.Cells.Item($ligne,$col)= $Folder.Fullname -replace "\r\n","" #répertoire#
    			$Col++
    			
    			$d.Cells.Item($ligne,$col)= $access.IdentityReference -replace "\r\n","" #groupe#
    			$Col++
    			
    			$ObjRowFileSystemRights = out-string -InputObject $access.Rights #Accès NTFS#
    			$d.Cells.Item($ligne,$col)= $ObjRowFileSystemRights -replace "\r\n",""
    			$Col++
    
    			$ObjRowIsInherited = out-string -InputObject $access.IsInherited #Héritage : Yes/no#
    			$d.Cells.Item($ligne,$col)= $ObjRowIsInherited -replace "\r\n",""
    			$ligne++			
    		}
    	}
    }
    # Message box : fin de traitement#
    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    $oReturn=[System.Windows.Forms.Messagebox]::Show("Traitement termine")
    
    $Resize=$d.UsedRange
    $Resize.EntireColumn.AutoFilter()
    $Resize.EntireColumn.AutoFit()
    $b.SaveAs("D:\Bureau\NTFS.xlsx")
    $a.Quit()
    Vous en pensez quoi ?

  5. #5
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par arnaudperfect Voir le message
    J'ai réussi (en tout cas j'ai le résultat attendu)
    C'est le principal.
    Fallait juste prendre le temps d'analyser l'objet renvoyé par la fonction...
    Citation Envoyé par arnaudperfect Voir le message
    Vous en pensez quoi ?
    Rien de particulier

  6. #6
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    Je viens de testé mon script sur un serveur, et j'ai ces erreurs (alors que sur mon Pc cela fonctionne bien)

    Exception calling "Add" with "0" argument(s): "Old format or invalid type library. (Exception from HRESULT: 0x80028018
    (TYPE_E_INVDATAREAD))"
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:193 char:1
    + $b = $a.Workbooks.Add()
    + ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

    You cannot call a method on a null-valued expression.
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:194 char:1
    + $d = $b.Worksheets.Item(1)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    The property 'name' cannot be found on this object. Verify that the property exists and can be set.
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:195 char:1
    + $d.name = "Droits NTFS"
    + ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

    You cannot call a method on a null-valued expression.
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:198 char:1
    + $d.Cells.Item($ligne,$col)= "Fullname"
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:199 char:1
    + $d.Cells.Item($ligne,$col).Font.Bold = $True
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:201 char:1
    + $d.Cells.Item($ligne,$col)= "Identity"
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:202 char:1
    + $d.Cells.Item($ligne,$col).Font.Bold = $True
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:204 char:1
    + $d.Cells.Item($ligne,$col)= "Rights"
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:205 char:1
    + $d.Cells.Item($ligne,$col).Font.Bold = $True
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:207 char:1
    + $d.Cells.Item($ligne,$col)= "IsInherited"
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Users\ADMROOT_fourquemin\Desktop\NTFS.PS1:208 char:1
    + $d.Cells.Item($ligne,$col).Font.Bold = $True
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
    Sur mon Pc j'ai Excel 2010 alors que sur le serveur, il y a Excel 2013. J'ai PowerShell 4 sur le serveur et le PowerShell 2 sur mon PC
    Comment rendre compatible mon script ?

  7. #7
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par arnaudperfect Voir le message
    Comment rendre compatible mon script ?
    Déjà comprendre l'erreur renvoyée : Exception calling "Add" with "0" argument(s): "Old format or invalid type library. (Exception from HRESULT: 0x80028018
    Consulte ceci :
    http://support2.microsoft.com/defaul...b;en-us;320369

  8. #8
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    d'après ce que je comprend, c'est un problème avec mon Excel en anglais et mon environnement système qui est en Français.

    Mais je n'y comprend rien pour résoudre le problème...

  9. #9
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par arnaudperfect Voir le message
    Mais je n'y comprend rien pour résoudre le problème...
    Essaie en utilisant ce script qui modifie la culture courante du thread.
    Ou en paramétrant le LCID, le langage/culture, comme indiqué dans l'article cité du support MS.
    Voir également ceci ou cela

  10. #10
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    Bonjour,

    Je suis de retour sur mon script.

    J'ai ajouter le script dans mon code. Cela à résolu mon problème de génération de tableau Excel :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    # FONCTIONS #
    
    # Using-Culture -Culture culture -Script {scriptblock}
    Function Using-Culture (
    [System.Globalization.CultureInfo]$culture = (throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"),
    [ScriptBlock]$script= (throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"))
    {
        $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
        trap 
        {
            [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
        }
        [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
        Invoke-Command $script
        [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
    }
    
    # Fenêtre de sélection dossier
    function Select-Folder($message='Select a folder', $path = 0) { 
    	$object = New-Object -comObject Shell.Application  
    	 
    	$folder = $object.BrowseForFolder(0, $message, 0, $path) 
    	if ($folder -ne $null) { 
    		$folder.self.Path 
    	} 
    }
    
    # Class droits NTFS
    filter ConvertFrom-SDDL
    {
    	<#
    	.SYNOPSIS
    	 
    		Convert a raw security descriptor from SDDL form to a parsed security descriptor.
    	 
    		Author: Matthew Graeber (@mattifestation)
    	 
    	.DESCRIPTION
    	 
    		ConvertFrom-SDDL generates a parsed security descriptor based upon any string in raw security descriptor definition language (SDDL) form. ConvertFrom-SDDL will parse the SDDL regardless of the type of object the security descriptor represents.
    	 
    	.PARAMETER RawSDDL
    	 
    		Specifies the security descriptor in raw SDDL form.
    	 
    	.EXAMPLE
    	 
    		ConvertFrom-SDDL -RawSDDL 'D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)'
    	 
    	.EXAMPLE
    	 
    		'O:BAG:SYD:(D;;0xf0007;;;AN)(D;;0xf0007;;;BG)(A;;0xf0005;;;SY)(A;;0x5;;;BA)', 'O:BAG:SYD:PAI(D;OICI;FA;;;BG)(A;OICI;FA;;;BA)(A;OICIIO;FA;;;CO)(A;OICI;FA;;;SY)' | ConvertFrom-SDDL
    	 
    	.INPUTS
    	 
    		System.String
    	 
    		ConvertFrom-SDDL accepts SDDL strings from the pipeline
    	 
    	.OUTPUTS
    	 
    		System.Management.Automation.PSObject
    	 
    	.LINK
    	 
    		http://www.exploit-monday.com
    	#>
     
    	Param (
    		[Parameter( Position = 0, Mandatory = $True, ValueFromPipeline = $True )]
    		[ValidateNotNullOrEmpty()]
    		[String[]]
    		$RawSDDL
    	)
     
    	Set-StrictMode -Version 2
     
    	# Get reference to sealed RawSecurityDescriptor class
    	$RawSecurityDescriptor = [Int].Assembly.GetTypes() | ? { $_.FullName -eq 'System.Security.AccessControl.RawSecurityDescriptor' }
     
    	# Create an instance of the RawSecurityDescriptor class based upon the provided raw SDDL
    	try
    	{
    		$Sddl = [Activator]::CreateInstance($RawSecurityDescriptor, [Object[]] @($RawSDDL))
    	}
    	catch [Management.Automation.MethodInvocationException]
    	{
    		throw $Error[0]
    	}
     
    	if ($Sddl.Group -eq $null)
    	{
    		$Group = $null
    	}
    	else
    	{
    		$SID = $Sddl.Group
    		$Group = $SID.Translate([Security.Principal.NTAccount]).Value
    	}
       
    	if ($Sddl.Owner -eq $null)
    	{
    		$Owner = $null
    	}
    	else
    	{
    		$SID = $Sddl.Owner
    		$Owner = $SID.Translate([Security.Principal.NTAccount]).Value
    	}
     
    	$ObjectProperties = @{
    		Group = $Group
    		Owner = $Owner
    	}
     
    	if ($Sddl.DiscretionaryAcl -eq $null)
    	{
    		$Dacl = $null
    	}
    	else
    	{
    		$DaclArray = New-Object PSObject[](0)
     
    		$ValueTable = @{}
     
    		$EnumValueStrings = [Enum]::GetNames([System.Security.AccessControl.CryptoKeyRights])
    		$CryptoEnumValues = $EnumValueStrings | % {
    				$EnumValue = [Security.AccessControl.CryptoKeyRights] $_
    				if (-not $ValueTable.ContainsKey($EnumValue.value__))
    				{
    					$EnumValue
    				}
    	   
    				$ValueTable[$EnumValue.value__] = 1
    			}
     
    		$EnumValueStrings = [Enum]::GetNames([System.Security.AccessControl.FileSystemRights])
    		$FileEnumValues = $EnumValueStrings | % {
    				$EnumValue = [Security.AccessControl.FileSystemRights] $_
    				if (-not $ValueTable.ContainsKey($EnumValue.value__))
    				{
    					$EnumValue
    				}
    	   
    				$ValueTable[$EnumValue.value__] = 1
    			}
     
    		$EnumValues = $CryptoEnumValues + $FileEnumValues
     
    		foreach ($DaclEntry in $Sddl.DiscretionaryAcl)
    		{
    			$SID = $DaclEntry.SecurityIdentifier
    			$Account = $SID.Translate([Security.Principal.NTAccount]).Value
     
    			$Values = New-Object String[](0)
     
    			# Resolve access mask
    			foreach ($Value in $EnumValues)
    			{
    				if (($DaclEntry.Accessmask -band $Value) -eq $Value)
    				{
    					$Values += $Value.ToString()
    				}
    			}
     
    			$Access = "$($Values -join ',')"
     
    			$DaclTable = @{
    				Rights = $Access
    				IdentityReference = $Account
    				IsInherited = $DaclEntry.IsInherited
    				InheritanceFlags = $DaclEntry.InheritanceFlags
    				PropagationFlags = $DaclEntry.PropagationFlags
    			}
     
    			if ($DaclEntry.AceType.ToString().Contains('Allowed'))
    			{
    				$DaclTable['AccessControlType'] = [Security.AccessControl.AccessControlType]::Allow
    			}
    			else
    			{
    				$DaclTable['AccessControlType'] = [Security.AccessControl.AccessControlType]::Deny
    			}
     
    			$DaclArray += New-Object PSObject -Property $DaclTable
    		}
     
    		$Dacl = $DaclArray
    	}
     
    	$ObjectProperties['Access'] = $Dacl
     
    	$SecurityDescriptor = New-Object PSObject -Property $ObjectProperties
     
    	Write-Output $SecurityDescriptor
    }
    
    # MAIN #
    
    # Effacer page #
    clear
    
    using-culture en-US {
    
    	# Sélectionner un dossier de recherche #
    	$RootPath = Select-Folder 
    
    	# Création du fichier Excel avec les entêtes #
    	$a = New-Object -comobject Excel.Application
    	$a.Visible = $True
    	$b = $a.Workbooks.Add()
    	$d = $b.Worksheets.Item(1)
    	$d.name = "Droits NTFS"
    	$ligne=1
    	$col=1
    	$d.Cells.Item($ligne,$col)= "Fullname"
    	$d.Cells.Item($ligne,$col).Font.Bold = $True
    	$col++
    	$d.Cells.Item($ligne,$col)= "Identity"
    	$d.Cells.Item($ligne,$col).Font.Bold = $True
    	$col++
    	$d.Cells.Item($ligne,$col)= "Rights"
    	$d.Cells.Item($ligne,$col).Font.Bold = $True
    	$col++
    	$d.Cells.Item($ligne,$col)= "IsInherited"
    	$d.Cells.Item($ligne,$col).Font.Bold = $True
    	$Ligne++
    
    	# Paresser les répertoires et sous répertoires #
    	$Folders = @(Get-Item $RootPath) + (dir $RootPath -recurse | where {$_.psiscontainer -eq $true})
    
    	echo "Exploration des répertoires en cours..."
    
    	foreach ($Folder in $Folders)
    	{
    		$ACL = Get-Acl $Folder.Fullname
    		$access = ConvertFrom-SDDL $acl.Sddl|select -ExpandProperty access
    		foreach($acl in $acl)
    		{
    			foreach($access in $access)
    			{
    				$Col=1
    				$d.Cells.Item($ligne,$col)= $Folder.Fullname -replace "\r\n","" #répertoire#
    				$Col++
    				
    				$d.Cells.Item($ligne,$col)= $access.IdentityReference -replace "\r\n","" #groupe#
    				$Col++
    				
    				$ObjRowFileSystemRights = out-string -InputObject $access.Rights #Accès NTFS#
    				$d.Cells.Item($ligne,$col)= $ObjRowFileSystemRights -replace "\r\n",""
    				$Col++
    
    				$ObjRowIsInherited = out-string -InputObject $access.IsInherited #Héritage : Yes/no#
    				$d.Cells.Item($ligne,$col)= $ObjRowIsInherited -replace "\r\n",""
    				$ligne++			
    			}
    		}
    	}
    
    	$Resize=$d.UsedRange
    	$Resize.EntireColumn.AutoFilter()
    	$Resize.EntireColumn.AutoFit()
    	$b.SaveAs("D:\Bureau\NTFS.xlsx")
    	#$a.Quit()
    
    	# Message box : fin de traitement#
    	[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    	$oReturn=[System.Windows.Forms.Messagebox]::Show("Traitement termine")
    }
    Après j'ai des problèmes de longueurs de chemin :

    dir : The specified path, file name, or both are too long. The fully qualified file name must be less than 260
    characters, and the directory name must be less than 248 characters.
    At C:\Users\xxxxxx\Desktop\NTFS.PS1:230 char:38
    + $Folders = @(Get-Item $RootPath) + (dir $RootPath -recurse | where {$_.psiscont ...
    + ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ReadError: (H:\groupe\Gesti...s\xxxx\Offres:String) [Get-ChildItem], PathTooLongExcept
    ion
    + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
    Il y a moyen de lever cette limitation ?

  11. #11
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par arnaudperfect Voir le message
    Il y a moyen de lever cette limitation ?
    Essaie en créant un drive Powershell (new-psDrive) ou system (net use ou Subst).

  12. #12
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    L'accès à mes répertoires sont font via un drive système.

    Mais la longueur des chemins de certains répertoires de mon arborescence de mon serveur de fichier peut être très très longue...

    Je suis accès étonné de cette limitation sur le powershell. En VBS, je n'ai aucun soucie.

  13. #13
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    J'ai trouvé ceci : http://asysadmin.tumblr.com/post/176...gth-limitation

    Tu en penses quoi ? Je n'ai pas testé.

  14. #14
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par arnaudperfect Voir le message
    Je suis assez étonné de cette limitation sur le powershell. En VBS, je n'ai aucun soucie.
    Je suppose que VBS utilise des APIs win32 là où Powershell utilise des APIs Dotnet.
    Avec la commande DOS Subst tu peux substituer un lecteur déjà substitué, avec le cmdlet Powershell New-PsDrive également.
    Mais la création transitoire d'un drive selon une longueur max du path peut s'avérer délicat. L'api Win 32 peut gérer une string d'une longueur de 32 Ko si je me souviens bien

    Citation Envoyé par arnaudperfect Voir le message
    Tu en penses quoi ? Je n'ai pas testé.
    Que c'est une possible solution, mais on retombe dans du parsing de chaîne.
    A moins d'utiliser une autre approche d'autres options et combiner l'usage de nom court :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    for /f "usebackq delims=" %X in (`dir /b /a:hd /S`) do @echo %~fsX
    Mais à mon avis on retarde le moment où la limite des 248 caractères sera atteinte.

    La solution du drive transitoire me semble plus robuste, mais cela reste à coder et à tester
    Ou bien trouver sur le net une fonction existante réglant ce problème...

  15. #15
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    Citation Envoyé par Laurent Dardenne Voir le message
    Que c'est une possible solution, mais on retombe dans du parsing de chaîne.
    Et je suppose que les temps de traitement vont être très long ? J'ai testé sur une petite arborescente et c'est déjà long, alors sur mon serveur de fichier...

    Le script va balayer tous les chemins, pour ensuite regarder un par un les droits NTFS. En sommes, deux accès réseau pour une tâche qui pourrait être faite en une.

    Citation Envoyé par Laurent Dardenne Voir le message
    A moins d'utiliser une autre approche d'autres options et combiner l'usage de nom court :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    for /f "usebackq delims=" %X in (`dir /b /a:hd /S`) do @echo %~fsX
    Mais à mon avis on retarde le moment où la limite des 248 caractères sera atteinte.
    Je le pense aussi...

    Citation Envoyé par Laurent Dardenne Voir le message
    La solution du drive transitoire me semble plus robuste, mais cela reste à coder et à tester
    Je ne vois pas trop niveau algo à quoi cela peut ressemblé...

    Citation Envoyé par Laurent Dardenne Voir le message
    Ou bien trouver sur le net une fonction existante réglant ce problème...
    Rien trouvé pour le moment.

  16. #16
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par arnaudperfect Voir le message
    J'ai testé sur une petite arborescente et c'est déjà long, alors sur mon serveur de fichier...
    Oui PS est très lent sur ce type d'opération.
    Citation Envoyé par arnaudperfect Voir le message
    Je ne vois pas trop niveau algo à quoi cela peut ressemblé...
    Cette approche nécessite de lire fichier par fichier
    Sinon on ne peut connaitre la taille max.
    Une approche ? http://94.227.151.106:1983/blog/2013...ith-junctions/

    Avec ton traitement, tu touches les limites de PS.
    Une retraite stratégique vers un outil Win32 couplé à du parsing est à envisager.
    Où coder des Api Win32

  17. #17
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    J'ai trouvé cela sinon : [Alphaleonis.Win32.Filesystem.Directory]::GetDirectories($Path)

    http://alphafs.codeplex.com/

    avec une bibliothèque alphaFS.dll

    Je cherche comment l'utiliser

  18. #18
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    Alors, j'ai réussi à faire fonctionné cette class.

    Avec [Alphaleonis.Win32.Filesystem.Directory]::GetDirectories($Path), j'arrive à avoir les chemins des répertoires contenu dans le $path.

    Pour avoir les sous répertoires, je pense qu'il faut que je code une récursivité.

    J'en pensé à un truc de ce genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    # Import AlphaFS .NET module - http://alphafs.codeplex.com/
    Import-Module C:\AlphaFS.dll
    
    # Variables
    $Path = "C:\Users"
    
    # RecursePath function.
    Function RecursePath($Path)
    {   
    	$count = 0
        $Paths = [Alphaleonis.Win32.Filesystem.Directory]::GetDirectories($Path)
        foreach($Path in $Paths)
    	{
    		RecursePath $Path[$count]
    		$count ++
    	}
    }
    
    RecursePath $Path
    Sauf que j'ai rien en sortie. Je ne sais pas trop comment on code une bouche récursive.

  19. #19
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Pour afficher les surcharges d'une méthode utilise ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    [Alphaleonis.Win32.Filesystem.Directory]::GetDirectories
    Il existe une doc .chm dans l'archive :
    public static string[] GetDirectories(
    string path,
    string searchPattern,
    SearchOption searchOption
    )

  20. #20
    Membre actif
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Décembre 2006
    Messages
    1 080
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 080
    Points : 287
    Points
    287
    Par défaut
    Oui, j'ai vu ça, mais c'est pas très claire pour moi...

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 4 1234 DernièreDernière

Discussions similaires

  1. [Infomaniak] Quelles permissions sur fichiers/répertoires ?
    Par Sayrus dans le forum Hébergement
    Réponses: 0
    Dernier message: 22/10/2009, 15h32
  2. Delphi et Permission NTFS (cacls inside)
    Par Raspoutitsa dans le forum Débuter
    Réponses: 0
    Dernier message: 19/08/2009, 16h37
  3. [WD11] Permissions NTFS
    Par WDKyle dans le forum WinDev
    Réponses: 7
    Dernier message: 06/07/2009, 09h29
  4. Modifier les permissions d'un répertoire
    Par zan001 dans le forum Général Java
    Réponses: 0
    Dernier message: 30/04/2009, 18h57
  5. Permissions NTFS avec XP Home
    Par Loceka dans le forum Sécurité
    Réponses: 2
    Dernier message: 10/09/2006, 11h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo