Question add-content/get-item caractere speciaux

Plus d'informations
il y a 9 ans 4 mois #22952 par hays
Bonjour,

Comment peut-on ecrire dans un fichier qui est nommé avec des caractère telque ][{ ).

lorsque que j'ai un fichier avec un nom de ce genre j'ai des erreurs car l’interpréteur cherche à intégrer des paramètres.

existe t'il des solution de contournement ?

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

Plus d'informations
il y a 9 ans 4 mois #22953 par Guillaume
Bonjour,

Dans ta commande, ton nom de fichier doit être encadré du symbole '.

Exemple : Get-Content 'C:\test)}\test.ps1'

Dit moi si c'est bon.

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

Plus d'informations
il y a 9 ans 4 mois #22954 par hays
j'ai essayé mais j'ai le même comportement :(

voici l'erreur :S

[code:1]
PS > $error[0] | Format-List -force


Exception : System.Management.Automation.ParameterBindingException: Impossible de récupérer les paramètres dynamiques pour l'applet de commande. Le
modèle générique spécifié n’est pas valide : errrer(5 }[i)ZE.txt ---> System.Management.Automation.WildcardPatternException: Le modèle
générique spécifié n’est pas valide : errrer(5 }[i)ZE.txt
à System.Management.Automation.WildcardPatternParser.Parse(WildcardPattern pattern, WildcardPatternParser parser)
à System.Management.Automation.WildcardPatternMatcher.MyWildcardPatternParser.Parse(WildcardPattern pattern, CharacterNormalizer
characterNormalizer)
à System.Management.Automation.WildcardPatternMatcher..ctor(WildcardPattern wildcardPattern)
à System.Management.Automation.WildcardPattern.Init()
à System.Management.Automation.WildcardPattern.IsMatch(String input)
à System.Management.Automation.LocationGlobber.IsChildNameAMatch(PSObject childObject, WildcardPattern stringMatcher, Collection`1
includeMatcher, Collection`1 excludeMatcher, String& childName)
à System.Management.Automation.LocationGlobber.GenerateNewPSPathsWithGlobLeaf(StringCollection currentDirs, PSDriveInfo drive, String
leafElement, Boolean isLastLeaf, ContainerCmdletProvider provider, CmdletProviderContext context)
à System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path, Boolean allowNonexistingPaths, PSDriveInfo drive,
ContainerCmdletProvider provider, CmdletProviderContext context)
à System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean
allowNonexistingPaths, CmdletProvider& providerInstance)
à System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths,
CmdletProviderContext context, CmdletProvider& providerInstance)
à System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths,
CmdletProviderContext context, ProviderInfo& provider, CmdletProvider& providerInstance)
à System.Management.Automation.SessionStateInternal.GetContentReaderDynamicParameters(String path, CmdletProviderContext context)
à Microsoft.PowerShell.Commands.GetContentCommand.GetDynamicParameters(CmdletProviderContext context)
à Microsoft.PowerShell.Commands.CoreCommandBase.GetDynamicParameters()
à System.Management.Automation.CmdletParameterBinderController.HandleCommandLineDynamicParameters(ParameterBindingException&
outgoingBindingException)
--- Fin de la trace de la pile d'exception interne ---
à System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean
enumerate)
à System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements,
CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
à lambda_method(Closure , Object[] , StrongBox`1[] , InterpretedFrame )
TargetObject :
CategoryInfo : InvalidArgument : (:«») [Get-Content], ParameterBindingException
FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetContentCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : à <ScriptBlock>, C:\Users\user\Google Drive\ \FICHIERS_DE_REFERENCES\ref_win\ps1\ref_pshell\tp_script_dl\1portv2_17012017.ps1 : ligne
64
PipelineIterationInfo : {}
PSMessageDetails :
[/code:1]<br><br>Message édité par: n3m0, à: 17/01/17 17:49

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

Plus d'informations
il y a 9 ans 4 mois #22979 par hays
Bonjour,

je n'ai pas trouvé comment éviter le problème alors je cherche plus à loguer le message d'erreur mais j'ai un problème de compréhension concernant le try catch finaly
[code:1]
try {
je met mon code à protéger dans le try
}
[/code:1]
[code:1]
catch [type erreur 1] { je mets l'instruction à exécuter en cas d'erreur 1}

catch [type erreur 2]{ je mets l'instruction à exécuter en cas d'erreur 2}
catch [type erreur 3]{ je mets l'instruction à exécuter en cas d'erreur 3}
[/code:1]

En revanche est-ce que le script s’arrête systématiquement ? c'est l'effet que j'avais lors de mes tests...


alors je débute donc je pense que c'est moi qui m'y suis mal pris mais j'aimerais avoir la certitude qu'il soit faisable de faire une erreur et obliger à continuer le script sans arrêter la boucle en plein vol.

merci pour votre retour expérience.

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

Plus d'informations
il y a 9 ans 4 mois #22982 par Philippe
salut n3m0

Comment peut-on ecrire dans un fichier qui est nommé avec des caractère telque ][{ ).

normalement ça ne devrait pas posé de problème
mais tu a option LiteralPath dans la majorité des commandes d'accès a des fichiers
exemple :
[code:1]set-Content -LiteralPath $variable[/code:1]


pour ton utilisation de try/catch regarde l'option ErrorAction qui determine ce que fait PowerShell en cas d'erreur

tu peut retrouvé plus info dans les doc des commandlets

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

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