Question
Obtenir les valeurs dans une variable propre
- Malley
- Auteur du sujet
- Hors Ligne
- Nouveau membre
Réduire
Plus d'informations
- Messages : 10
- Remerciements reçus 0
il y a 7 ans 2 mois #23193
par Malley
Obtenir les valeurs dans une variable propre a été créé par Malley
Bonjour les amis, je débute dans PS et je souhaiterai de l'aide sur un problème de récupération de données ??
Je lance la commande ci dessous (le but est de récupérer les temps de Netlogon de l'utilisateur qui vient de se connecter sur son environnement)
#j'importe le module
Import-Module \"I:\LogonDurationAnalysis_Signed.ps1\"
#
New-Variable -Name Duration (Get-LogonDurationAnalysis -Username $env:USERNAME -UserDomain mondomaine | Format-List -Property 'Logon Duration')
en \"visualisant\" $Duration j'obtiens :
Logon Phase Duration (s) Start Time End Time Interim Delay
Network Providers 1,0 02:25:50.9 02:25:51.9 0,0
User Profile 46,6 02:25:52.1 02:26:38.6 0,1
Group Policy 21,7 02:26:38.6 02:27:00.3 0,0
GP Scripts (async) 2,8 02:27:00.8 02:27:03.7 0,5
Pre-Shell (Userinit) 0,6 02:27:00.8 02:27:01.5 -2,8
et c'est à partir de là que je bloque, j'aimerai obtenir en
$var1 la valeur 1,0
$var2 --> 46,6
$var3 --> 21,7 ... etc jusqu'à 0,6
et là je sèche !!! ça fait plusieurs semaine que je tente des trucs, mais sans résultats. <br><br>Message édité par: Tomalley, à: 17/02/17 14:59
Je lance la commande ci dessous (le but est de récupérer les temps de Netlogon de l'utilisateur qui vient de se connecter sur son environnement)
#j'importe le module
Import-Module \"I:\LogonDurationAnalysis_Signed.ps1\"
#
New-Variable -Name Duration (Get-LogonDurationAnalysis -Username $env:USERNAME -UserDomain mondomaine | Format-List -Property 'Logon Duration')
en \"visualisant\" $Duration j'obtiens :
Logon Phase Duration (s) Start Time End Time Interim Delay
Network Providers 1,0 02:25:50.9 02:25:51.9 0,0
User Profile 46,6 02:25:52.1 02:26:38.6 0,1
Group Policy 21,7 02:26:38.6 02:27:00.3 0,0
GP Scripts (async) 2,8 02:27:00.8 02:27:03.7 0,5
Pre-Shell (Userinit) 0,6 02:27:00.8 02:27:01.5 -2,8
et c'est à partir de là que je bloque, j'aimerai obtenir en
$var1 la valeur 1,0
$var2 --> 46,6
$var3 --> 21,7 ... etc jusqu'à 0,6
et là je sèche !!! ça fait plusieurs semaine que je tente des trucs, mais sans résultats. <br><br>Message édité par: Tomalley, à: 17/02/17 14:59
Pièces jointes :
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 7 ans 2 mois #23194
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Obtenir les valeurs dans une variable propre
Salut,
essaie sans le Format-List.
Format-List est utilisé uniquement pour la visualisation dans la console et change la nature de l'objet.
essaie sans le Format-List.
Format-List est utilisé uniquement pour la visualisation dans la console et change la nature de l'objet.
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- Malley
- Auteur du sujet
- Hors Ligne
- Nouveau membre
Réduire
Plus d'informations
- Messages : 10
- Remerciements reçus 0
il y a 7 ans 2 mois #23195
par Malley
Réponse de Malley sur le sujet Re:Obtenir les valeurs dans une variable propre
Hey merci pour ta réponse, je viens donc d'enlever le format-list et j'obtiens exactement la même chose en fait et je n'arrive pas à traiter cette réponse et obtenir les valeurs qui m'intéresse ...
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 7 ans 2 mois #23196
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Obtenir les valeurs dans une variable propre
Dans ce cas utilise ceci :
[code:1]$Duration=Get-LogonDurationAnalysis -Username $env:USERNAME -UserDomain mondomaine
$Duration.Gettype()
$Duration|Get-Member[/code:1]
Il faut déjà déterminer ce que tu reçois comme objet.
Peut être que ta fonction renvoi un objet de type string ou un objet déjà formaté.
[code:1]$Duration=Get-LogonDurationAnalysis -Username $env:USERNAME -UserDomain mondomaine
$Duration.Gettype()
$Duration|Get-Member[/code:1]
Il faut déjà déterminer ce que tu reçois comme objet.
Peut être que ta fonction renvoi un objet de type string ou un objet déjà formaté.
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- Malley
- Auteur du sujet
- Hors Ligne
- Nouveau membre
Réduire
Plus d'informations
- Messages : 10
- Remerciements reçus 0
il y a 7 ans 2 mois #23197
par Malley
Réponse de Malley sur le sujet Re:Obtenir les valeurs dans une variable propre
voici ce que j'obtiens en lançant les deux commandes :
PS C:\Users\moi> $Duration.Gettype()
IsPublic IsSerial Name BaseType
----
True True Object[] System.Array
______________________________________________________________________________________________________________________________________________________________________________________________
PS C:\Users\moi> $Duration|Get-Member
TypeName: Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Name MemberType Definition
----
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
autosizeInfo Property Microsoft.PowerShell.Commands.Internal.Format.AutosizeInfo autosizeInfo {get;set;}
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property System.String ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry groupingEntry {get;set;}
pageFooterEntry Property Microsoft.PowerShell.Commands.Internal.Format.PageFooterEntry pageFooterEntry {get;set;}
pageHeaderEntry Property Microsoft.PowerShell.Commands.Internal.Format.PageHeaderEntry pageHeaderEntry {get;set;}
shapeInfo Property Microsoft.PowerShell.Commands.Internal.Format.ShapeInfo shapeInfo {get;set;}
TypeName: Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Name MemberType Definition
----
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property System.String ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry groupingEntry {get;set;}
shapeInfo Property Microsoft.PowerShell.Commands.Internal.Format.ShapeInfo shapeInfo {get;set;}
TypeName: Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Name MemberType Definition
----
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property System.String ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
formatEntryInfo Property Microsoft.PowerShell.Commands.Internal.Format.FormatEntryInfo formatEntryInfo {get;set;}
outOfBand Property System.Boolean outOfBand {get;set;}
writeErrorStream Property System.Boolean writeErrorStream {get;set;}
TypeName: Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Name MemberType Definition
----
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property System.String ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry groupingEntry {get;set;}
TypeName: Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Name MemberType Definition
----
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property System.String ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry groupingEntry {get;set;}
PS C:\Users\moi> $Duration.Gettype()
IsPublic IsSerial Name BaseType
----
True True Object[] System.Array
______________________________________________________________________________________________________________________________________________________________________________________________
PS C:\Users\moi> $Duration|Get-Member
TypeName: Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Name MemberType Definition
----
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
autosizeInfo Property Microsoft.PowerShell.Commands.Internal.Format.AutosizeInfo autosizeInfo {get;set;}
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property System.String ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry groupingEntry {get;set;}
pageFooterEntry Property Microsoft.PowerShell.Commands.Internal.Format.PageFooterEntry pageFooterEntry {get;set;}
pageHeaderEntry Property Microsoft.PowerShell.Commands.Internal.Format.PageHeaderEntry pageHeaderEntry {get;set;}
shapeInfo Property Microsoft.PowerShell.Commands.Internal.Format.ShapeInfo shapeInfo {get;set;}
TypeName: Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Name MemberType Definition
----
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property System.String ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry groupingEntry {get;set;}
shapeInfo Property Microsoft.PowerShell.Commands.Internal.Format.ShapeInfo shapeInfo {get;set;}
TypeName: Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
Name MemberType Definition
----
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property System.String ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
formatEntryInfo Property Microsoft.PowerShell.Commands.Internal.Format.FormatEntryInfo formatEntryInfo {get;set;}
outOfBand Property System.Boolean outOfBand {get;set;}
writeErrorStream Property System.Boolean writeErrorStream {get;set;}
TypeName: Microsoft.PowerShell.Commands.Internal.Format.GroupEndData
Name MemberType Definition
----
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property System.String ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry groupingEntry {get;set;}
TypeName: Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Name MemberType Definition
----
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ClassId2e4f51ef21dd47e99d3c952918aff9cd Property System.String ClassId2e4f51ef21dd47e99d3c952918aff9cd {get;}
groupingEntry Property Microsoft.PowerShell.Commands.Internal.Format.GroupingEntry groupingEntry {get;set;}
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 7 ans 2 mois #23198
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Obtenir les valeurs dans une variable propre
C'est la fonction qui est mal conçue ou conçue pour la visualisation uniquement.
Tu ne récupères pas l'objet portant les propriétés mais une représentation formatée juste bon à être affichée :/
Il ne reste plus qu'a réécrire/adapter la fonction...
Tu ne récupères pas l'objet portant les propriétés mais une représentation formatée juste bon à être affichée :/
Il ne reste plus qu'a réécrire/adapter la fonction...
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.080 secondes
- Vous êtes ici :
- Accueil
- forum
- PowerShell
- Entraide pour les débutants
- Obtenir les valeurs dans une variable propre