I whould faccio: creare una funzione per chiamare lo script e reindirizzare l'uscita di questa funzione come questa:
ps1:
function test{
#your simple script commands
ls c:\temp -Filter *.JPG
ls z:\ #non existent dir
}
test *> c:\temp\log.txt
Ecco il file di registro:
Répertoire : C:\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 07/06/2008 11:06 176275 HPIM1427.JPG
-a--- 07/06/2008 11:06 69091 HPIM1428.JPG
-a--- 07/06/2008 11:06 174661 HPIM1429.JPG
ls : Lecteur introuvable. Il n'existe aucun lecteur nommé « z ».
Au caractère C:\temp\test.ps1:14 : 1
+ ls z:\ #non existent dir
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (z:String) [Get-ChildItem], Driv
eNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetC
hildItemCommand
È possibile controllare ciò che si desidera produrre con i nuovi operatori di reindirizzamento V3:
Do-Something 3> warning.txt # Writes warning output to warning.txt
Do-Something 4>> verbose.txt # Appends verbose.txt with the verbose output
Do-Something 5>&1 # Writes debug output to the output stream
Do-Something *> out.txt # Redirects all streams (output, error, warning, verbose, and debug) to out.txt
fonte
2012-12-09 07:36:29
Si potrebbe anche voler usare -Noninteractive per evitare qualsiasi richiesta. – David
Come si aggiunge un timestamp a questo? – Anders
Se qualcuno sa come farlo con gli spazi nei percorsi dei file mi piacerebbe sapere come. Non riesco a ottenere il parser per analizzare correttamente le virgolette doppie, virgolette singole o virgolette di escape. – MrEdmundo