Question nouveau

Plus d'informations
il y a 7 ans 3 semaines #23371 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:Nouveau quota dossier
Quelques erreurs et amélioration :
[code:1]
#on force le type
Function Measure-UserQuota ([int]$Quota_Source)
[/code:1]
Le cas final référence une variable de l'appelant, à éviter. Modifie l'affectation si la mienne est erronée :
[code:1]
else
{
return $Quota_Source
}

}
[/code:1]
Dans le foreach il faut adresser l'objet courant $Item
[code:1]
foreach ($item in $folders)
{
$Quota_Cible=Measure-UserQuota $Item.Quota_Source
[/code:1]
Tu devrais enrichir tes cas de test, par exemple Quota_Source contenant une chaine vide, contenant une valeur impossible à convertir, etc

Tutoriels PowerShell

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

Plus d'informations
il y a 7 ans 3 semaines #23372 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:Nouveau quota dossier
Powershell convertit l'opérande droit dans le type de l'opérande gauche.
[code:1]
Trace-Command -PSHost -Name TypeMatch, TypeConversion -Expression { $Quota_Source='510';if ($Quota_Source -le 500) {'ok'} else {'Nok'} }
# DÉBOGUER : TypeConversion Information: 0 : Converting \"64\" to \"System.Int32\".
# DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from
# value to convert's type
# DÉBOGUER : TypeConversion Information: 0 : Converting \"System.Object[]\" to
# \"System.Object[]\".
# DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from
# value to convert's type
# DÉBOGUER : TypeConversion Information: 0 : Converting \"500\" to \"System.String\". <---- test sur des strings
# DÉBOGUER : TypeConversion Information: 0 : Converting numeric to string.
Nok

Trace-Command -PSHost -Name TypeMatch, TypeConversion -Expression { $Quota_Source='510';if (500 -ge $Quota_Source) {'ok'} else {'Nok'} }
# DÉBOGUER : TypeConversion Information: 0 : Converting \"64\" to \"System.Int32\".
# DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from
# value to convert's type
# DÉBOGUER : TypeConversion Information: 0 : Converting \"System.Object[]\" to
# \"System.Object[]\".
# DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from
# value to convert's type
# DÉBOGUER : TypeConversion Information: 0 : Converting \"510\" to \"System.Int32\". <---- test sur des entiers
# DÉBOGUER : TypeConversion Information: 0 : Converting to integer.
Nok
[/code:1]
Voir aussi

Tutoriels PowerShell

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

Plus d'informations
il y a 7 ans 3 semaines #23379 par Faye
Réponse de Faye sur le sujet Re:Nouveau quota dossier
Merci pour votre aide précieuse.
ça marche avec le [int] positionné avant la variable locale et l'appel de ma fonction en mentionnant le $item.Quota_source.

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

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