Разница между командлетами (по состоянию на powershell-v5.0 ) заключается в том, какой поток они используют для отображения информации.По умолчанию подробный поток (4) не виден , если только не указано -Verbose
, добавьте -Verbose
с помощью автоматического словаря $PSDefaultParameterValues
, чтобы добавить переключатель ко всем или определенным командлетам или установить $VerbosePreference
автоматическая переменная.
Вы можете наблюдать поведение этого потока следующим образом:
PS ~/> Write-Verbose -Message 'Just testing' -Verbose 4>$null
PS ~/> Write-Verbose -Message 'Just testing' -Verbose
VERBOSE: Just testing
Аналогично, командлет Write-Host
использует поток информации (6), который также не отображается по умолчанию., но Write-Host
по сути стал оболочкой для
Write-Information -InformationAction Continue
Этот поток имеет те же требования, что и поток Verbose
, который можно увидеть с переменной предпочтения $InformationPreference
.
Youможно дополнительно наблюдать за этими объектами, присваивая их выходные данные:
PS ~/> $output = Write-Verbose -Message test -Verbose 4>&1
PS ~/> $output | Get-Member
TypeName: System.Management.Automation.VerboseRecord
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
WriteVerboseStream NoteProperty bool WriteVerboseStream=True
InvocationInfo Property System.Management.Automation.InvocationInfo InvocationInfo {get;}
Message Property string Message {get;set;}
PipelineIterationInfo Property System.Collections.ObjectModel.ReadOnlyCollection[int] PipelineIterationInfo
PS ~/> $output = Write-Host -Object test 6>&1
PS ~/> $output | Get-Member
TypeName: System.Management.Automation.InformationRecord
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
WriteInformationStream NoteProperty bool WriteInformationStream=True
Computer Property string Computer {get;set;}
ManagedThreadId Property uint ManagedThreadId {get;set;}
MessageData Property System.Object MessageData {get;}
NativeThreadId Property uint NativeThreadId {get;set;}
ProcessId Property uint ProcessId {get;set;}
Source Property string Source {get;set;}
Tags Property System.Collections.Generic.List[string] Tags {get;}
TimeGenerated Property datetime TimeGenerated {get;set;}
User Property string User {get;set;}
Допустимые значения для переменных предпочтения таковы:
[System.Management.Automation.ActionPreference].GetEnumValues()