Question [Resolu]System.Byte[] to sting

Plus d'informations
il y a 13 ans 11 mois #6689 par Seals
Réponse de Seals sur le sujet Re:System.Byte[] to sting
Laurent Dardenne écrit:

Essaie ceci, sinon ton code affiche l'objet collection et pas l'objet contenu :
[code:1]
Write-Properties $user.unixUserPassword[0]
[/code:1]


dans ce cas, il ne me retourne rien meme pas le 1er champs (65)

il se peut qu'il faille adresser un membre, par exemple $user.unixUserPassword.Value

En faite, je n'ai pas trouve le methode Value, mais GetValue.
[code:1]TypeName: System.Byte[]

Name MemberType Definition
----

Count AliasProperty Count = Length
Address Method System.Byte&, mscorlib, Version=2.0.0.0, Cultur...
Clone Method System.Object Clone()
CopyTo Method System.Void CopyTo(array array, int index), Sys...
Equals Method bool Equals(System.Object obj)
Get Method byte Get(int )
GetEnumerator Method System.Collections.IEnumerator GetEnumerator()
GetHashCode Method int GetHashCode()
GetLength Method int GetLength(int dimension)
GetLongLength Method long GetLongLength(int dimension)
GetLowerBound Method int GetLowerBound(int dimension)
GetType Method type GetType()
GetUpperBound Method int GetUpperBound(int dimension)
GetValue Method System.Object GetValue(Params int[] indices), S...
Initialize Method System.Void Initialize()
Set Method System.Void Set(int , byte )
SetValue Method System.Void SetValue(System.Object value, int i...
ToString Method string ToString()
IsFixedSize Property System.Boolean IsFixedSize {get;}
IsReadOnly Property System.Boolean IsReadOnly {get;}
IsSynchronized Property System.Boolean IsSynchronized {get;}
Length Property System.Int32 Length {get;}
LongLength Property System.Int64 LongLength {get;}
Rank Property System.Int32 Rank {get;}
SyncRoot Property System.Object SyncRoot {get;}
[/code:1]

J'en conclu que je dois ecrire ceci
[code:1]($user.unixUserPassword).getValue(Params int[0])[/code:1]
Mais ca ne fonctionne pas...

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

Plus d'informations
il y a 13 ans 11 mois #6691 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:System.Byte[] to sting
Seals écrit:

dans ce cas, il ne me retourne rien meme pas le 1er champs (65)

:dry:
Seals écrit:

J'en conclu que je dois ecrire ceci
[code:1]($user.unixUserPassword).getValue(Params int[0])[/code:1]
Mais ca ne fonctionne pas...

Ainsi tu déclares plutot une signature, il faut l'utiliser comme ceci : GetValue(0)

Sinon que renvoi le code suivant ?
[code:1]
[string][char[]]$user.unixUserPassword
[/code:1]

Tutoriels PowerShell

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

Plus d'informations
il y a 13 ans 11 mois #6693 par Seals
Réponse de Seals sur le sujet Re:System.Byte[] to sting
pkoi les conversions sont elles toujours aussi compliquées :dry:

[code:1]____________________________________________________________________________
[DBG]: PS U:\>>> [string][char[]]$user.unixUserPassword

Impossible de convertir la valeur « System.DirectoryServices.PropertyValueColle
ction » en type « System.Char[] ». Erreur : « Impossible de convertir la valeur
« System.Byte[] » du type « System.Byte[] » en type « System.Char ». »
Au niveau de ligne : 1 Caractère : 23
+ [string][char[]]$user. <<<< unixUserPassword
+ CategoryInfo : NotSpecified: (:«») [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException


____________________________________________________________________________
[DBG]: PS U:\>>> ($user.unixUserPassword).getValue(0)

L'appel de la méthode a échoué parce que [System.DirectoryServices.PropertyValu
eCollection] ne contient pas de méthode nommée « getValue ».
Au niveau de ligne : 1 Caractère : 34
+ ($user.unixUserPassword).getValue <<<< (0)
+ CategoryInfo : InvalidOperation: (getValue:«»String) [], RuntimeE
xception
+ FullyQualifiedErrorId : MethodNotFound

[/code:1]

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

Plus d'informations
il y a 13 ans 11 mois #6694 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:System.Byte[] to sting
Seals écrit:

pkoi les conversions sont elles toujours aussi compliquées :dry:

Elles ne le sont que rarement, la difficulté ici,n'ayant pas AD sous la main, est de connaître l'objet que tu manipules. Et je me souviens avoir déjà rencontré ce pb sur le forum.

$user.unixUserPassword est une collection , ça on en est sûr, reste à déterminer la méthode d'accés à ces éléments.

Que donne ceci :
[code:1]$user.unixUserPassword.GetEnumerator()[/code:1]

Tutoriels PowerShell

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

Plus d'informations
il y a 13 ans 11 mois #6696 par Seals
Réponse de Seals sur le sujet Re:System.Byte[] to sting
Il me liste le contenu du tableau de la même manière que $user.unixUserPassword | Out-Host

[code:1][DBG]: PS U:\>>> $user.unixUserPassword.GetEnumerator()
65
66
67
68
33
101
102
103
104
49
50
51
52
53
36
54
55
56
57
48[/code:1]

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

Plus d'informations
il y a 13 ans 11 mois #6697 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:System.Byte[] to sting
Essaie ceci :
[code:1]$Strb=new-object System.Text.StringBuilder
$user.unixUserPassword|% {[void]$Strb.Append([char]$_)}
$Strb.ToString()[/code:1]
On peut trouver + simple je pense, mais là je n'ai pas trop le temps.

Tutoriels PowerShell

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

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