Sortie PowerShell objet en chaîne de caractères
Ce code lance ping:
$ProcessInfo = New-Object System.Diagnostics.ProcessStartInfo
$ProcessInfo.FileName = "ping.exe"
$ProcessInfo.RedirectStandardError = $true
$ProcessInfo.RedirectStandardOutput = $true
$ProcessInfo.UseShellExecute = $false
$ProcessInfo.Arguments = "localhost"
$Proc = New-Object System.Diagnostics.Process
$Proc.StartInfo = $ProcessInfo
$Proc.Start() | Out-Null
Quand je tape $Proc à la commande,
$Proc
J'obtiens ceci:
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
27 3 1936 1852 10 0.02 6832 PING
Je veux obtenir la ligne de données dans une chaîne de caractères.
J'ai donc essayé ceci:
$Proc | Format-table -HideTableHeaders
Et j'ai obtenu ceci:
27 3 1936 1852 10 0.02 6832 PING
J'ai essayé ceci:
$Foo = $Proc | Format-table -HideTableHeaders
$Foo
Et obtenu ceci:
Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
Donc la question est... Comment faites-vous généralement la belle sortie de chaîne à partir d'une powershell objet en chaîne de caractères?
En fin de compte tout ce que je suis en train de faire est de coller le mot de COMMENCER en face de la sortie normal que j'ai quand je viens de type $Proc par lui-même sur une ligne dans mon script powershell.
START 27 3 1936 1852 10 0.02 6832 PING
Mais, "Start" + $Proc produit ceci:
Start System.Diagnostics.Process (PING)
C'est pourquoi j'ai pensé que je pourrais essayer d'obtenir $Proc dans une chaîne.
Out-String
après Format-Table
?OriginalL'auteur johnnycrash | 2014-07-09
Vous devez vous connecter pour publier un commentaire.
Quelque chose comme..
OriginalL'auteur arashid290