Server : Apache/2.4.43 (Win64) OpenSSL/1.1.1g PHP/7.4.6 System : Windows NT USER-PC 6.1 build 7601 (Windows 7 Professional Edition Service Pack 1) AMD64 User : User ( 0) PHP Version : 7.4.6 Disable Function : NONE Directory : C:/Windows/SysWOW64/WindowsPowerShell/v1.0/zh-TW/ |
<?xml version="1.0" encoding="utf-8"?> <helpItems schema="maml"> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Add-Member </command:name> <maml:description> <maml:para>為 Windows PowerShell 物件的執行個體加入使用者定義的自訂成員。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Add</command:verb> <command:noun>Member</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Add-Member Cmdlet 會為 Windows PowerShell 物件的執行個體新增使用者定義的自訂成員。它可讓您加入下列成員類型:AliasProperty、CodeProperty、NoteProperty、ScriptProperty、PropertySet、CodeMethod、MemberSet 和 ScriptMethod。您可以使用 Value 參數來設定成員的初始值。如果是 AliasProperty、ScriptProperty、CodeProperty 和 CodeMethod,則可以使用 SecondValue 參數來提供其他資訊。 其他的成員會加入至您經由管道輸出至 Add-Member 或是使用 InputObject 參數所指定的特定物件執行個體中。其他的成員只有在該執行個體存在時才能使用。您可以使用 Export-Clixml Cmdlet,將執行個體 (包括其他成員) 儲存至檔案。Import-Clixml Cmdlet 則可以使用該檔案中儲存的資訊來重新建立物件執行個體。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Add-Member</maml:name> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="1"> <maml:name>MemberType</maml:name> <maml:description> <maml:para>指定要新增的成員型別。此參數是必要的。 此參數的有效值為: -- AliasProperty:為現有屬性定義新名稱的屬性。 -- CodeMethod:參考 Microsoft .NET Framework 類別之靜態方法的某個方法。 -- CodeProperty:參考 .NET Framework 類別之靜態屬性的某個屬性。 -- MemberSet:屬性及方法的預先定義的集合,例如 PSBase、PSObject 和 PSTypeNames。 -- Method:基礎 .NET Framework 物件的方法。 -- NoteProperty:有靜態值的屬性。 -- ParameterizedProperty:接受參數和參數值的屬性。 -- Property:基礎 .NET Framework 物件的屬性。 -- PropertySet:物件屬性的預先定義的集合。 -- ScriptMethod:值為指令碼輸出的方法。 -- ScriptProperty:值為指令碼輸出的屬性。 -- All:取得所有成員型別。 -- Methods:取得物件方法的所有型別 (例如 method、codemethod、scriptmethod) -- Properties:取得物件屬性的所有型別 (例如 property、codeproperty、aliasproperty、scriptproperty)。 並不是所有物件都有全部的成員型別。如果指定物件所沒有的成員型別,Windows PowerShell 就會傳回錯誤。 Event 成員型別不適用於 Add-Member。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">AliasProperty</command:parameterValue> <command:parameterValue required="false" variableLength="false">CodeProperty</command:parameterValue> <command:parameterValue required="false" variableLength="false">Property</command:parameterValue> <command:parameterValue required="false" variableLength="false">NoteProperty</command:parameterValue> <command:parameterValue required="false" variableLength="false">ScriptProperty</command:parameterValue> <command:parameterValue required="false" variableLength="false">Properties</command:parameterValue> <command:parameterValue required="false" variableLength="false">PropertySet</command:parameterValue> <command:parameterValue required="false" variableLength="false">Method</command:parameterValue> <command:parameterValue required="false" variableLength="false">CodeMethod</command:parameterValue> <command:parameterValue required="false" variableLength="false">ScriptMethod</command:parameterValue> <command:parameterValue required="false" variableLength="false">Methods</command:parameterValue> <command:parameterValue required="false" variableLength="false">ParameterizedProperty</command:parameterValue> <command:parameterValue required="false" variableLength="false">MemberSet</command:parameterValue> <command:parameterValue required="false" variableLength="false">Event</command:parameterValue> <command:parameterValue required="false" variableLength="false">All</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定所加入成員的名稱。 如果省略 "Name" 參數名稱,-Name 參數的值就必須是命令中第二個未具名的參數值。如果包含參數名稱,則可依任意順序列出參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要加入新成員的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Value</maml:name> <maml:description> <maml:para>指定所加入成員的初始值。如果加入的是 AliasProperty、CodeProperty 或 CodeMethod 成員,則可使用 SecondValue 參數提供其他選擇性資訊。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="4"> <maml:name>SecondValue</maml:name> <maml:description> <maml:para>指定有關 AliasProperty、ScriptProperty、CodeProperty 或 CodeMethod 成員的其他選擇性資訊。若在加入 AliasProperty 時使用,則此參數必須是資料類型。AliasProperty 的值會經過轉換成為指定的資料類型。例如,若您加入 AliasProperty 以提供字串屬性的替代名稱,便可將 SecondValue 參數指定為 System.Int32,表示每當使用對應的 AliasProperty 存取該字串屬性時,都應該將其值轉換成整數。 加入 ScriptProperty 成員時可以使用 SecondValue 參數額外指定 ScriptBlock。在此情況下,便會使用 Value 參數內指定的第一個 ScriptBlock 來取得變數的值。SecondValue 參數內指定的第二個 ScriptBlock 會用來設定變數的值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>即使已有名稱相同的成員,亦強制加入新成員。不適用於類型的核心成員。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>將新擴充的物件傳遞給管線。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>即使已有名稱相同的成員,亦強制加入新成員。不適用於類型的核心成員。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要加入新成員的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="false" position="1"> <maml:name>MemberType</maml:name> <maml:description> <maml:para>指定要新增的成員型別。此參數是必要的。 此參數的有效值為: -- AliasProperty:為現有屬性定義新名稱的屬性。 -- CodeMethod:參考 Microsoft .NET Framework 類別之靜態方法的某個方法。 -- CodeProperty:參考 .NET Framework 類別之靜態屬性的某個屬性。 -- MemberSet:屬性及方法的預先定義的集合,例如 PSBase、PSObject 和 PSTypeNames。 -- Method:基礎 .NET Framework 物件的方法。 -- NoteProperty:有靜態值的屬性。 -- ParameterizedProperty:接受參數和參數值的屬性。 -- Property:基礎 .NET Framework 物件的屬性。 -- PropertySet:物件屬性的預先定義的集合。 -- ScriptMethod:值為指令碼輸出的方法。 -- ScriptProperty:值為指令碼輸出的屬性。 -- All:取得所有成員型別。 -- Methods:取得物件方法的所有型別 (例如 method、codemethod、scriptmethod) -- Properties:取得物件屬性的所有型別 (例如 property、codeproperty、aliasproperty、scriptproperty)。 並不是所有物件都有全部的成員型別。如果指定物件所沒有的成員型別,Windows PowerShell 就會傳回錯誤。 Event 成員型別不適用於 Add-Member。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSMemberTypes</command:parameterValue> <dev:type> <maml:name>PSMemberTypes</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定所加入成員的名稱。 如果省略 "Name" 參數名稱,-Name 參數的值就必須是命令中第二個未具名的參數值。如果包含參數名稱,則可依任意順序列出參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>將新擴充的物件傳遞給管線。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="4"> <maml:name>SecondValue</maml:name> <maml:description> <maml:para>指定有關 AliasProperty、ScriptProperty、CodeProperty 或 CodeMethod 成員的其他選擇性資訊。若在加入 AliasProperty 時使用,則此參數必須是資料類型。AliasProperty 的值會經過轉換成為指定的資料類型。例如,若您加入 AliasProperty 以提供字串屬性的替代名稱,便可將 SecondValue 參數指定為 System.Int32,表示每當使用對應的 AliasProperty 存取該字串屬性時,都應該將其值轉換成整數。 加入 ScriptProperty 成員時可以使用 SecondValue 參數額外指定 ScriptBlock。在此情況下,便會使用 Value 參數內指定的第一個 ScriptBlock 來取得變數的值。SecondValue 參數內指定的第二個 ScriptBlock 會用來設定變數的值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Value</maml:name> <maml:description> <maml:para>指定所加入成員的初始值。如果加入的是 AliasProperty、CodeProperty 或 CodeMethod 成員,則可使用 SecondValue 參數提供其他選擇性資訊。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件類型輸出至 Add-Member。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Object</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 PassThru 參數時,Add-Member 會傳回新擴充的物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您只能將成員加入至 PSObject 物件。若要判斷物件是否為 PSObject 物件,請使用 "is" 運算子。例如,若要測試 $obj 變數中儲存的物件,可以輸入 "$obj -is [PSObject]"。 MemberType、Name、Value 及 SecondValue 參數的名稱為選擇性。如果省略參數名稱,就必須依此順序列出未具名的參數值:MemberType、Name、Value、SecondValue。如果包含參數名稱,則可依任意順序列出參數。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = (get-childitem)[0] C:\PS> $a | add-member -membertype noteproperty -name Status -value done C:\PS> $a | get-member -type noteproperty TypeName: System.IO.DirectoryInfo Name MemberType Definition ---- ---------- ---------- PSChildName NoteProperty System.String PSChildName=Co PSDrive NoteProperty System.Management.Automation PSIsContainer NoteProperty System.Boolean PSIsContainer PSParentPath NoteProperty System.String PSParentPath=M PSPath NoteProperty System.String PSPath=Microso PSProvider NoteProperty System.Management.Automation Status NoteProperty System.String Status=done </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將 Status note 屬性加入至 Get-ChildItem 所傳回的 DirectoryInfo 物件中,並為它指派 "done" 的值。 第一個命令會取得 Get-Childitem 所傳回的第一個物件 (索引 0)。 第二個命令會加入 note 屬性。 第三個命令會使用管線運算子 (|),將更新的物件傳送到 Get-Member Cmdlet。輸出會顯示已經加入此屬性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = (get-childitem)[0] C:\PS> $a | add-member -membertype aliasproperty -name FileLength -value Length C:\PS> $a.filelength </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將 FileLength alias 屬性加入至 Get-ChildItem 所傳回的 DirectoryInfo 物件。新的屬性是 Length 屬性的別名。 第一個命令會取得 Get-Childitem 所傳回的第一個物件 (索引 0)。 第二個命令會加入 alias 屬性。 第三個命令會傳回新 FileLength 屬性的值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = "a string" C:\PS> $a = $a | add-member -membertype noteproperty -name StringUse -value Display -passthru C:\PS> $a.StringUse </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將 StringUse 屬性加入至字串。因為此字串並非 PSObject 物件,所以您必須在命令中指定 PassThru 參數,才能將擴充的字串儲存到變數中。範例中的最後一個命令會顯示新的屬性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = "this is a string" C:\PS> $a = add-member -inputobject $a -membertype scriptmethod -name words ` -value {$this.split()} -passthru C:\PS> $a.words() </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將指令碼方法加入至字串物件。這個指令碼方法公開 System.String .NET Framework 類別庫類別的 Split() 方法,可讓您很方便地藉由呼叫字串物件上名為 "Words" 的方法,傳回字串中的個別單字。請注意,指定 PassThru 參數是為了強制 Add-Member 將擴充的字串物件當做輸出傳回,以便儲存至 $a 變數中。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $event = get-eventlog -logname system -newest 1 C:\PS> $event.TimeWritten | get-member C:\PS> add-member -inputobject $event -membertype aliasproperty -name When ` -value TimeWritten -secondvalue System.String C:\PS> $event.When | get-member </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將 AliasProperty 加入至 Get-EventLog Cmdlet 所傳回的 EventLogEntry 物件。AliasProperty 的名稱為 "When",而且是物件之 TimeWritten 屬性的別名。SecondValue 參數是用來指定:當使用 AliasProperty 存取屬性值時,必須將它轉換為類型 System.String;TimeWritten 屬性為 DateTime 物件。 第一個命令會使用 Get-EventLog Cmdlet,從系統事件記錄檔擷取最新的事件,並將它儲存在 $event 變數中。 第二個命令會存取該事件的 TimeWritten 屬性,並經由管道將它輸入至 Get-Member Cmdlet,表明該屬性為 DateTime 類型。然後使用 Add-Member 將 AliasProperty 成員加入至儲存於 $event 變數的 EventLogEntry 物件執行個體。Name 參數用於將新成員的名稱設定為 "When",而 Value 參數則用於指定此成員是 TimeWritten 屬性的別名。SecondValue 參數用來表示:使用這個新成員時,應該將它傳回的值從原始的 System.DateTime 類型轉換為 System.String 類型。 第三個命令會存取新成員,並經由管道將它輸入至 Get-Member Cmdlet,以確認它屬於類型 System.String。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> function Copy-Property ($From, $To) { foreach ($p in Get-Member -InputObject $From -MemberType Property) { Add-Member -InputObject $To -MemberType NoteProperty -Name $p.Name -Value $From.$($p.Name) -Force $To.$($p.Name) = $From.$($p.Name) } } </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個函數會將一個物件的所有屬性複製到另一個物件。 函數的第一個命令會宣告此函數名稱,並列出其參數。 Foreach 迴圈會使用 Get-Member Cmdlet 取得 From 物件的每個屬性。而 Foreach 迴圈內的命令會連續在每個屬性上執行。 Add-Member 命令會將 From 物件的屬性加入至 To 物件當做 NoteProperty。它會使用 Force 參數讓此命令加入同名的成員。 函數的最後一個命令是將新屬性命名為與原始屬性同名。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113280</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Member</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-Clixml</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-Clixml</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Add-Type </command:name> <maml:description> <maml:para>將 Microsoft .NET Framework 型別 (類別) 加入至 Windows PowerShell 工作階段。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Add</command:verb> <command:noun>Type</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Add-Type Cmdlet 能讓您在 Windows PowerShell 工作階段中定義 .NET Framework 類別。然後您可以具現化物件 (利用 New-Object Cmdlet) 並使用這些物件,就像使用任何 .NET Framework 物件一樣。如果將 Add-Type 命令新增到 Windows PowerShell 設定檔,就可以在所有 Windows PowerShell 工作階段中使用該類別。 您不僅可以透過指定現有的組件或原始程式碼檔來指定型別,也可以指定內嵌原始程式碼或儲存在變數中的原始程式碼。您甚至可以只指定方法,Add-Type 就會定義並產生類別。您可以在 Windows PowerShell 中使用此功能,對 Unmanaged 函數進行平台叫用 (P/Invoke) 呼叫。如果您指定原始程式碼,Add-Type 會編譯指定的原始程式碼,並在記憶體中產生包含新 .NET Framework 型別的組件。 您可以使用 Add-Type 的參數,指定替代語言和編譯器 (預設為 CSharp)、編譯器選項、組件相依性、類別命名空間、型別名稱和產生的組件。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Add-Type</maml:name> <command:parameter required="true" variableLength="true" globbing="true" pipelineInput="false" position="named"> <maml:name>AssemblyName</maml:name> <maml:description> <maml:para>指定包含型別的組件名稱。Add-Type 會從指定的組件取得型別。當您根據組件名稱建立型別時,必須提供此參數。 請輸入組件的完整名稱或簡單名稱 (也稱為「部分名稱」)。在組件名稱中允許使用萬用字元。如果輸入簡單名稱或部分名稱,Add-Type 會將其解析成完整名稱,然後以完整名稱來載入組件。 此參數不接受路徑或檔名。若要輸入組件動態連結程式庫 (DLL) 檔的路徑,請使用 Path 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IgnoreWarnings</maml:name> <maml:description> <maml:para>忽略編譯器警告。此參數可用來避免 Add-Type 將編譯器警告當做錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已加入之型別的 System.Runtime 物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Add-Type</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定要建立的類別名稱。當從成員定義產生型別時,必須提供此參數。 型別名稱和命名空間在工作階段內必須是唯一的。您無法卸載或變更型別。如果需要為型別變更程式碼,則必須變更名稱或啟動新的 Windows PowerShell 工作階段,否則命令會失敗。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="2"> <maml:name>MemberDefinition</maml:name> <maml:description> <maml:para>為類別指定新的屬性或方法。Add-Type 會產生支援屬性或方法所需的範本程式碼。 您可以在 Windows PowerShell 中使用此功能,對 Unmanaged 函數進行平台叫用 (P/Invoke) 呼叫。如需詳細資訊,請參閱範例。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CodeDomProvider</maml:name> <maml:description> <maml:para>指定程式碼產生器或編譯器。Add-Type 會以指定的編譯器來編譯原始程式碼。預設為 CSharp 編譯器。如果您使用無法以 Language 參數指定的語言,請使用 CodeDomProvider 參數。您所指定的 CodeDomProvider 必須能夠從原始程式碼產生組件。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CodeDomProvider</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CompilerParameters</maml:name> <maml:description> <maml:para>為原始程式碼編譯器指定選項。這些選項會在不修改的情況下傳送給編譯器。 此參數可讓您指示編譯器產生可執行檔、嵌入資源或設定命令列選項,例如 "/unsafe" 選項。此參數會實作 CompilerParameters 類別 (System.CodeDom.Compiler.CompilerParameters)。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CompilerParameters</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Language</maml:name> <maml:description> <maml:para>指定原始程式碼中使用的語言。Add-Type 會以語言來選取正確的語言編譯器。 有效的值包括 "CSharp"、"CSharpVersion3"、"VisualBasic" 和 "JScript"。預設為 "CSharp"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">CSharp</command:parameterValue> <command:parameterValue required="false" variableLength="false">CSharpVersion3</command:parameterValue> <command:parameterValue required="false" variableLength="false">VisualBasic</command:parameterValue> <command:parameterValue required="false" variableLength="false">JScript</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Namespace</maml:name> <maml:description> <maml:para>為型別指定命名空間。 如果未在命令中包含此參數,則會在 Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes 命名空間中建立型別。如果在命令中包含此參數並為其加上空字串或 $null 值,則會在全域命名空間中產生型別。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="true" pipelineInput="false" position="named"> <maml:name>OutputAssembly</maml:name> <maml:description> <maml:para>為有指定之名稱的組件在位置中產生 DLL 檔。請輸入路徑 (選擇性) 和檔名。允許使用萬用字元。根據預設,Add-Type 只會在記憶體中產生組件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>OutputType</maml:name> <maml:description> <maml:para>指定輸出組件的輸出類型。有效的值為 Library、ConsoleApplication 和 WindowsApplication。 根據預設,不會指定任何輸出類型。 只有當命令中指定了輸出組件時,這個參數才有效。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">OutputAssemblyType</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>ReferencedAssemblies</maml:name> <maml:description> <maml:para>指定型別相依的組件。根據預設,Add-Type 會參考 System.dll 和 System.Management.Automation.dll。除預設組件之外,它還會參考使用此參數所指定的組件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>UsingNamespace</maml:name> <maml:description> <maml:para>指定類別所需的其他命名空間。此參數與 C# 的 "Using" 關鍵字相當類似。 根據預設,Add-Type 會參考 System 命名空間。當使用 MemberDefinition 參數時,Add-Type 預設也會參考 System.Runtime.InteropServices 命名空間。除預設命名空間之外,它還會參考使用 UsingNamespace 參數所新增的命名空間。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IgnoreWarnings</maml:name> <maml:description> <maml:para>忽略編譯器警告。此參數可用來避免 Add-Type 將編譯器警告當做錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已加入之型別的 System.Runtime 物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Add-Type</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定包含型別之原始程式碼檔或組件 DLL 檔的路徑。 如果您送出原始程式碼檔,Add-Type 會編譯當中的程式碼,並在記憶體中建立型別的組件。Path 的值中指定的副檔名會決定 Add-Type 使用的編譯器。 如果您送出組件檔,Add-Type 會從組件取得型別。若要指定記憶體中的組件或是全域組件快取,請使用 AssemblyName 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CompilerParameters</maml:name> <maml:description> <maml:para>為原始程式碼編譯器指定選項。這些選項會在不修改的情況下傳送給編譯器。 此參數可讓您指示編譯器產生可執行檔、嵌入資源或設定命令列選項,例如 "/unsafe" 選項。此參數會實作 CompilerParameters 類別 (System.CodeDom.Compiler.CompilerParameters)。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CompilerParameters</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="true" pipelineInput="false" position="named"> <maml:name>OutputAssembly</maml:name> <maml:description> <maml:para>為有指定之名稱的組件在位置中產生 DLL 檔。請輸入路徑 (選擇性) 和檔名。允許使用萬用字元。根據預設,Add-Type 只會在記憶體中產生組件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>OutputType</maml:name> <maml:description> <maml:para>指定輸出組件的輸出類型。有效的值為 Library、ConsoleApplication 和 WindowsApplication。 根據預設,不會指定任何輸出類型。 只有當命令中指定了輸出組件時,這個參數才有效。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">OutputAssemblyType</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>ReferencedAssemblies</maml:name> <maml:description> <maml:para>指定型別相依的組件。根據預設,Add-Type 會參考 System.dll 和 System.Management.Automation.dll。除預設組件之外,它還會參考使用此參數所指定的組件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IgnoreWarnings</maml:name> <maml:description> <maml:para>忽略編譯器警告。此參數可用來避免 Add-Type 將編譯器警告當做錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已加入之型別的 System.Runtime 物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Add-Type</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>TypeDefinition</maml:name> <maml:description> <maml:para>指定包含型別定義的原始程式碼。請在字串或 here-string 中輸入原始程式碼,或是輸入包含原始程式碼的變數。如需 here-string 的詳細資訊,請參閱 about_Quoting_Rules。 請在您的型別定義中加上命名空間宣告。如果省略命名空間宣告的話,您的型別可能會與另一個型別或另一個型別的捷徑同名,而導致意外覆寫。例如,若定義一個稱為 "Exception" 的型別,則以 "Exception" 當做 System.Exception 之捷徑的指令碼將會失敗。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CodeDomProvider</maml:name> <maml:description> <maml:para>指定程式碼產生器或編譯器。Add-Type 會以指定的編譯器來編譯原始程式碼。預設為 CSharp 編譯器。如果您使用無法以 Language 參數指定的語言,請使用 CodeDomProvider 參數。您所指定的 CodeDomProvider 必須能夠從原始程式碼產生組件。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CodeDomProvider</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CompilerParameters</maml:name> <maml:description> <maml:para>為原始程式碼編譯器指定選項。這些選項會在不修改的情況下傳送給編譯器。 此參數可讓您指示編譯器產生可執行檔、嵌入資源或設定命令列選項,例如 "/unsafe" 選項。此參數會實作 CompilerParameters 類別 (System.CodeDom.Compiler.CompilerParameters)。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CompilerParameters</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Language</maml:name> <maml:description> <maml:para>指定原始程式碼中使用的語言。Add-Type 會以語言來選取正確的語言編譯器。 有效的值包括 "CSharp"、"CSharpVersion3"、"VisualBasic" 和 "JScript"。預設為 "CSharp"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">CSharp</command:parameterValue> <command:parameterValue required="false" variableLength="false">CSharpVersion3</command:parameterValue> <command:parameterValue required="false" variableLength="false">VisualBasic</command:parameterValue> <command:parameterValue required="false" variableLength="false">JScript</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="true" pipelineInput="false" position="named"> <maml:name>OutputAssembly</maml:name> <maml:description> <maml:para>為有指定之名稱的組件在位置中產生 DLL 檔。請輸入路徑 (選擇性) 和檔名。允許使用萬用字元。根據預設,Add-Type 只會在記憶體中產生組件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>OutputType</maml:name> <maml:description> <maml:para>指定輸出組件的輸出類型。有效的值為 Library、ConsoleApplication 和 WindowsApplication。 根據預設,不會指定任何輸出類型。 只有當命令中指定了輸出組件時,這個參數才有效。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">OutputAssemblyType</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>ReferencedAssemblies</maml:name> <maml:description> <maml:para>指定型別相依的組件。根據預設,Add-Type 會參考 System.dll 和 System.Management.Automation.dll。除預設組件之外,它還會參考使用此參數所指定的組件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IgnoreWarnings</maml:name> <maml:description> <maml:para>忽略編譯器警告。此參數可用來避免 Add-Type 將編譯器警告當做錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已加入之型別的 System.Runtime 物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="true" globbing="true" pipelineInput="false" position="named"> <maml:name>AssemblyName</maml:name> <maml:description> <maml:para>指定包含型別的組件名稱。Add-Type 會從指定的組件取得型別。當您根據組件名稱建立型別時,必須提供此參數。 請輸入組件的完整名稱或簡單名稱 (也稱為「部分名稱」)。在組件名稱中允許使用萬用字元。如果輸入簡單名稱或部分名稱,Add-Type 會將其解析成完整名稱,然後以完整名稱來載入組件。 此參數不接受路徑或檔名。若要輸入組件動態連結程式庫 (DLL) 檔的路徑,請使用 Path 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CodeDomProvider</maml:name> <maml:description> <maml:para>指定程式碼產生器或編譯器。Add-Type 會以指定的編譯器來編譯原始程式碼。預設為 CSharp 編譯器。如果您使用無法以 Language 參數指定的語言,請使用 CodeDomProvider 參數。您所指定的 CodeDomProvider 必須能夠從原始程式碼產生組件。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CodeDomProvider</command:parameterValue> <dev:type> <maml:name>CodeDomProvider</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>CSharp 編譯器</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CompilerParameters</maml:name> <maml:description> <maml:para>為原始程式碼編譯器指定選項。這些選項會在不修改的情況下傳送給編譯器。 此參數可讓您指示編譯器產生可執行檔、嵌入資源或設定命令列選項,例如 "/unsafe" 選項。此參數會實作 CompilerParameters 類別 (System.CodeDom.Compiler.CompilerParameters)。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CompilerParameters</command:parameterValue> <dev:type> <maml:name>CompilerParameters</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IgnoreWarnings</maml:name> <maml:description> <maml:para>忽略編譯器警告。此參數可用來避免 Add-Type 將編譯器警告當做錯誤。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Language</maml:name> <maml:description> <maml:para>指定原始程式碼中使用的語言。Add-Type 會以語言來選取正確的語言編譯器。 有效的值包括 "CSharp"、"CSharpVersion3"、"VisualBasic" 和 "JScript"。預設為 "CSharp"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Language</command:parameterValue> <dev:type> <maml:name>Language</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>CSharp</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="2"> <maml:name>MemberDefinition</maml:name> <maml:description> <maml:para>為類別指定新的屬性或方法。Add-Type 會產生支援屬性或方法所需的範本程式碼。 您可以在 Windows PowerShell 中使用此功能,對 Unmanaged 函數進行平台叫用 (P/Invoke) 呼叫。如需詳細資訊,請參閱範例。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定要建立的類別名稱。當從成員定義產生型別時,必須提供此參數。 型別名稱和命名空間在工作階段內必須是唯一的。您無法卸載或變更型別。如果需要為型別變更程式碼,則必須變更名稱或啟動新的 Windows PowerShell 工作階段,否則命令會失敗。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Namespace</maml:name> <maml:description> <maml:para>為型別指定命名空間。 如果未在命令中包含此參數,則會在 Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes 命名空間中建立型別。如果在命令中包含此參數並為其加上空字串或 $null 值,則會在全域命名空間中產生型別。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="true" pipelineInput="false" position="named"> <maml:name>OutputAssembly</maml:name> <maml:description> <maml:para>為有指定之名稱的組件在位置中產生 DLL 檔。請輸入路徑 (選擇性) 和檔名。允許使用萬用字元。根據預設,Add-Type 只會在記憶體中產生組件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>OutputType</maml:name> <maml:description> <maml:para>指定輸出組件的輸出類型。有效的值為 Library、ConsoleApplication 和 WindowsApplication。 根據預設,不會指定任何輸出類型。 只有當命令中指定了輸出組件時,這個參數才有效。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">OutputAssemblyType</command:parameterValue> <dev:type> <maml:name>OutputAssemblyType</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已加入之型別的 System.Runtime 物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定包含型別的原始程式碼檔或組件 DLL 檔之路徑。 如果您送出原始程式碼檔,Add-Type 會編譯當中的程式碼,並在記憶體中建立型別的組件。Path 的值中指定的副檔名會決定 Add-Type 使用的編譯器。 如果您送出組件檔,Add-Type 會從組件取得型別。若要指定記憶體中的組件或是全域組件快取,請使用 AssemblyName 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>ReferencedAssemblies</maml:name> <maml:description> <maml:para>指定型別相依的組件。根據預設,Add-Type 會參考 System.dll 和 System.Management.Automation.dll。除預設組件之外,它還會參考使用此參數所指定的組件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>TypeDefinition</maml:name> <maml:description> <maml:para>指定包含型別定義的原始程式碼。請在字串或 here-string 中輸入原始程式碼,或是輸入包含原始程式碼的變數。如需 here-string 的詳細資訊,請參閱 about_Quoting_Rules。 請在您的型別定義中加上命名空間宣告。如果省略命名空間宣告的話,您的型別可能會與另一個型別或另一個型別的捷徑同名,而導致意外覆寫。例如,若定義一個稱為 "Exception" 的型別,則以 "Exception" 當做 System.Exception 之捷徑的指令碼將會失敗。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>UsingNamespace</maml:name> <maml:description> <maml:para>指定類別所需的其他命名空間。此參數與 C# 的 "Using" 關鍵字相當類似。 根據預設,Add-Type 會參考 System 命名空間。當使用 MemberDefinition 參數時,Add-Type 預設也會參考 System.Runtime.InteropServices 命名空間。除預設命名空間之外,它還會參考使用 UsingNamespace 參數所新增的命名空間。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將物件輸出至 Add-Type。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.RuntimeType</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 PassThru 參數時,Add-Type 會傳回代表新型別的 System.RuntimeType 物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您所加入的型別只存在於目前的工作階段中。若要在所有工作階段中使用這些型別,請將它們新增到 Windows PowerShell 設定檔。如需設定檔的詳細資訊,請參閱 about_Profiles。 型別名稱 (和命名空間) 在工作階段內必須是唯一的。您無法卸載或變更型別。如果需要為型別變更程式碼,則必須變更名稱或啟動新的 Windows PowerShell 工作階段,否則命令會失敗。 有些語言 (如 IronPython 和 JSharp) 的 CodeDomProvider 類別並不會產生輸出,因此用這些語言撰寫的型別不能與 Add-Type 搭配使用。 此 Cmdlet 是以 CodeDomProvider 類別基礎。如需這個類別的詳細資訊,請參閱 Microsoft .NET Framework SDK。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $source = @" public class BasicTest { public static int Add(int a, int b) { return (a + b); } public int Multiply(int a, int b) { return (a * b); } } "@ C:\PS> Add-Type -TypeDefinition $source C:\PS> [BasicTest]::Add(4, 3) C:\PS> $basicTestObject = New-Object BasicTest C:\PS> $basicTestObject.Multiply(5, 2) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會藉由指定儲存在變數中的原始程式碼,將 BasicTest 類別加入至工作階段。型別有一個稱為 Add 的靜態方法,以及一個稱為 Multiply 的非靜態方法。 第一個命令會將類別的原始程式碼儲存到 $source 變數。 第二個命令會使用 Add-Type Cmdlet 將類別新增到工作階段。因為使用的是內嵌原始程式碼,此命令會使用 TypeDefinition 參數指定 $source 變數中的程式碼。 其他命令則會使用新的類別。 第三個命令會呼叫 BasicTest 類別的 Add 靜態方法,並使用雙冒號字元 (::) 指定類別的靜態成員。 第四個命令會使用 New-Object Cmdlet 將 BasicTest 類別的執行個體具現化,然後將新的物件儲存到 $basicTestObject 變數。 第五個命令會使用 $basicTestObject 的 Multiply 方法。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> [BasicTest] | get-member C:\PS> [BasicTest] | get-member -static C:\PS> $basicTestObject | get-member C:\PS> [BasicTest] | get-member TypeName: System.RuntimeType Name MemberType Definition ---- ---------- ---------- Clone Method System.Object Clone() Equals Method System.Boolean Equals FindInterfaces Method System.Type[] FindInt ... C:\PS> [BasicTest] | get-member -static TypeName: BasicTest Name MemberType Definition ---- ---------- ---------- Add Method static System.Int32 Add(Int32 a, Int32 b) Equals Method static System.Boolean Equals(Object objA, ReferenceEquals Method static System.Boolean ReferenceEquals(Obj C:\PS> $basicTestObject | get-member TypeName: BasicTest Name MemberType Definition ---- ---------- ---------- Equals Method System.Boolean Equals(Object obj) GetHashCode Method System.Int32 GetHashCode() GetType Method System.Type GetType() Multiply Method System.Int32 Multiply(Int32 a, Int32 b) ToString Method System.String ToString() </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會使用 Get-Member Cmdlet 查看上一個範例中所建立的 Add-Type 和 New-Object Cmdlet。 第一個命令會使用 Get-Member Cmdlet 取得 Add-Type 新增到工作階段的 BasicTest 類別的型別和成員。Get-Member 命令會顯示這個類別是 System.RuntimeType 物件,後者是從 System.Object 類別衍生而來。 第二個命令會使用 Get-Member 的 Static 參數取得 BasicTest 類別的靜態屬性和方法。輸出會顯示 Add 方法已包含在其中。 第三個命令會使用 Get-Member 取得儲存在 $BasicTestObject 變數中的物件成員。此為物件執行個體,是透過使用 New-Object Cmdlet 搭配 $BasicType 類別建立的。 輸出會顯示 $basicTestObject 變數的值是 BasicTest 類別的執行個體,而且它有一個稱為 Multiply 的成員。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $accType = add-type -assemblyname accessib* -passthru </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將 Accessibility 組件的類別新增到目前的工作階段,並使用 AssemblyName 參數指定組件的名稱。即使您不確定組件名稱或其拼字,還是可以使用萬用字元取得正確的組件。 這個命令會使用 PassThru 參數產生代表已加入至工作階段之類別的物件,然後將這些物件儲存到 $accType 變數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> add-type -path c:\ps-test\Hello.vb [VBFromFile]::SayHello(", World") # From Hello.vb Public Class VBFromFile Public Shared Function SayHello(sourceName As String) As String Dim myValue As String = "Hello" return myValue + sourceName End Function End Class C:\PS> [VBFromFile]::SayHello(", World") Hello, World </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會使用 Add-Type Cmdlet 將 Hello.vb 檔案中所定義的 VBFromFile 類別新增到目前的工作階段。Hello.vb 檔案的文字會出現在命令輸出中。 第一個命令會使用 Add-Type Cmdlet 將 Hello.vb 檔案中所定義的型別新增到目前的工作階段,並使用 path 參數指定原始程式檔。 第二個命令會呼叫 SayHello 函數,以做為 VBFromFile 類別的靜態方法。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $signature = @" [DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); "@ $showWindowAsync = Add-Type -memberDefinition $signature -name "Win32ShowWindowAsync" -namespace Win32Functions -passThru # Minimize the Windows PowerShell console $showWindowAsync::ShowWindowAsync((Get-Process -id $pid).MainWindowHandle, 2) # Restore it $showWindowAsync::ShowWindowAsync((Get-Process -id $pid).MainWindowHandle, 4) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例中的命令示範如何在 Windows PowerShell 中呼叫原生 Windows API。Add-Type 會使用平台叫用 (P/Invoke) 機制,從 Windows PowerShell 呼叫 User32.dll 中的函數。 第一個命令會將 ShowWindowAsync 函數的 C# 簽章儲存到 $signature 變數 (如需詳細資訊,請參閱 MSDN Library (http://go.microsoft.com/fwlink/?LinkId=143643) 中的<ShowWindowAsync 函數>(英文))。為確保產生的方法會在 Windows PowerShell 工作階段中顯示,"public" 關鍵字已經新增到標準簽章。 第二個命令會使用 Add-Type Cmdlet 將 ShowWindowAsync 函數新增到 Windows PowerShell 工作階段,以做為 Add-Type 所建立之類別的靜態方法。此命令會使用 MemberDefinition 參數指定儲存在 $signature 變數中的方法定義。 也會使用 Name 和 Namespace 參數指定類別的名稱及命名空間,以及使用 PassThru 參數產生代表型別的物件,然後該物件儲存到 $showWindowAsync 變數。 第三個和第四個命令會使用新的 ShowWindowAsync 靜態方法。此方法會接受兩個參數,一個是視窗控制碼,另一個是指定視窗顯示方式的整數。 第三個命令會呼叫 ShowWindowAsync。它會使用 Get-Process Cmdlet 搭配 $pid 自動變數,取得主控目前 Windows PowerShell 工作階段的處理序,然後使用目前處理序的 MainWindowHandle 屬性以及 "2" 這個值,後者代表 SW_MINIMIZE 值。 為了還原視窗,第四個命令會針對視窗位置使用 "4" 這個值,後者代表 SW_RESTORE 值 (SW_MAXIMIZE 為 3)。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> Add-Type -MemberDefinition $jsMethod -Name "PrintInfo" -Language JScript </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 Add-Type Cmdlet 將內嵌 JScript 程式碼的方法新增到 Windows PowerShell 工作階段。這個命令會使用 MemberDefinition 參數送出儲存在 $jsMethod 變數中的原始程式碼、使用 Name 變數指定 Add-Type 為方法所建立之類別的名稱,以及使用 Language 參數指定 JScript 語言。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> Add-Type -Path FSharp.Compiler.CodeDom.dll C:\PS> Add-Type -Path FSharp.Compiler.CodeDom.dll C:\PS> $provider = New-Object Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider C:\PS> $fSharpCode = @" let rec loop n = if n <= 0 then () else begin print_endline (string_of_int n); loop (n-1) end "@ C:\PS> $fsharpType = Add-Type -TypeDefinition $fSharpCode -CodeDomProvider $provider -PassThru | where { $_.IsPublic } C:\PS> $fsharpType::loop(4) 4 3 2 1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用 Add-Type Cmdlet 將 FSharp 程式碼編譯器新增到 Windows PowerShell 工作階段。若要在 Windows PowerShell 中執行這個範例,必須要有隨 FSharp 語言安裝的 FSharp.Compiler.CodeDom.dll。 這個範例中的第一個命令會使用 Add-Type Cmdlet 搭配 Path 參數來指定組件。Add-Type 會取得該組件中的型別。 第二個命令會使用 New-Object Cmdlet 建立 FSharp 程式碼提供者的執行個體,然後將結果儲存到 $provider 變數。 第三個命令會將定義 Loop 方法的 FSharp 程式碼儲存到 $FSharpCode 變數。 第四個命令會使用 Add-Type Cmdlet 將定義在 $fSharpCode 中的公用型別儲存到 $fSharpType 變數。TypeDefinition 參數會指定定義型別的原始程式碼。CodeDomProvider 參數則會指定原始程式碼編譯器。 PassThru 參數會指示 Add-Type 傳回代表型別的執行階段物件,然後管線運算子 (|) 會將該執行階段物件傳送給 Where-Object Cmdlet,讓後者只傳回公用型別。使用 Where-Object 篩選器,是因為 FSharp 提供者會產生非公用型別來支援產生的公用型別。 第五個命令會呼叫 Loop 方法,以做為儲存在 $fSharpType 變數中之型別的靜態方法。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135195</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Add-Member</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Clear-Variable </command:name> <maml:description> <maml:para>刪除變數的值。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Clear</command:verb> <command:noun>Variable</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Clear-Variable Cmdlet 會刪除變數中儲存的資料,但是不刪除變數。結果,變數的值是 Null (空的)。如果變數具有指定的資料或物件類型,Clear-Variable 會保留變數中儲存的物件類型。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Clear-Variable</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定要清除資料的變數名稱。允許使用萬用字元。此參數為必要參數,但參數名稱 ("Name") 則為選擇性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。此參數的值用於限定 Name 參數。輸入名稱元素或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 清除變數,即使它是唯讀的亦然。即便使用 Force 參數,此 Cmdlet 也無法清除常數。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>只清除指定的項目。此參數的值用於限定 Name 參數。輸入名稱元素或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已清除之變數的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定此別名仍屬有效的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。此參數的值用於限定 Name 參數。輸入名稱元素或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 清除變數,即使它是唯讀的亦然。即便使用 Force 參數,此 Cmdlet 也無法清除常數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>只清除指定的項目。此參數的值用於限定 Name 參數。輸入名稱元素或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定要清除資料的變數名稱。允許使用萬用字元。此參數為必要參數,但參數名稱 ("Name") 則為選擇性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已清除之變數的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定此別名仍屬有效的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將物件輸出至 Clear-Variable。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.PSVariable</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 PassThru 參數時,Clear-Variable 會產生代表已清除之變數的 System.Management.Automation.PSVariable 物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 若要一併刪除變數及變數的值,請使用 Remove-Variable 或 Remove-Item。 即使您使用 -Force 參數,Clear-Variable 也不會刪除設定為常數或系統所擁有之變數的值。 如果您要清除的變數不存在,cmdlet 就沒有作用。它不會建立含有 Null 值的變數。 您也可以利用內建的別名 "clv" 來參照 Clear-Variable。如需詳細資訊,請參閱 about_Aliases。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> clear-variable my* -global </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令刪除以 "my" 開頭之全域變數的值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a=3 C:\PS>&{ clear-variable a } C:\PS>$a 3 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令示範,清除子範圍中的變數並不會清除父範圍中的值。第一個命令會將變數 $a 的值設定為 "3"。第二個命令會使用呼叫運算子 (&),在新的範圍中執行 Clear-Variable 命令。此變數在子範圍中被清除 (雖然它不存在),但是在區域範圍中並沒有被清除。第三個命令取得 $a 的值,顯示 "3" 這個值並未受影響。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> clear-variable -name processes </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令刪除 $processes 變數的值。$processes 變數仍然存在,但是值變成 Null。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113285</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Compare-Object </command:name> <maml:description> <maml:para>比較兩組物件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Compare</command:verb> <command:noun>Object</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Compare-Object Cmdlet 會對兩組物件進行比較。一組物件是參考組,而另一組是差異組。 比較結果將指出屬性值是否只在參照組的物件中出現 (以 <= 符號表示)、是否只在差異組的物件中出現 (以 => 符號表示),或者在指定 IncludeEqual 參數的情況下,是否同時出現於兩組物件 (以 == 符號表示)。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Compare-Object</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>ReferenceObject</maml:name> <maml:description> <maml:para>供比較使用的參照物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="2"> <maml:name>DifferenceObject</maml:name> <maml:description> <maml:para>指定與參考物件比較的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CaseSensitive</maml:name> <maml:description> <maml:para>表示比較應區分大小寫。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Culture</maml:name> <maml:description> <maml:para>指定比較所使用的文化特性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ExcludeDifferent</maml:name> <maml:description> <maml:para>只顯示所比較物件結果為相等的特性。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IncludeEqual</maml:name> <maml:description> <maml:para>顯示所比較物件結果為相等的特性。預設情況下,只會顯示參考物件和差異物件之間不同的特性。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳遞有差異的物件給管線。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定參照物件和差異物件所要比較的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SyncWindow</maml:name> <maml:description> <maml:para>定義搜尋區域,在沒有相符的項目時嘗試將順序重新同步。預設值為 [Int32]::MaxValue。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CaseSensitive</maml:name> <maml:description> <maml:para>表示比較應區分大小寫。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Culture</maml:name> <maml:description> <maml:para>指定比較所使用的文化特性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="2"> <maml:name>DifferenceObject</maml:name> <maml:description> <maml:para>指定與參考物件比較的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> <dev:type> <maml:name>PSObject[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ExcludeDifferent</maml:name> <maml:description> <maml:para>只顯示所比較物件結果為相等的特性。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IncludeEqual</maml:name> <maml:description> <maml:para>顯示所比較物件結果為相等的特性。預設情況下,只會顯示參考物件和差異物件之間不同的特性。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳遞有差異的物件給管線。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定參照物件和差異物件所要比較的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>ReferenceObject</maml:name> <maml:description> <maml:para>供比較使用的參照物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> <dev:type> <maml:name>PSObject[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SyncWindow</maml:name> <maml:description> <maml:para>定義搜尋區域,在沒有相符的項目時嘗試將順序重新同步。預設值為 [Int32]::MaxValue。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>[Int32]::MaxValue</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您也可以經由管道將 DifferenceObject 物件輸出至 Compare-Object。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無,或是不同的物件</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 PassThru 參數時,Compare-Object 會傳回不同的物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> compare-object -referenceobject $(get-content C:\test\testfile1.txt) -differenceobject $(get-content C:\test\testfile2.txt) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將兩個文字檔的內容做比較。只顯示出現在某個檔案或另一個檔案中的行,而不是同時出現在兩個檔案中的行。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> compare-object -referenceobject $(get-content C:\Test\testfile1.txt) -differenceobject $(get-content C:\Test\testfile2.txt) -includeequal </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將兩個文字檔內容中的每一行做比較,並顯示兩個檔案內容的所有行,指出每一行出現於檔案的情形:只在 Textfile1.txt 中、只在 Textfile2.txt 中,或同時在兩個檔案中出現。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $processes_before = get-process C:\PS> notepad C:\PS> $processes_after = get-process C:\PS> compare-object -referenceobject $processes_before -differenceobject $processes_after </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將兩組處理序物件做比較。 第一個命令會使用 Get-Process Cmdlet 取得電腦上的處理序,它會將處理序儲存在 $processes_before 變數中。 第二個命令會啟動 [記事本]。 第三個命令會再次使用 Get-Process Cmdlet,並將產生的處理序儲存在 $processes_after 變數中。 第四個命令會使用 Compare-Object Cmdlet 比較兩組處理序物件。它會顯示兩者之間的差異,包括新的 [記事本] 執行個體。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113286</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Group-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Measure-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Sort-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ForEach-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Select-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Tee-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Where-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> ConvertFrom-CSV </command:name> <maml:description> <maml:para>以逗號分隔值 (CSV) 格式將物件屬性轉換成原始物件的 CSV 版本。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>ConvertFrom</command:verb> <command:noun>CSV</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>ConvertFrom-CSV Cmdlet 會從 ConvertTo-CSV Cmdlet 所產生之 CSV 格式的變動長度字串建立物件。 您可以使用 ConvertFrom-CSV Cmdlet 的參數指定欄標頭列 (用來決定產生的物件的屬性名稱)、指定項目分隔符號,或是指示 ConvertFrom-CSV 將目前文化特性的清單分隔符號當成分隔符號。 ConvertFrom-CSV 建立的物件是原始物件的 CSV 版本,而 CSV 物件的屬性值是原始物件的屬性值的字串版本。物件的 CSV 版本沒有任何方法。 您也可以使用 Export-CSV 和 Import-CSV Cmdlet,將物件轉換成檔案中的 CSV 字串 (反之亦然)。除了將 CSV 字串儲存到檔案中以外,這兩個 Cmdlet 與 ConvertTo-CSV 和 ConvertFrom-CSV Cmdlet 都相同。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>ConvertFrom-CSV</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Delimiter</maml:name> <maml:description> <maml:para>指定用來在 CSV 字串中分隔屬性值的分隔符號。預設為逗號 (,)。請輸入字元,例如分號 (:)。若要指定分號 (;),請將其置於引號內。 如果您指定的字元不是 CSV 字串中所使用的分隔字元,ConvertFrom-CSV 會無法從 CSV 字串建立物件,而是會傳回字串。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">char</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要轉換成物件的 CSV 字串。請輸入包含 CSV 字串的變數,或輸入可取得 CSV 字串的命令或運算式。您也可經由管道將 CSV 字串輸出至 ConvertFrom-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Header</maml:name> <maml:description> <maml:para>為匯入的字串指定其他的欄標頭列。欄標頭決定 ConvertFrom-CSV 所建立之物件的屬性名稱。 請輸入逗號分隔欄標頭的清單,並以引號 (單引號或雙引號) 括住每一個項目,但不要以引號括住標頭字串。如果您輸入比實際欄數量還要少的欄標頭,剩餘的欄會沒有標頭。如果輸入比實際欄數量還要多的欄標頭,則會忽略多餘的欄標頭。 使用 Header 參數時,請省略 CSV 字串的欄標頭,否則 ConvertFrom-CSV 會從標頭列的項目建立多餘的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>ConvertFrom-CSV</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UseCulture</maml:name> <maml:description> <maml:para>使用目前文化特性的清單分隔符號做為字串分隔符號。預設為逗號 (,)。 若要尋找文化特性的清單分隔符號,請使用下列命令:(Get-Culture).TextInfo.ListSeparator。如果您指定的字元不是 CSV 字串中所使用的分隔字元,ConvertFrom-CSV 會無法從 CSV 字串建立物件,而是會傳回字串。</maml:para> </maml:description> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要轉換成物件的 CSV 字串。請輸入包含 CSV 字串的變數,或輸入可取得 CSV 字串的命令或運算式。您也可經由管道將 CSV 字串輸出至 ConvertFrom-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Header</maml:name> <maml:description> <maml:para>為匯入的字串指定其他的欄標頭列。欄標頭決定 ConvertFrom-CSV 所建立之物件的屬性名稱。 請輸入逗號分隔欄標頭的清單,並以引號 (單引號或雙引號) 括住每一個項目,但不要以引號括住標頭字串。如果您輸入比實際欄數量還要少的欄標頭,剩餘的欄會沒有標頭。如果輸入比實際欄數量還要多的欄標頭,則會忽略多餘的欄標頭。 使用 Header 參數時,請省略 CSV 字串的欄標頭,否則 ConvertFrom-CSV 會從標頭列的項目建立多餘的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Delimiter</maml:name> <maml:description> <maml:para>指定用來在 CSV 字串中分隔屬性值的分隔符號。預設為逗號 (,)。請輸入字元,例如分號 (:)。若要指定分號 (;),請將其置於引號內。 如果您指定的字元不是 CSV 字串中所使用的分隔字元,ConvertFrom-CSV 會無法從 CSV 字串建立物件,而是會傳回字串。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">char</command:parameterValue> <dev:type> <maml:name>char</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>','</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Header</maml:name> <maml:description> <maml:para>為匯入的字串指定其他的欄標頭列。欄標頭決定 ConvertFrom-CSV 所建立之物件的屬性名稱。 請輸入逗號分隔欄標頭的清單,並以引號 (單引號或雙引號) 括住每一個項目,但不要以引號括住標頭字串。如果您輸入比實際欄數量還要少的欄標頭,剩餘的欄會沒有標頭。如果輸入比實際欄數量還要多的欄標頭,則會忽略多餘的欄標頭。 使用 Header 參數時,請省略 CSV 字串的欄標頭,否則 ConvertFrom-CSV 會從標頭列的項目建立多餘的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要轉換成物件的 CSV 字串。請輸入包含 CSV 字串的變數,或輸入可取得 CSV 字串的命令或運算式。您也可經由管道將 CSV 字串輸出至 ConvertFrom-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> <dev:type> <maml:name>PSObject[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UseCulture</maml:name> <maml:description> <maml:para>使用目前文化特性的清單分隔符號做為字串分隔符號。預設為逗號 (,)。 若要尋找文化特性的清單分隔符號,請使用下列命令:(Get-Culture).TextInfo.ListSeparator。如果您指定的字元不是 CSV 字串中所使用的分隔字元,ConvertFrom-CSV 會無法從 CSV 字串建立物件,而是會傳回字串。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>逗號</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將 CSV 字串輸出至 ConvertFrom-CSV。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> ConvertFrom-CSV 會傳回 CSV 字串中屬性所描述的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 因為匯入的物件是物件型別的 CSV 版本,Windows PowerShell 型別格式化項目 (用來格式化物件型別的非 CSV 版本) 無法識別和格式化這些物件。 使用 CSV 格式,每個物件都會由逗號分隔物件屬性值的清單來代表。屬性值會轉換成字串 (利用物件的 ToString() 方法),所以一般由屬性值的名稱來代表。ConvertTo-Csv 並不會匯出物件的方法。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $p = get-process | convertto-csv C:\PS> $p | convertfrom-csv </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將本機電腦上的處理序轉換成 CSV 格式,然後將其還原成物件格式。 第一個命令會使用 Get-Process Cmdlet 取得本機電腦上的處理序。管線運算子 (|) 會將這些處理序傳送給 ConvertTo-CSV Cmdlet,此 Cmdlet 會將處理序物件轉換成 CSV 格式。CSV 字串會儲存在 $p 變數中。 第二個命令會使用管線運算子將 $p 變數中的 CSV 字串傳送給 ConvertFrom-CSV Cmdlet。此 Cmdlet 會將 CSV 字串轉換成原始處理序物件的 CSV 版本。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $date = get-date | convertto-csv -delimiter ";" C:\PS> convertfrom-csv -inputobject $date -delimiter ";" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將資料物件轉換成 CSV 格式,再轉換成 CSV 物件格式。 第一個命令會使用 Get-Date Cmdlet 取得目前的日期和時間。管線物件 (|) 會將日期傳送給 ConvertTo-CSV Cmdlet,讓後者將日期物件轉換成一連串的 CSV 字串。此命令會使用 Delimiter 參數指定分號分隔符號。字串會儲存在 $date 變數中。 第二個命令會使用 ConvertFrom-CSV Cmdlet 將 $date 變數中的 CSV 字串轉換回物件格式。此命令會使用 InputObject 參數指定 CSV 字串,以及使用 Delimiter 參數指定分號分隔字元。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $j = start-job -scriptblock { get-process } | convertto-csv C:\PS> $header = "MoreData","StatusMessage","Location","Command","State","Finished","InstanceId","SessionId","Name","ChildJobs","Output","Error","Progress","Verbose","Debug","Warning","StateChanged" # Delete header from $j C:\PS> $j = $j[0], $j[2..($j.count - 1)] $j | convertfrom-csv -header $header MoreData : True StatusMessage : Location : localhost Command : get-process State : Running Finished : System.Threading.ManualResetEvent InstanceId : 6fcb6578-7f42-4d93-9f23-9937f6aac1a2 SessionId : 1 Name : Job1 ChildJobs : System.Collections.Generic.List`1[System.Management.Automation.Job] Output : System.Management.Automation.PSDataCollection`1[System.Management.Automation.PSObject] Error : System.Management.Automation.PSDataCollection`1[System.Management.Automation.ErrorRecord] Progress : System.Management.Automation.PSDataCollection`1[System.Management.Automation.ProgressRecord] Verbose : System.Management.Automation.PSDataCollection`1[System.String] Debug : System.Management.Automation.PSDataCollection`1[System.String] Warning : System.Management.Automation.PSDataCollection`1[System.String] StateChanged : </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用 ConvertFrom-Csv 的 Header 參數變更產生之匯入物件內的屬性名稱。 第一個命令會使用 Start-Job Cmdlet 啟動一個在本機電腦上執行 Get-Process 命令的背景工作。管線運算子 (|) 會將產生的工作物件傳送給 ConvertTo-CSV Cmdlet,此 Cmdlet 會將工作物件轉換成 CSV 格式。指派運算子 (=) 會將產生的 CSV 儲存到 $j 變數。 第二個命令會將標頭儲存到 $header 變數。此標頭與預設標頭不同之處在於它以 "MoreData" 來代替 "HasMoreData",而且以 "State" 來代替 "JobStateInfo"。 第三個字串會從 CSV 字串刪除原始標頭 (第二行),並將它傳回給 $j 變數。 第四個命令會使用 ConvertFrom-CSV Cmdlet 將 CSV 字串轉換成工作物件的 CSV 版本,並使用管線運算子將 $j 中的內容傳送給 ConvertFrom-CSV。依照標頭所指定,產生的物件有 "MoreData" 和 "State" 屬性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> (get-culture).textinfo.listseparator C:\PS> ConvertFrom-Csv -inputobject $services -UseCulture </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 ConvertFrom-CSV Cmdlet 轉換 ConvertTo-CSV 已轉換過的服務物件的 CSV 字串,並使用 UseCulture 參數指示 ConvertFrom-CSV 使用目前文化特性的分隔符號 (清單分隔符號)。 使用 UseCulture 參數時,請確定目前文化特性的清單分隔符號與 CSV 字串中使用的分隔符號相符,否則 ConvertFrom-CSV 無法從 CSV 字串產生物件。 在這個範例中,先使用 Get-Culture 命令確認清單分隔符號,然後才使用 ConvertFrom-CSV 命令。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135201</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertTo-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> ConvertFrom-StringData </command:name> <maml:description> <maml:para>將含有一組或多組索引鍵/值的字串轉換成雜湊表。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>ConvertFrom</command:verb> <command:noun>StringData</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>ConvertFrom-StringData Cmdlet 會將含有一組或多組索引鍵/值的字串轉換成雜湊表。因為每組索引鍵/值必須在不同行,通常會使用 here-string 當做輸入格式。 ConvertFrom-StringData Cmdlet 被認為是安全 Cmdlet,可用於指令碼或函數的 DATA 區段。用於 DATA 區段時,字串的內容必須符合 DATA 區段的規則。如需詳細資訊,請參閱 about_Data_Sections。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>ConvertFrom-StringData</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>StringData</maml:name> <maml:description> <maml:para>指定要轉換的字串。您可以直接使用此參數,或經由管道將字串輸出至 ConvertFrom-StringData。參數名稱為選擇性。 這個參數的值必須是括在單引號內的字串 (單引號字串) 或是括在雙引號內的字串 (雙引號字串),或者是包含一組或多組索引鍵/值的 here-string。每一組索引鍵/值都必須在不同行,或者以新行字元 (`n) 分隔。 您可以在字串內加上註解,但是註解不能與索引鍵/值組位於同一行。註解不會包含在雜湊表中。 here-string 是由一行或多行組成的字串,當中的引號會被逐字解譯。如需詳細資訊,請參閱 about_Quoting_Rules。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>StringData</maml:name> <maml:description> <maml:para>指定要轉換的字串。您可以直接使用此參數,或經由管道將字串輸出至 ConvertFrom-StringData。參數名稱為選擇性。 這個參數的值必須是括在單引號內的字串 (單引號字串) 或是括在雙引號內的字串 (雙引號字串),或者是包含一組或多組索引鍵/值的 here-string。每一組索引鍵/值都必須在不同行,或者以新行字元 (`n) 分隔。 您可以在字串內加上註解,但是註解不能與索引鍵/值組位於同一行。註解不會包含在雜湊表中。 here-string 是由一行或多行組成的字串,當中的引號會被逐字解譯。如需詳細資訊,請參閱 about_Quoting_Rules。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含索引鍵/值組的字串輸出至 ConvertFrom-StringData。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Collections.Hashtable</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> ConvertFrom-StringData 會傳回它從索引鍵/值組所建立的雜湊表。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> here-string 是由一行或多行組成的字串,當中的引號會被逐字解譯。如需詳細資訊,請參閱 about_Quoting_Rules。 ConvertFrom-StringData 針對以多國語言顯示使用者訊息的指令碼很有用。您可以使用字典式雜湊表來隔離像資源檔這樣的檔案中的文字字串與程式碼,並且格式化文字字串,以便在翻譯工具中使用。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $here = @' Msg1 = The string parameter is required. Msg2 = Credentials are required for this command. Msg3 = The specified variable does not exist. '@ C:\PS> convertfrom-stringdata -stringdata $here Name Value ---- ----- Msg3 The specified variable does not exist. Msg2 Credentials are required for this command. Msg1 The string parameter is required. </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將以單引號括住的使用者訊息 here-string 轉換成雜湊表。在以單引號括住的字串中,變數不會被值取代,運算式也不會被評估。 第一個命令會建立 here-string,並將它儲存在 $here 變數中。 第二個命令會使用 ConvertFrom-StringData Cmdlet 將 $here 變數中的 here-string 轉換成雜湊表。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $p = @" ISE = Windows PowerShell Integrated Scripting Environment "@ C:\PS> $p | get-member TypeName: System.String Name MemberType Definition ---- ---------- ---------- Clone Method System.Object Clone() ... C:\PS> $hash = convertfrom-stringdata -stringdata $p C:\PS> $hash | get-member TypeName: System.Collections.Hashtable Name MemberType Definition ---- ---------- ---------- Add Method System.Void Add(Object key, Object ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令示範 ConvertFrom-StringData 實際上將 here-string 轉換成雜湊表。 第一個命令會建立以雙引號括住的 here-string (其中含有一組索引鍵/值),然後將其儲存到 $p 變數。 第二個命令會使用管線運算子 (|) 將 $p 變數傳送給 Get-Member Cmdlet。結果會顯示 $p 是字串 (System.String)。 第三個命令會使用 ConvertFrom-StringData Cmdlet 將 $p 變數中的 here-string 轉換成雜湊表,然後將結果儲存到 $hash 變數。 最後一個命令會使用管線運算子 (|) 將 $hash 變數傳送給 Get-Member Cmdlet。結果會顯示 $hash 變數的內容是雜湊表 (System.Collections.Hashtable)。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> convertfrom-stringdata -stringdata @' Name = Disks.ps1 # Category is optional. Category = Storage Cost = Free '@ Name Value ---- ----- Cost Free Category Storage Name Disks.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將包含多組索引鍵/值而且以單引號括住的 here-string 轉換成雜湊表。 在這個命令中,StringData 參數的值是 here-string,而不是含有 here-string 的變數。不過,這兩種格式都有效。 here-string 內包含有關其中一個字串的註解。只要註解與索引鍵/值組位於不同行,註解在字串中就是有效的。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = convertfrom-stringdata -stringdata "Top = Red `n Bottom = Blue" C:\PS> "Top = " + $a.Top Top = Red C:\PS> "Bottom = " + $a.Bottom Bottom = Blue </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會將以一般雙引號括住的字串 (非 here-string) 轉換成雜湊表,然後將其儲存到 $a 變數。 為了滿足每組索引鍵/值必須在不同行的條件,這個範例會以 Windows PowerShell 新行字元 (`n) 來進行分隔。 結果為輸出的雜湊表。其他命令則會顯示輸出。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $TextMsgs = DATA { ConvertFrom-StringData @' Text001 = The $Notebook variable contains the name of the user's system notebook. Text002 = The $MyNotebook variable contains the name of the user's private notebook. '@ } C:\PS> $TextMsgs.Text001 The $Notebook variable contains the name of the user's system notebook. C:\PS> $TextMsgs.Text002 The $MyNotebook variable contains the name of the user's private notebook. </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會顯示指令碼的 DATA 區段中所使用的 ConvertFrom-StringData 命令。在 DATA 區段下的陳述式會向使用者顯示文字。 因為文字內含變數名稱,所以必須置於以單引號括住的字串內,如此變數就會被逐字解譯,而不被帶入變數值。DATA 區段中不允許有變數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $here = @' Msg1 = The string parameter is required. Msg2 = Credentials are required for this command. Msg3 = The specified variable does not exist. '@ C:\PS> $hash = $here | convertfrom-stringdata C:\PS> $hash Name Value ---- ----- Msg3 The specified variable does not exist. Msg2 Credentials are required for this command. Msg1 The string parameter is required. </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範您可以用管線運算子 (|) 將字串傳送給 ConvertFrom-StringData。 第一個命令會將 here-string 儲存到 $here 變數。第二個命令會使用管線運算子 (|) 將 $here 變數傳送給 ConvertFrom-StringData,然後將結果儲存到 $hash 變數。 最後一個命令會顯示 $hash 變數的內容。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113288</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Data_Sections</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Quoting_Rules</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Script_Internationalization</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> ConvertTo-CSV </command:name> <maml:description> <maml:para>將 Microsoft .NET Framework 物件轉換成一連串以逗點分隔值 (CSV) 且長度可變的字串。 </maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>ConvertTo</command:verb> <command:noun>CSV</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>ConvertTo-CSV Cmdlet 會傳回一連串以逗點分隔且長度可變 (CSV) 的字串,代表您所送出的物件。然後您可以使用 ConvertFrom-CSV Cmdlet 從 CSV 字串重新建立物件。產生的物件為原始物件的 CSV 版本,是由屬性值的字串表示所組成,而且沒有任何方法。 您也可以使用 Export-CSV 和 Import-CSV Cmdlet,將 .NET Framework 物件轉換成 CSV 字串 (反之亦然)。Export-CSV 除了將 CSV 字串儲存到檔案中以外,與 ConvertTo-CSV 都相同。 您可以使用 ConvertTo-CSV Cmdlet 的參數指定逗號以外的分隔符號,或是指示 ConvertTo-CSV 使用目前文化特性的預設分隔符號。 如需詳細資訊,請參閱 Export-CSV 和 Notes 區段。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>ConvertTo-CSV</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Delimiter</maml:name> <maml:description> <maml:para>指定分隔屬性值的分隔符號。預設為逗號 (,)。請輸入字元,例如分號 (:)。 若要指定分號 (;),請將其置於引號內。否則,分號會被解譯為命令分隔符號。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">char</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要匯出成 CSV 字串的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。您也可經由管道將物件輸出至 ConvertTo-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoTypeInformation</maml:name> <maml:description> <maml:para>省略輸出的型別資訊標頭。根據預設,輸出的字串會包含 "#TYPE ",後面接著 .NET Framework 物件型別的完整名稱。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>ConvertTo-CSV</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UseCulture</maml:name> <maml:description> <maml:para>使用目前文化特性的清單分隔符號做為資料分隔符號。預設為逗號 (,)。 此參數針對發佈給全球使用者的指令碼很有用。若要尋找文化特性的清單分隔符號,請使用下列命令:(Get-Culture).TextInfo.ListSeparator。</maml:para> </maml:description> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要匯出成 CSV 字串的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。您也可經由管道將物件輸出至 ConvertTo-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoTypeInformation</maml:name> <maml:description> <maml:para>省略輸出的型別資訊標頭。根據預設,輸出的字串會包含 "#TYPE ",後面接著 .NET Framework 物件型別的完整名稱。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Delimiter</maml:name> <maml:description> <maml:para>指定分隔屬性值的分隔符號。預設為逗號 (,)。請輸入字元,例如分號 (:)。 若要指定分號 (;),請將其置於引號內。否則,分號會被解譯為命令分隔符號。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">char</command:parameterValue> <dev:type> <maml:name>char</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>, (逗號)</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要匯出成 CSV 字串的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。您也可經由管道將物件輸出至 ConvertTo-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoTypeInformation</maml:name> <maml:description> <maml:para>省略輸出的型別資訊標頭。根據預設,輸出的字串會包含 "#TYPE ",後面接著 .NET Framework 物件型別的完整名稱。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UseCulture</maml:name> <maml:description> <maml:para>使用目前文化特性的清單分隔符號做為資料分隔符號。預設為逗號 (,)。 此參數針對發佈給全球使用者的指令碼很有用。若要尋找文化特性的清單分隔符號,請使用下列命令:(Get-Culture).TextInfo.ListSeparator。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>逗號</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何 .NET Framework 物件輸出至 ConvertTo-CSV。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 傳回的 CSV 輸出是字串的集合。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 使用 CSV 格式,每個物件都會由逗號分隔物件屬性值的清單來代表。屬性值會轉換成字串 (利用物件的 ToString() 方法),所以一般由屬性值的名稱來代表。ConvertTo-CSV 並不會匯出物件的方法。 產生的 CSV 字串的格式如下: -- 第一個字串包含 '#TYPE ',後面接著 .NET Framework 物件型別的完整名稱,例如 #TYPE System.Diagnostics.Process。若要隱藏這個字串,請使用 NoTypeInformation 參數。 -- 第二個字串代表欄標頭,而且包含逗號分隔第一個物件所有屬性名稱的清單。 -- 其他字串包含逗號分隔每個物件屬性值的清單。 當您送出多個物件給 ConvertTo-CSV 時,ConvertTo-CSV 會依照所送出之第一個物件的屬性來排序字串。如果其他物件沒有其中一個指定的屬性,該物件的屬性值則為 null,以兩個連續的逗號代表。如果其他物件有額外的屬性,則會忽略額外的屬性值。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process powershell | convertto-csv #TYPE System.Diagnostics.Process "__NounName","Name","Handles","VM","WS","PM","NPM","Path","Company","CPU","FileVersion","ProductVersion","Description", "Product","BasePriority","ExitCode","HasExited","ExitTime","Handle","HandleCount","Id","MachineName","MainWindowHandle" ,"MainWindowTitle","MainModule","MaxWorkingSet","MinWorkingSet","Modules","NonpagedSystemMemorySize","NonpagedSystemMem orySize64","PagedMemorySize","PagedMemorySize64","PagedSystemMemorySize","PagedSystemMemorySize64","PeakPagedMemorySize ","PeakPagedMemorySize64","PeakWorkingSet","PeakWorkingSet64","PeakVirtualMemorySize","PeakVirtualMemorySize64","Priori tyBoostEnabled","PriorityClass","PrivateMemorySize","PrivateMemorySize64","PrivilegedProcessorTime","ProcessName","Proc essorAffinity","Responding","SessionId","StartInfo","StartTime","SynchronizingObject","Threads","TotalProcessorTime","U serProcessorTime","VirtualMemorySize","VirtualMemorySize64","EnableRaisingEvents","StandardInput","StandardOutput","Sta ndardError","WorkingSet","WorkingSet64","Site","Container" "Process","powershell","216","597544960","60399616","63197184","21692","C:\WINDOWS\system32\WindowsPowerShell\v1.0\powe rshell.exe","Microsoft Corporation","3.4788223","6.1.6587.1 (fbl_srv_powershell(nigels).070711-0102)","6.1.6587.1","Win dows PowerShell","Microsoft® Windows® Operating System","8",,"False",,"860","216","5132",".","5636936","Windows PowerSh ell 2.0 (04/17/2008 00:10:40)","System.Diagnostics.ProcessModule (powershell.exe)","1413120","204800","System.Diagnosti cs.ProcessModuleCollection","21692","21692","63197184","63197184","320080","320080","63868928","63868928","60715008","6 0715008","598642688","598642688","True","Normal","63197184","63197184","00:00:00.2028013","powershell","15","True","1", "System.Diagnostics.ProcessStartInfo","4/21/2008 3:49:19 PM",,"System.Diagnostics.ProcessThreadCollection","00:00:03.51 00225","00:00:03.3072212","597544960","597544960","False",,,,"60399616","60399616",, </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將單一處理序物件轉換成 CSV 格式。它會使用 Get-Process Cmdlet 取得本機電腦上的 PowerShell 處理序,並使用管線運算子 (|) 將命令結果傳送給 ConvertTo-CSV Cmdlet,讓後者將結果轉換成一連串以逗點分隔的字串。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $date = get-date C:\PS> convertto-csv -inputobject $date -delimiter ";" -notypeinformation </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會將日期物件轉換成 CSV 格式。 第一個命令會使用 Get-Date Cmdlet 取得目前的日期,然後將其儲存到 $date 變數。 第二個命令會使用 ConvertTo-CSV Cmdlet 將 $date 變數中的 DateTime 物件轉換成 CSV 格式。此命令會使用 InputObject 參數指定要轉換的物件、使用 Delimiter 參數指定分隔物件屬性的分隔符號,以及使用 NoTypeInformation 參數隱藏 #TYPE 字串。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-eventlog -log "windows powershell" | convertto-csv -useculture </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將本機電腦上的 Windows PowerShell 事件記錄檔轉換成一連串的 CSV 字串。 該命令會使用 Get-EventLog Cmdlet 取得 Windows PowerShell 記錄檔中的事件。管線運算子 (|) 會將事件傳送給 ConvertTo-CSV Cmdlet,此 Cmdlet 會將事件轉換成 CSV 格式。該命令會使用 UseCulture 參數,其將目前文化特性的清單分隔符號當成分隔符號。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135203</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertFrom-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> ConvertTo-Html </command:name> <maml:description> <maml:para>將 Microsoft .NET Framework 物件轉換成可在網頁瀏覽器中顯示的 HTML。 </maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>ConvertTo</command:verb> <command:noun>Html</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>ConvertTo-Html Cmdlet 會將 .NET Framework 物件轉換成可在網頁瀏覽器中顯示的 HTML。此 Cmdlet 可以用來在網頁中顯示命令的輸出。 您可以使用 ConvertTo-Html 的參數,選取物件屬性、指定表格或清單格式、指定 HTML 網頁標題、在物件前後加上文字,以及只傳回表格或清單片段而非 Strict DTD 頁面。 當您送出多個物件給 ConvertTo-Html 時,Windows PowerShell 會依照所送出之第一個物件的屬性來建立表格 (或清單)。如果其他物件沒有其中一個指定的屬性,該物件的屬性值則為空資料格。如果其他物件有額外的屬性,則不會在檔案中包含額外的屬性值。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>ConvertTo-Html</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="2"> <maml:name>Head</maml:name> <maml:description> <maml:para>指定 <HEAD> 標記的內容。預設為 "<title>HTML TABLE</title>"。如果使用 Head 參數,則會略過 Title 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Title</maml:name> <maml:description> <maml:para>指定 HTML 檔案的標題,也就是出現在 <TITLE> 標記之間的文字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="4"> <maml:name>Body</maml:name> <maml:description> <maml:para>指定要在開頭 <BODY> 標記後加上的文字。根據預設,該位置沒有任何文字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CssUri</maml:name> <maml:description> <maml:para>指定套用到 HTML 檔案之階層式樣式表 (CSS) 的統一資源識別項 (URI)。輸出的樣式表連結含有此 URI。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Uri</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>將指定的物件屬性列入 HTML 中。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>As</maml:name> <maml:description> <maml:para>決定是否將物件格式化為表格或清單。有效的值為 TABLE 和 LIST。預設值為 TABLE。 TABLE 值會產生 HTML 表格,類似於 Windows PowerShell 表格格式。標頭列會顯示屬性名稱。每個表格列都代表一個物件,而且會為每個屬性顯示物件的值。 LIST 值會為每個物件產生兩欄 HTML 表格,類似於 Windows PowerShell 清單格式。第一欄顯示屬性名稱,而第二欄顯示屬性值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要以 HTML 表示的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。 如果您使用此參數送出多個物件,例如電腦上的所有服務,ConvertTo-Html 就會建立一個顯示集合屬性或物件陣列 (System.Object[]) 屬性的表格。若要建立個別物件的表格,請使用管線運算子將物件傳送給 ConvertTo-Html。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>PostContent</maml:name> <maml:description> <maml:para>指定要在結尾 </TABLE> 標記後加上的文字。根據預設,該位置沒有任何文字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>PreContent</maml:name> <maml:description> <maml:para>指定要在開頭 <TABLE> 標記前加上的文字。根據預設,該位置沒有任何文字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>ConvertTo-Html</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Fragment</maml:name> <maml:description> <maml:para>只產生 HTML 表格。HTML、HEAD、TITLE 和 BODY 標記會被省略。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>將指定的物件屬性列入 HTML 中。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>As</maml:name> <maml:description> <maml:para>決定是否將物件格式化為表格或清單。有效的值為 TABLE 和 LIST。預設值為 TABLE。 TABLE 值會產生 HTML 表格,類似於 Windows PowerShell 表格格式。標頭列會顯示屬性名稱。每個表格列都代表一個物件,而且會為每個屬性顯示物件的值。 LIST 值會為每個物件產生兩欄 HTML 表格,類似於 Windows PowerShell 清單格式。第一欄顯示屬性名稱,而第二欄顯示屬性值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要以 HTML 表示的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。 如果您使用此參數送出多個物件,例如電腦上的所有服務,ConvertTo-Html 就會建立一個顯示集合屬性或物件陣列 (System.Object[]) 屬性的表格。若要建立個別物件的表格,請使用管線運算子將物件傳送給 ConvertTo-Html。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>PostContent</maml:name> <maml:description> <maml:para>指定要在結尾 </TABLE> 標記後加上的文字。根據預設,該位置沒有任何文字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>PreContent</maml:name> <maml:description> <maml:para>指定要在開頭 <TABLE> 標記前加上的文字。根據預設,該位置沒有任何文字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>As</maml:name> <maml:description> <maml:para>決定是否將物件格式化為表格或清單。有效的值為 TABLE 和 LIST。預設值為 TABLE。 TABLE 值會產生 HTML 表格,類似於 Windows PowerShell 表格格式。標頭列會顯示屬性名稱。每個表格列都代表一個物件,而且會為每個屬性顯示物件的值。 LIST 值會為每個物件產生兩欄 HTML 表格,類似於 Windows PowerShell 清單格式。第一欄顯示屬性名稱,而第二欄顯示屬性值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Table</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="4"> <maml:name>Body</maml:name> <maml:description> <maml:para>指定要在開頭 <BODY> 標記後加上的文字。根據預設,該位置沒有任何文字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>沒有文字。</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CssUri</maml:name> <maml:description> <maml:para>指定套用到 HTML 檔案之階層式樣式表 (CSS) 的統一資源識別項 (URI)。輸出的樣式表連結含有此 URI。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Uri</command:parameterValue> <dev:type> <maml:name>Uri</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Fragment</maml:name> <maml:description> <maml:para>只產生 HTML 表格。HTML、HEAD、TITLE 和 BODY 標記會被省略。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="2"> <maml:name>Head</maml:name> <maml:description> <maml:para>指定 <HEAD> 標記的內容。預設為 "<title>HTML TABLE</title>"。如果使用 Head 參數,則會略過 Title 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue><title>HTML TABLE</title></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要以 HTML 表示的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。 如果您使用此參數送出多個物件,例如電腦上的所有服務,ConvertTo-Html 就會建立一個顯示集合屬性或物件陣列 (System.Object[]) 屬性的表格。若要建立個別物件的表格,請使用管線運算子將物件傳送給 ConvertTo-Html。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>PostContent</maml:name> <maml:description> <maml:para>指定要在結尾 </TABLE> 標記後加上的文字。根據預設,該位置沒有任何文字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>沒有文字</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>PreContent</maml:name> <maml:description> <maml:para>指定要在開頭 <TABLE> 標記前加上的文字。根據預設,該位置沒有任何文字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>沒有文字</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>將指定的物件屬性列入 HTML 中。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Title</maml:name> <maml:description> <maml:para>指定 HTML 檔案的標題,也就是出現在 <TITLE> 標記之間的文字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何 .NET 物件輸出至 ConvertTo-Html。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> ConvertTo-Html 會傳回由有效 HTML 組成的一串字串。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 若要使用此 Cmdlet,請經由管道將一個或多個物件輸出至 Cmdlet,或是使用 InputObject 參數指定物件。當輸入有多個物件時,上述兩種方法的輸出大不相同。 -- 當您經由管道將多個物件輸出至 Cmdlet 時,Windows PowerShell 會將物件一個一個地傳送給 Cmdlet,因此 ConvertTo-Html 建立的表格會顯示個別物件。例如,若經由管道將電腦上的處理序輸出至 ConvertTo-Html,產生的表格就會顯示所有處理序。 -- 使用 InputObject 參數送出多個物件時,ConvertTo-Html 會接收這些物件當做集合或陣列,因此它建立的表格會顯示陣列及其屬性,而非陣列中的項目。例如,若使用 InputObject 送出電腦上的處理序給 ConvertTo-Html,產生的表格就會顯示物件陣列 (System.Object[]) 及其屬性。 為了遵守 XHTML Strict DTD,也相應修改了 DOCTYPE 標記: (<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">) </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> convertto-html -inputobject (get-date) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立一個顯示目前日期屬性的 HTML 網頁,並使用 InputObject 參數將 Get-Date 命令的結果送出給 ConvertTo-Html Cmdlet。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-alias | convertto-html > aliases.htm C:\PS> invoke-item aliases.htm </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立一個列出目前主控台中 Windows PowerShell 別名的 HTML 網頁。 它會使用 Get-Alias Cmdlet 取得別名,並使用管線運算子 (|) 將別名傳送給 ConvertTo-Html Cmdlet,此 Cmdlet 會建立 HTML 網頁。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-eventlog -logname "Windows PowerShell | convertto-html > pslog.htm </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立一個稱為 pslog.htm 的 HTML 網頁,此網頁將顯示本機電腦上 Windows PowerShell 事件記錄檔中的事件。 這個命令會使用 Get-EventLog Cmdlet 取得 Windows PowerShell 記錄檔中的事件,然後使用管線運算子 (|) 將事件傳送給 ConvertTo-Html Cmdlet。 也會使用重新導向運算子 (>) 將 HTML 程式碼傳送給 pslog.htm 檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | convertto-html -property Name, Path, Company -title "Process Information" > proc.htm; ii proc.htm </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會建立並開啟一個列出本機電腦上處理序之名稱、路徑和公司的 HTML 網頁。 第一個命令會使用 Get-Process Cmdlet 取得代表正在電腦上執行之處理序的物件,然後使用管線運算子 (|) 將處理序物件傳送給 ConvertTo-Html Cmdlet。 這個命令會使用 Property 參數選取要包含在表格中之處理序物件的三個屬性、使用 Title 參數指定 HTML 網頁的標題,以及使用重新導向運算子 (>) 將產生的 HTML 傳送給名為 Proc.htm 的檔案。 第二個命令會使用 Invoke-Item Cmdlet (別名為 ii) 將 Proc.htm 在預設瀏覽器中開啟。這兩個命令之間是以分號 (;) 區隔。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-service | convertto-html -CssUri "test.css" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>HTML TABLE</title> <link rel="stylesheet" type="text/css" href="test.css" /> ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立一個 Get-Service Cmdlet 所傳回之服務物件的 HTML 網頁,並使用 CssUri 參數指定 HTML 網頁的階層式樣式表。 CssUri 參數會將額外的 "<link rel="stylesheet" type="text/css" 標記加入至產生的 HTML。這個標記中的 HREF 屬性包含樣式表的名稱。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-service | convertto-html -as LIST > services.htm </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立一個 Get-Service Cmdlet 所傳回之服務物件的 HTML 網頁,並使用 As 參數指定清單格式。重新導向運算子 (>) 會將產生的 HTML 傳送給 Services.htm 檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-date | cth -fragment <table> <colgroup>...</colgroup> <tr><th>DisplayHint</th><th>DateTime</th><th>Date</th><th>Day</th><th>DayOfWeek</th><th>DayOfYear</th><th>Hour</th><th> Kind</th><th>Millisecond</th><th>Minute</th><th>Month</th><th>Second</th><th>Ticks</th><th>TimeOfDay</th><th>Year</th>< /tr> <tr><td>DateTime</td><td>Monday, May 05, 2008 10:40:04 AM</td><td>5/5/2008 12:00:00 AM</td><td>5</td><td>Monday</td><td >126</td><td>10</td><td>Local</td><td>123</td><td>40</td><td>5</td><td>4</td><td>633455808041237213</td><td>10:40:04.12 37213</td><td>2008</td></tr> </table> </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 ConvertTo-Html 產生目前日期的 HTML 表格。它會使用 Get-Date Cmdlet 取得目前的日期,並使用管線運算子 (|) 傳送結果給 ConvertTo-Html Cmdlet (別名為 "cth")。 ConvertTo-Html 命令包含 Fragment 參數,這會將輸出限制在 HTML 表格。因此,HTML 網頁的其他元素,例如 <HEAD> 和 <BODY> 標記,會被省略。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 8 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-eventlog -log "Windows PowerShell" | convertto-html -property id, level, task </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 Get-EventLog Cmdlet 取得 "Windows PowerShell" 事件記錄檔中的事件。 它會使用管線運算子 (|) 將事件傳送給 ConvertTo-Html Cmdlet,此 Cmdlet 會將事件轉換成 HTML 格式。 ConvertTo-Html 命令會使用 Property 參數,只選取事件的 ID、Level 和 Task 屬性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 9 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-service A* | ConvertTo-Html -title "Windows Services: Server01" -body (get-date) -pre "<P>Generated by Corporate IT</P >" -post "For details, contact Corporate IT." > services.htm; ii services.htm </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立及開啟一個顯示電腦上 "A" 開頭之服務的網頁,並使用 ConvertTo-Html 的 Title、Body、PreContent 和 PostContent 參數自訂輸出。 這個命令的第一個部分是使用 Get-Service Cmdlet 取得電腦上 "A" 開頭的服務。這個命令會使用管線運算子 (|) 傳送結果給 ConvertTo-Html Cmdlet,並使用重新導向運算子 (>) 將輸出傳送給 Services.htm 檔案。 分號 (;) 用來結束第一個命令並開始第二個命令,第二個命令會使用 Invoke-Item Cmdlet (別名為 "ii"),在預設瀏覽器中開啟 Services.htm 檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113290</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertTo-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertTo-Xml</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> ConvertTo-XML </command:name> <maml:description> <maml:para>建立物件的 XML 表示。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>ConvertTo</command:verb> <command:noun>XML</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>ConvertTo-Xml Cmdlet 會建立一個或多個 Microsoft .NET Framework 物件的 XML 表示法。若要使用此 Cmdlet,請經由管道將一個或多個物件輸出至 Cmdlet,或是使用 InputObject 參數指定物件。 當您經由管道將多個物件輸出至 ConvertTo-XML 或使用 InputObject 參數送出多個物件時,ConvertTo-XML 會傳回一個包含所有物件表示的 XML 文件。 此 Cmdlet 與 Export-Clixml 相似,但不同是 Export-Clixml 將產生的 XML 儲存到檔案中。ConvertTo-XML 會傳回 XML,因此您可以在 Windows PowerShell 中繼續處理它。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>ConvertTo-XML</maml:name> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="true (ByValue)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要轉換的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。您也可經由管道將物件輸出至 ConvertTo-XML。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>As</maml:name> <maml:description> <maml:para>決定輸出格式。有效的值包括: -- String: 傳回單一字串。 -- Stream: 傳回字串的陣列。 -- Document: 傳回 XmlDocument 物件。 預設為 Stream。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Depth</maml:name> <maml:description> <maml:para>指定 XML 表示中所含之物件的層級數量。預設值為 1。 例如,若物件的屬性也包含物件,要將這些內含物件的屬性儲存成 XML 表示,就必須將深度指定為 2。 您可以在 Types.ps1xml 檔案中覆寫物件型別的預設值。如需詳細資訊,請參閱 about_Types.ps1xml。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoTypeInformation</maml:name> <maml:description> <maml:para>省略 object 節點的 Type 屬性。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>As</maml:name> <maml:description> <maml:para>決定輸出格式。有效的值包括: -- String: 傳回單一字串。 -- Stream: 傳回字串的陣列。 -- Document: 傳回 XmlDocument 物件。 預設為 Stream。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Stream</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Depth</maml:name> <maml:description> <maml:para>指定 XML 表示中所含之物件的層級數量。預設值為 1。 例如,若物件的屬性也包含物件,要將這些內含物件的屬性儲存成 XML 表示,就必須將深度指定為 2。 您可以在 Types.ps1xml 檔案中覆寫物件型別的預設值。如需詳細資訊,請參閱 about_Types.ps1xml。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>1</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="true" pipelineInput="true (ByValue)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要轉換的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。您也可經由管道將物件輸出至 ConvertTo-XML。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoTypeInformation</maml:name> <maml:description> <maml:para>省略 object 節點的 Type 屬性。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 ConvertTo-XML。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.String 或 System.Xml.XmlDocument</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> As 參數的值會決定 ConvertTo-XML 傳回的物件類型。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-date | convertto-xml </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將目前的日期 (DateTime 物件) 轉換成 XML。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> convertto-xml -as Document -inputObject (get-process) -depth 3 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將那些代表電腦上所有處理序的處理序物件轉換成 XML 文件,並將物件展開成 3 層。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135204</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-Clixml</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-Clixml</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertTo-Html</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertTo-Csv</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Disable-PSBreakpoint </command:name> <maml:description> <maml:para>在目前主控台中停用中斷點。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Disable</command:verb> <command:noun>PSBreakpoint</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Disable-PSBreakpoint Cmdlet 會停用中斷點,如此可確保指令碼執行時不會點擊中斷點。您可以用它來停用所有的中斷點,或是透過送出中斷點物件或中斷點識別碼來指定中斷點。 嚴格來說,此 Cmdlet 會將中斷點物件的 Enabled 屬性值設為 False。若要重新啟用中斷點,請使用 Enable-PSBreakpoint Cmdlet。在使用 Set-PSBreakpoint Cmdlet 建立中斷點時,預設會將中斷點設為啟用。 中斷點是指令碼中的一個位置,只要指令碼執行到此處就會暫停執行,讓您可以檢查指令碼中的指令。Disable-PSBreakpoint 是其中幾個專為偵錯 Windows PowerShell 指令碼所設計的 Cmdlet。如需 Windows PowerShell 偵錯工具的詳細資訊,請參閱 about_Debuggers。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Disable-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Id</maml:name> <maml:description> <maml:para>停用有指定的中斷點識別碼的中斷點。請輸入識別碼或含有識別碼的變數。您無法經由管道將識別碼輸出至 Disable-PSBreakpoint。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已啟用之中斷點的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Disable-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Breakpoint</maml:name> <maml:description> <maml:para>指定要停用的中斷點。請輸入包含中斷點物件的變數或可取得中斷點物件的命令,例如 Get-PSBreakpoint 命令。您也可經由管道將中斷點物件輸出至 Disable-PSBreakpoint Cmdlet。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Breakpoint[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已啟用之中斷點的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Breakpoint</maml:name> <maml:description> <maml:para>指定要停用的中斷點。請輸入包含中斷點物件的變數或可取得中斷點物件的命令,例如 Get-PSBreakpoint 命令。您也可經由管道將中斷點物件輸出至 Disable-PSBreakpoint Cmdlet。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Breakpoint[]</command:parameterValue> <dev:type> <maml:name>Breakpoint[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Id</maml:name> <maml:description> <maml:para>停用有指定的中斷點識別碼的中斷點。請輸入識別碼或含有識別碼的變數。您無法經由管道將識別碼輸出至 Disable-PSBreakpoint。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> <dev:type> <maml:name>Int32[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已啟用之中斷點的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.Breakpoint</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將中斷點物件輸出至 Disable-PSBreakpoint。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.Breakpoint</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 PassThru 參數時,Disable-PSBreakpoint 會傳回代表已停用之中斷點的物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $b = set-psbreakpoint -script sample.ps1 -variable name C:\PS> $b | disable-psbreakpoint </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會停用新建立的中斷點。 第一個命令會使用 Set-PSBreakpoint Cmdlet 在 Sample.ps1 指令碼的 Name 變數上建立中斷點,然後將中斷點物件儲存到 $b 變數。 第二個命令會使用 Disable-PSBreakpoint Cmdlet 停用新的中斷點。並使用管線運算子 (|) 將 $b 中的中斷點物件傳送給 Disable-PSBreakpoint。 因為這個命令,$b 中的中斷點物件的 Enabled 屬性值會是 False。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> disable-psbreakpoint -id 0 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會停用中斷點識別碼為 0 的中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> disable-psbreakpoint -breakpoint ($b = set-psbreakpoint -script sample.ps1 -line 5) C:\PS> $b </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立新的中斷點,讓它處於停用狀態,直到您啟用它為止。 這個命令會使用 Disable-PSBreakpoint Cmdlet 停用中斷點。Breakpoint 參數的值為 Set-PSBreakpoint 命令,此命令會設定新的中斷點、產生中斷點物件,以及將該物件儲存到 $b 變數。 對於將物件當成值的 Cmdlet 參數來說,變數包含物件或是命令取得或產生物件都是可以接受的。既然這樣,Set-PSBreakpoint 就可以當成 Breakpoint 參數的值使用,因為它會產生中斷點物件。 第二個命令會顯示 $b 變數值中的中斷點物件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-psbreakpoint | disable-psbreakpoint </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在目前主控台中停用所有中斷點。您可以將這個命令縮短為:"gbp | ebp"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113294</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Debuggers</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Enable-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSCallStack</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Enable-PSBreakpoint </command:name> <maml:description> <maml:para>在目前主控台中啟用中斷點。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Enable</command:verb> <command:noun>PSBreakpoint</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Enable-PSBreakpoint Cmdlet 會重新啟用已停用的中斷點。您可以用它來啟用所有的中斷點,或是透過送出中斷點物件或中斷點識別碼來指定中斷點。 中斷點是指令碼中的一個位置,只要指令碼執行到此處就會暫停執行,讓您可以檢查指令碼中的指令。新建立的中斷點會自動處於啟用狀態,但是您可以使用 Disable-PSBreakpoint Cmdlet 加以停用。 嚴格來說,此 Cmdlet 會將中斷點物件的 Enabled 屬性值設為 True。 Enable-PSBreakpoint 是其中幾個專為偵錯 Windows PowerShell 指令碼所設計的 Cmdlet。如需 Windows PowerShell 偵錯工具的詳細資訊,請參閱 about_Debuggers。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Enable-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Id</maml:name> <maml:description> <maml:para>啟用有指定的中斷點識別碼的中斷點。預設值為所有中斷點。請輸入識別碼或含有識別碼的變數 (您無法經由管道將識別碼輸出至 Enable-PSBreakpoint)。若要尋找中斷點的識別碼,請使用 Get-PSBreakpoint Cmdlet。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已啟用之中斷點的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Enable-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Breakpoint</maml:name> <maml:description> <maml:para>指定要啟用的中斷點。請輸入包含中斷點物件的變數或可取得中斷點物件的命令,例如 Get-PSBreakpoint 命令。您也可經由管道將中斷點物件輸出至 Enable-PSBreakpoint。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Breakpoint[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已啟用之中斷點的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Breakpoint</maml:name> <maml:description> <maml:para>指定要啟用的中斷點。請輸入包含中斷點物件的變數或可取得中斷點物件的命令,例如 Get-PSBreakpoint 命令。您也可經由管道將中斷點物件輸出至 Enable-PSBreakpoint。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Breakpoint[]</command:parameterValue> <dev:type> <maml:name>Breakpoint[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無。</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Id</maml:name> <maml:description> <maml:para>啟用有指定的中斷點識別碼的中斷點。預設值為所有中斷點。請輸入識別碼或含有識別碼的變數 (您無法經由管道將識別碼輸出至 Enable-PSBreakpoint)。若要尋找中斷點的識別碼,請使用 Get-PSBreakpoint Cmdlet。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> <dev:type> <maml:name>Int32[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已啟用之中斷點的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>沒有輸出</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.Breakpoint</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將中斷點物件輸出至 Enable-PSBreakpoint。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.Breakpoint</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 PassThru 參數時,Enable-PSBreakpoint 會傳回代表已啟用之中斷點的中斷點物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 如果您嘗試啟用已經啟用的中斷點,Enable-PSBreakpoint Cmdlet 並不會產生任何錯誤。就這一點來說,即使當只有一些中斷點處於停用狀態的時候,您也可以啟用所有中斷點而不會有錯誤產生。 在使用 Set-PSBreakpoint Cmdlet 建立中斷點時會啟用中斷點,您不需要啟用新建立的中斷點。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-psbreakpoint | enable-psbreakpoint </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在目前主控台中啟用所有中斷點。您可以將這個命令縮短為 "gbp | ebp"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> enable-psbreakpoint -id 0, 1, 5 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會啟用中斷點識別碼為 0、1 和 5 的中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $b = set-psbreakpoint -script sample.ps1 -variable Name C:\PS> $b | disable-psbreakpoint -passthru AccessMode : Write Variable : Name Action : Enabled : False HitCount : 0 Id : 0 Script : C:\ps-test\sample.ps1 ScriptName : C:\ps-test\sample.ps1 C:\PS> $b | enable-psbreakpoint -passthru AccessMode : Write Variable : Name Action : Enabled : True HitCount : 0 Id : 0 Script : C:\ps-test\sample.ps1 ScriptName : C:\ps-test\sample.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會重新啟用已經停用的中斷點。 第一個命令會使用 Set-PSBreakpoint Cmdlet 在 Sample.ps1 指令碼的 "Name" 變數上建立中斷點,然後將中斷點物件儲存到 $b 變數。 第二個命令會使用 Disable-PSBreakpoint Cmdlet 停用新的中斷點。它會使用管線運算子 (|) 將 $b 中的中斷點物件傳送給 Disable-PSBreakpoint Cmdlet,並使用 Disable-PSBreakpoint 的 PassThru 參數顯示已停用的中斷點物件。您可藉此確認中斷點物件的 Enabled 屬性值為 False。 第三個命令會使用 Enable-PSBreakpoint Cmdlet 重新啟用中斷點。它會使用管線運算子 (|) 將 $b 中的中斷點物件傳送給 Enable-PSBreakpoint Cmdlet,並使用 Enable-PSBreakpoint 的 PassThru 參數顯示中斷點物件。您可藉此確認中斷點物件的 Enabled 屬性值為 True。 下列範例的輸出會顯示結果。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $b = get-psbreakpoint -id 3, 5 C:\PS> enable-psbreakpoint -breakpoint $b </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會藉由指定一組中斷點的中斷點物件來啟用這一組中斷點。 第一個命令會使用 Get-PSBreakpoint Cmdlet 取得中斷點,然後這些中斷點儲存到 $b 變數。 第二個命令會將 Enable-PSBreakpoint Cmdlet 搭配其 Breakpoint 參數使用,以啟用中斷點。 此命令相當於 "enable-psbreakpoint -id 3, 5"。 </maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113295</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Debuggers</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Disable-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSCallStack</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Export-Alias </command:name> <maml:description> <maml:para>將目前已定義的別名相關資訊匯出至檔案。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Export</command:verb> <command:noun>Alias</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Export-Alias Cmdlet 會將目前工作階段中的別名匯出到檔案。如果輸出檔不存在,Cmdlet 將會建立它。 Export-Alias 能夠針對特定範圍或所有範圍中的別名進行匯出,也能夠以 CSV 格式或是以一連串可加到工作階段或 Windows PowerShell 設定檔的 Set-Alias 命令形式來產生資料。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Export-Alias</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定輸出檔的路徑。允許使用萬用字元,但產生的路徑值必須解析成單一檔案名稱。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定要匯出的別名名稱。允許使用萬用字元。 根據預設,Export-Alias 會將工作階段或範圍中的所有別名都匯出。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Append</maml:name> <maml:description> <maml:para>將輸出附加到指定的檔案,而非覆寫該檔案現有的內容。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>As</maml:name> <maml:description> <maml:para>決定輸出格式。預設為 CSV。 有效的值包括: -- CSV:逗號分隔值 (CSV) 格式。 -- Script: 建立每個匯出的別名的 Set-Alias 命令。如果以 .ps1 副檔名來命名輸出檔,就能將它執行成指令碼,以便將別名新增到任何工作階段。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Csv</command:parameterValue> <command:parameterValue required="false" variableLength="false">Script</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Description</maml:name> <maml:description> <maml:para>在匯出檔中新增描述。描述會以註解的形式出現在檔案頂端,位於標頭資訊後面。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>覆寫輸出檔,即使其中已設定唯讀屬性。 除非檔案上已設定唯讀或隱藏屬性或是命令中已使用 NoClobber 參數,否則 Export-Alias 預設會毫無預警地覆寫檔案。同時使用 NoClobber 參數與 Force 參數時,前者的優先順序高於後者。 Force 參數無法強制 Export-Alias 覆寫有隱藏屬性的檔案。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>防止 Export-Alias 覆寫任何檔案,即使命令中已使用 Force 參數亦然。 如果省略 NoClobber 參數,則除非現有檔案上已設定唯讀屬性,否則 Export-Alias 會毫無預警地覆寫該檔案。NoClobber 的優先順序高於 Force 參數,後者允許 Export-Alias 覆寫有唯讀屬性的檔案。 NoClobber 不能防止 Append 參數將內容加入至現有檔案。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已匯入之別名的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定匯出的別名所隸屬的範圍。 有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其父範圍)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Append</maml:name> <maml:description> <maml:para>將輸出附加到指定的檔案,而非覆寫該檔案現有的內容。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>As</maml:name> <maml:description> <maml:para>決定輸出格式。預設為 CSV。 有效的值包括: -- CSV:逗號分隔值 (CSV) 格式。 -- Script: 建立每個匯出的別名的 Set-Alias 命令。如果以 .ps1 副檔名來命名輸出檔,就能將它執行成指令碼,以便將別名新增到任何工作階段。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">ExportAliasFormat</command:parameterValue> <dev:type> <maml:name>ExportAliasFormat</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Description</maml:name> <maml:description> <maml:para>在匯出檔中新增描述。描述會以註解的形式出現在檔案頂端,位於標頭資訊後面。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>覆寫輸出檔,即使其中已設定唯讀屬性。 除非檔案上已設定唯讀或隱藏屬性或是命令中已使用 NoClobber 參數,否則 Export-Alias 預設會毫無預警地覆寫檔案。同時使用 NoClobber 參數與 Force 參數時,前者的優先順序高於後者。 Force 參數無法強制 Export-Alias 覆寫有隱藏屬性的檔案。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>不會覆寫唯讀檔案。</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定要匯出的別名名稱。允許使用萬用字元。 根據預設,Export-Alias 會將工作階段或範圍中的所有別名都匯出。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>匯出所有別名</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>防止 Export-Alias 覆寫任何檔案,即使命令中已使用 Force 參數亦然。 如果省略 NoClobber 參數,則除非現有檔案上已設定唯讀屬性,否則 Export-Alias 會毫無預警地覆寫該檔案。NoClobber 的優先順序高於 Force 參數,後者允許 Export-Alias 覆寫有唯讀屬性的檔案。 NoClobber 不能防止 Append 參數將內容加入至現有檔案。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>覆寫讀寫檔案。</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表已匯入之別名的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>沒有輸出</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定輸出檔的路徑。允許使用萬用字元,但產生的路徑值必須解析成單一檔案名稱。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定匯出的別名所隸屬的範圍。 有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其父範圍)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Local</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無。</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將物件輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.AliasInfo</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 Passthru 參數時,Export-Alias 會傳回代表別名的 System.Management.Automation.AliasInfo 物件,否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您只能將別名匯出 (Export-Alias) 到檔案。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> export-alias -path alias.csv </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將目前別名資訊匯出到目前目錄中名為 Alias.csv 的檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> export-alias -path alias.csv -noclobber </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將目前工作階段中的別名匯出到 Alias.csv 檔案。 因為指定了 NoClobber 參數,如果目前目錄中已有 Alias.csv 檔案,這個命令會失敗。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> export-alias -path alias.csv -append -description "Appended Aliases" -force </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將目前工作階段中的別名附加到 Alias.csv 檔案。 這個命令會使用 Description 參數將描述加到位於檔案頂端的註解。 也會使用 Force 參數覆寫任何現有的 Alias.csv 檔案,即使這些檔案有唯讀屬性也一樣。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> export-alias -path alias.ps1 -as script C:\PS> add-content -path $profile -value (get-content alias.ps1) C:\PS> $s = new-pssession -computername Server01 C:\PS> invoke-command -session $s -filepath .\alias.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用 Export-Alias 產生的指令碼檔案格式。 第一個命令會將工作階段中的別名匯出到 Alias.ps1 檔案,並使用值為 Script 的 As 參數來產生一個包含每個別名的 Set-Alias 命令的檔案。 第二個命令會將 Alias.ps1 檔案中的別名新增到 CurrentUser-CurrentHost 設定檔 (設定檔的路徑儲存在 $profile 變數中)。該命令會使用 Get-Content Cmdlet 從 Alias.ps1 檔案取得別名,而 Add-Content Cmdlet 會將這些別名新增到設定檔。如需詳細資訊,請參閱 about_Profiles。 第三個和第四個命令會將 Alias.ps1 檔案中的別名新增到 Server01 電腦上的遠端工作階段。第三個命令會使用 New-PSSession Cmdlet 建立工作階段。第四個命令會使用 Invoke-Command Cmdlet 的 FilePath 參數,在新的工作階段中執行 Alias.ps1。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113296</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Export-Clixml </command:name> <maml:description> <maml:para>建立物件的 XML 表示法並儲存至檔案。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Export</command:verb> <command:noun>Clixml</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Export-Clixml Cmdlet 會建立物件的 XML 表示,然後將其儲存到檔案中。然後您可以使用 Import-CLIXML Cmdlet,根據該檔案的內容重新建立儲存的物件。 此 Cmdlet 與 ConvertTo-XML 相似,但不同是 Export-Clixml 將產生的 XML 儲存到檔案中。ConvertTo-XML 會傳回 XML,因此您可以在 Windows PowerShell 中繼續處理它。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Export-Clixml</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定用於儲存物件 XML 表示法的檔案所在路徑。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要轉換的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。您也可經由管道將物件輸出至 Export-Clixml。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Depth</maml:name> <maml:description> <maml:para>指定 XML 表示中所含之物件的層級數量。預設值為 2。 您可以在 Types.ps1xml 檔案中覆寫物件型別的預設值。如需詳細資訊,請參閱 about_Types.ps1xml。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定目標檔案的編碼類型。有效的值包括 ASCII、UTF8、UTF7、UTF32、Unicode、BigEndianUnicode、Default 和 OEM。預設為 UTF8。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>指示 cmdlet 於必要時清除輸出檔的唯讀屬性。cmdlet 會在命令完成後嘗試重設唯讀屬性。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>確保 cmdlet 不會覆寫現有檔案的內容。根據預設,如果檔案已在指定的路徑中,Export-Clixml 會毫無預警地覆寫該檔案。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Depth</maml:name> <maml:description> <maml:para>指定 XML 表示中所含之物件的層級數量。預設值為 2。 您可以在 Types.ps1xml 檔案中覆寫物件型別的預設值。如需詳細資訊,請參閱 about_Types.ps1xml。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>2</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定目標檔案的編碼類型。有效的值包括 ASCII、UTF8、UTF7、UTF32、Unicode、BigEndianUnicode、Default 和 OEM。預設為 UTF8。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>UTF8</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>指示 cmdlet 於必要時清除輸出檔的唯讀屬性。cmdlet 會在命令完成後嘗試重設唯讀屬性。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要轉換的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。您也可經由管道將物件輸出至 Export-Clixml。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>確保 cmdlet 不會覆寫現有檔案的內容。根據預設,如果檔案已在指定的路徑中,Export-Clixml 會毫無預警地覆寫該檔案。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定用於儲存物件 XML 表示法的檔案所在路徑。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Export-Clixml。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.IO.FileInfo</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Export-Clixml 會建立包含 XML 的檔案。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> "This is a test" | export-clixml sample.xml </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立一個 XML 檔案,儲存 "This is a test" 字串的表示法。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-acl C:\test.txt | export-clixml -Path fileacl.xml C:\PS> $fileacl = import-clixml fileacl.xml </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何將物件匯出到 XML 檔案,然後透過從該檔案匯入 XML 來建立物件。 第一個命令會使用 Get-ACL Cmdlet 取得 Test.txt 檔案的安全性描述元,並使用管線運算子將安全性描述元傳遞給 Export-Clixml,讓後者將物件的 XML 表示儲存到名為 FileACL.xml 的檔案。 第二個命令會使用 Import-Clixml Cmdlet 從 FileACL.xml 檔案中的 XML 建立物件,然後將該物件儲存到 $FileAcl 變數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113297</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-Clixml</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertTo-XML</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-Csv</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertTo-Html</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Export-CSV </command:name> <maml:description> <maml:para>將 Microsoft .NET Framework 物件轉換成一連串以逗號分隔值 (CSV) 且長度可變的字串,並將該字串儲存到 CSV 檔案。 </maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Export</command:verb> <command:noun>CSV</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Export-CSV Cmdlet 會建立長度可變的 CSV 檔案,代表您所送出的物件。 然後您可以使用 Import-CSV Cmdlet,從該檔案中的 CSV 字串重新建立物件。產生的物件為原始物件的 CSV 版本,是由屬性值的字串表示所組成,而且沒有任何方法。 您也可以使用 ConvertTo-CSV 和 ConvertFrom-CSV Cmdlet,將 .NET Framework 物件轉換成 CSV 字串 (反之亦然)。Export-CSV 除了將 CSV 字串儲存到檔案中以外,與 ConvertTo-CSV 都相同。 您可以使用 Export-CSV Cmdlet 的參數指定逗號以外的分隔符號,或是指示 Export-CSV 使用目前文化特性的預設分隔符號。 當您送出多個物件給 Export-CSV 時,Export-CSV 會依照所送出之第一個物件的屬性來組織檔案。如果其他物件沒有其中一個指定的屬性,該物件的屬性值則為 null,以兩個連續的逗號代表。如果其他物件有額外的屬性,則不會在檔案中包含額外的屬性值。 如需詳細資訊,請參閱 Export-CSV 和 Notes 區段。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Export-CSV</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Delimiter</maml:name> <maml:description> <maml:para>指定分隔屬性值的分隔符號。預設為逗號 (,)。請輸入字元,例如分號 (:)。若要指定分號 (;),請將其置於引號內。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">char</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定 CSV 輸出檔的路徑。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要匯出成 CSV 字串的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。您也可經由管道將物件輸出至 Export-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定 CSV 匯出檔的編碼。有效的值包括 Unicode、UTF7、UTF8、ASCII、UTF32、BigEndianUnicode、Default 和 OEM。預設為 ASCII。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>毫無預警地覆寫路徑中指定的檔案。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>不覆寫 (取代) 現有檔案的內容。根據預設,如果有檔案現存於指定的路徑,Export-CSV 將覆寫該檔案而不顯示警告。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoTypeInformation</maml:name> <maml:description> <maml:para>省略 CSV 檔案的型別資訊標頭。根據預設,CSV 檔案的第一行會包含 "#TYPE ",後面接著 .NET Framework 物件型別的完整名稱。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Export-CSV</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UseCulture</maml:name> <maml:description> <maml:para>使用目前文化特性的清單分隔符號做為項目分隔符號。預設為逗號 (,)。 此參數針對發佈給全球使用者的指令碼很有用。若要尋找文化特性的清單分隔符號,請使用下列命令:(Get-Culture).TextInfo.ListSeparator。</maml:para> </maml:description> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定 CSV 輸出檔的路徑。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要匯出成 CSV 字串的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。您也可經由管道將物件輸出至 Export-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定 CSV 匯出檔的編碼。有效的值包括 Unicode、UTF7、UTF8、ASCII、UTF32、BigEndianUnicode、Default 和 OEM。預設為 ASCII。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>毫無預警地覆寫路徑中指定的檔案。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>不覆寫 (取代) 現有檔案的內容。根據預設,如果有檔案現存於指定的路徑,Export-CSV 將覆寫該檔案而不顯示警告。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoTypeInformation</maml:name> <maml:description> <maml:para>省略 CSV 檔案的型別資訊標頭。根據預設,CSV 檔案的第一行會包含 "#TYPE ",後面接著 .NET Framework 物件型別的完整名稱。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Delimiter</maml:name> <maml:description> <maml:para>指定分隔屬性值的分隔符號。預設為逗號 (,)。請輸入字元,例如分號 (:)。若要指定分號 (;),請將其置於引號內。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">char</command:parameterValue> <dev:type> <maml:name>char</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>, (逗號)</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定 CSV 匯出檔的編碼。有效的值包括 Unicode、UTF7、UTF8、ASCII、UTF32、BigEndianUnicode、Default 和 OEM。預設為 ASCII。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>ASCII</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>毫無預警地覆寫路徑中指定的檔案。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要匯出成 CSV 字串的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。您也可經由管道將物件輸出至 Export-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>不覆寫 (取代) 現有檔案的內容。根據預設,如果有檔案現存於指定的路徑,Export-CSV 將覆寫該檔案而不顯示警告。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoTypeInformation</maml:name> <maml:description> <maml:para>省略 CSV 檔案的型別資訊標頭。根據預設,CSV 檔案的第一行會包含 "#TYPE ",後面接著 .NET Framework 物件型別的完整名稱。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定 CSV 輸出檔的路徑。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UseCulture</maml:name> <maml:description> <maml:para>使用目前文化特性的清單分隔符號做為項目分隔符號。預設為逗號 (,)。 此參數針對發佈給全球使用者的指令碼很有用。若要尋找文化特性的清單分隔符號,請使用下列命令:(Get-Culture).TextInfo.ListSeparator。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>逗號</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何 .NET Framework 物件輸出至 Export-CSV。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> CSV 清單會傳送至 Path 參數所指定的檔案。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> Export-CSV Cmdlet 會將您所送出的物件轉換成一連串長度可變的 CSV 字串,並將它們儲存到指定的文字檔。您可以使用 Export-CSV 將物件儲存到 CSV 檔案,然後使用 Import-CSV Cmdlet 從該 CSV 檔案中的文字建立物件。 在 CSV 檔案中,每個物件都會由逗號分隔物件屬性值的清單來代表。屬性值會轉換成字串 (利用物件的 ToString() 方法),所以一般由屬性值的名稱來代表。Export-CSV 並不會匯出物件的方法。 匯出檔的格式如下: -- CSV 檔案的第一行包含 '#TYPE ' 字串,後面接著 .NET Framework 物件型別的完整名稱,例如 #TYPE System.Diagnostics.Process。若要隱藏這一行,請使用 NoTypeInformation 參數。 -- CSV 檔案的第二行代表欄標頭,而且包含逗號分隔第一個物件所有屬性名稱的清單。 -- CSV 檔案的其他行包含逗號分隔每個物件屬性值的清單。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process wmiprvse | select-object basePriority,ID,SessionID,WorkingSet | export-csv -path data.csv </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令選取 wmiprvse 處理序的幾個屬性,並將它們匯出至名為 data.csv 的 CSV 格式檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | export-csv processes.csv C:\PS> get-process | export-csv processes.csv # In processes.csv #TYPE System.Diagnostics.Process __NounName,Name,Handles,VM,WS,PM,NPM,Path,Company,CPU,FileVersion,... Process,powershell,626,201666560,76058624,61943808,11960,C:\WINDOWS... Process,powershell,257,151920640,38322176,37052416,7836,C:\WINDOWS\... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將那些代表電腦上處理序的物件匯出到目前目錄中的 Processes.csv 檔案,因為沒有指定分隔符號,該檔案中的欄位用逗號 (,) 分隔。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | export-csv processes.csv -Delimiter ";" # In processes.csv #TYPE System.Diagnostics.Process __NounName;Name;Handles;VM;WS;PM;NPM;Path;Company;CPU;FileVersion;... Process;powershell;626;201666560;76058624;61943808;11960;C:\WINDOWS... Process;powershell;257;151920640;38322176;37052416;7836;C:\WINDOWS\... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將那些代表電腦上處理序的物件匯出到目前目錄中的 Processes.csv 檔案,並使用 Delimiter 參數指定分號 (;)。因此,該檔案中的欄位之間是以分號分隔。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | export-csv processes.csv -UseCulture </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將那些代表電腦上處理序的物件匯出到目前目錄中的 Processes.csv 檔案,並使用 UseCulture 參數指示 Export-CSV 使用目前文化特性的 ListSeparator 屬性所指定的分隔符號。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | export-csv processes.csv -NoTypeInformation C:\PS> get-process | export-csv processes.csv -NoTypeInformation # In processes.csv __NounName,Name,Handles,VM,WS,PM,NPM,Path,Company,CPU,FileVersion,... Process,powershell,626,201666560,76058624,61943808,11960,C:\WINDOWS... Process,powershell,257,151920640,38322176,37052416,7836,C:\WINDOWS\... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將那些代表電腦上處理序的物件匯出到目前目錄中的 Processes.csv 檔案,並使用 NoTypeInformation 參數隱藏該檔案中的型別資訊。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113299</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertTo-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertFrom-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Export-FormatData </command:name> <maml:description> <maml:para>將目前工作階段的格式化資料儲存到格式化檔案中。 </maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Export</command:verb> <command:noun>FormatData</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Export-FormatData Cmdlet 會從目前工作階段的格式化物件建立 Windows PowerShell 格式化檔案 (format.ps1xml)。它會採用 Get-FormatData 傳回的 ExtendedTypeDefinition 物件,並以 XML 格式將其儲存在檔案中。 Windows PowerShell 會使用格式化檔案 (format.ps1xml) 中的資料,在工作階段中產生 Microsoft .NET Framework 物件的預設顯示。您可以檢視及編輯格式化檔案,並使用 Update-FormatData Cmdlet 將格式化資料加入至工作階段。 如需 Windows PowerShell 中格式化檔案的詳細資訊,請參閱 about_Format.ps1xml。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Export-FormatData</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>覆寫現有輸出檔案,即使檔案有唯讀屬性亦然。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IncludeScriptBlock</maml:name> <maml:description> <maml:para>判斷是否匯出格式資料中的指令碼區塊。 因為指令碼區塊包含程式碼而且可能會遭人惡意利用,所以預設情況下不會將其匯出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要匯出的格式資料物件。輸入包含物件的變數或是可取得物件的命令,如 Get-FormatData 命令。您也可以經由管道將物件從 Get-FormatData 輸出至 Export-FormatData。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">ExtendedTypeDefinition[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>防止此 Cmdlet 覆寫現有的檔案。根據預設,Export-FormatData 會覆寫檔案而不顯示警告,除非檔案具有唯讀屬性。 若要指示 Export-FormatData 覆寫唯讀檔案,請使用 Force 參數。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定輸出檔的位置。請輸入路徑 (選擇性) 以及副檔名為 format.ps1xml 的檔案名稱。如果您省略路徑,Export-FormatData 會在目前的目錄中建立檔案。 如果您使用 .ps1xml 以外的副檔名,Update-FormatData Cmdlet 將無法辨識檔案。 如果您指定現有檔案,除非該檔案擁有唯讀屬性,否則 Export-FormatData 便會覆寫該檔案而不顯示警告。若要覆寫唯讀檔案,請使用 Force 參數。若要避免檔案遭到覆寫,請使用 NoClobber 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>覆寫現有輸出檔案,即使檔案有唯讀屬性亦然。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IncludeScriptBlock</maml:name> <maml:description> <maml:para>判斷是否匯出格式資料中的指令碼區塊。 因為指令碼區塊包含程式碼而且可能會遭人惡意利用,所以預設情況下不會將其匯出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要匯出的格式資料物件。輸入包含物件的變數或是可取得物件的命令,如 Get-FormatData 命令。您也可以經由管道將物件從 Get-FormatData 輸出至 Export-FormatData。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">ExtendedTypeDefinition[]</command:parameterValue> <dev:type> <maml:name>ExtendedTypeDefinition[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>防止此 Cmdlet 覆寫現有的檔案。根據預設,Export-FormatData 會覆寫檔案而不顯示警告,除非檔案具有唯讀屬性。 若要指示 Export-FormatData 覆寫唯讀檔案,請使用 Force 參數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定輸出檔的位置。請輸入路徑 (選擇性) 以及副檔名為 format.ps1xml 的檔案名稱。如果您省略路徑,Export-FormatData 會在目前的目錄中建立檔案。 如果您使用 .ps1xml 以外的副檔名,Update-FormatData Cmdlet 將無法辨識檔案。 如果您指定現有檔案,除非該檔案擁有唯讀屬性,否則 Export-FormatData 便會覆寫該檔案而不顯示警告。若要覆寫唯讀檔案,請使用 Force 參數。若要避免檔案遭到覆寫,請使用 NoClobber 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.ExtendedTypeDefinition</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可以經由管道將 ExtendedTypeDefinition 物件從 Get-FormatData 輸出至 Export-FormatData。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Export-FormatData 不會傳回任何物件。它會產生檔案,並將它儲存到指定的路徑中。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 若要使用任何格式化檔案,包括匯出的格式化檔案,工作階段的執行原則必須允許執行指令碼和組態檔。如需詳細資訊,請參閱 about_Execution_Policies。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-formatdata -typename * | export-formatdata -path allformat.ps1xml -IncludeScriptBlock </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將工作階段中的所有格式資料匯出到 AllFormat.ps1xml 檔案。 此命令會使用 Get-FormatData Cmdlet 取得工作階段中的格式資料。如果 TypeName 參數值為 * (全部),則會指示此 Cmdlet 取得工作階段中的所有資料。 此命令會使用管線運算子 (|) 將格式資料從 Get-FormatData 命令傳送到 Export-FormatData Cmdlet,此 Cmdlet 會將格式資料匯出到 AllFormat.ps1 檔案。 Export-FormatData 命令會使用 IncludeScriptBlock 參數,在檔案的格式資料中包含指令碼區塊。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $f = get-formatdata -typename helpinfoshort C:\PS> export-formatdata -inputObject $f -path c:\test\help.format.ps1xml -IncludeScriptBlock </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將 HelpInfoShort 型別的格式資料匯出到 Help.format.ps1xml 檔案。 第一個命令會使用 Get-FormatData Cmdlet 取得 HelpInfoShort 型別的格式資料,並將它儲存在 $f 變數中。 第二個命令會使用 Export-FormatData 的 InputObject 參數,輸入 $f 格式內所儲存的格式資料。此命令也會使用 IncludeScriptBlock 參數,在輸出中包含指令碼區塊。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-formatdata -typename System.Diagnostics.Process | export-FormatData -path process.format.ps1xml C:\PS> Update-FormatData -prependPath .\process.format.ps1xml C:\PS> get-process p* Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 323 5600 powershell 336 3900 powershell_ise 138 4076 PresentationFontCache </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會示範從 Export-FormatData 命令省略 IncludeScriptBlock 參數所產生的影響。 第一個命令會使用 Get-FormatData Cmdlet 取得 Get-Process Cmdlet 所傳回之 System.Diagnostics.Process 物件的格式資料。此命令會使用管線運算子 (|) 將格式化資料傳送給 Export-FormatData Cmdlet,此 Cmdlet 會將它匯出到目前目錄中的 Process.format.ps1xml 檔案。 在此例中,Export-FormatData 命令不會使用 IncludeScriptBlock 參數。 第二個命令會使用 Update-FormatData Cmdlet 將 Process.format.ps1xml 檔案加入至目前的工作階段。此命令會使用 PrependPath 參數來確定先找到 Process.format.ps1xml 檔案中處理序物件的格式化資料,然後再找到處理序物件的標準格式化資料。 第三個命令會顯示這項變更的影響。此命令會使用 Get-Process Cmdlet 取得名稱開頭為 "P" 的處理序。輸出顯示使用指令碼區塊所計算的屬性值將會從顯示畫面中遺漏。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=144302</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-FormatData</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Update-FormatData</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Export-PSSession </command:name> <maml:description> <maml:para>從另一個工作階段匯入命令,並將其儲存在 Windows PowerShell 模組中。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Export</command:verb> <command:noun>PSSession</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Export-PSSession Cmdlet 會從本機或遠端電腦上的另一個 PSSession 取得 Cmdlet、函數、別名和其他命令類型,並將它們儲存到 Windows PowerShell 模組中。若要將此模組中的命令加入至目前的工作階段,請使用 Import-Module Cmdlet。 不像 Import-PSSession 從另一個 PSSession 將命令匯入目前工作階段,Export-PSSession 會將命令儲存到模組中,而不會將命令匯入目前工作階段。 若要匯出命令,請先使用 New-PSSession Cmdlet 建立具有您所要匯出之命令的 PSSession,再使用 Export-PSSession Cmdlet 匯出命令。根據預設,Export-PSSession 除了已存在於目前工作階段中的命令以外,所有命令都會匯出,但是您可以用 CommandName 參數指定要匯出的命令。 Export-PSSession Cmdlet 會使用 Windows PowerShell 的隱含遠端功能。當您將命令匯入目前的工作階段時,這些命令就會以隱含方式執行於原始工作階段,或是執行於原始電腦的類似工作階段。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Export-PSSession</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Session</maml:name> <maml:description> <maml:para>指定從中匯出命令的 PSSession。請輸入包含工作階段物件的變數或可取得工作階段物件的命令,例如 Get-PSSession 命令。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSSession</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>OutputModule</maml:name> <maml:description> <maml:para>針對 Export-PSSession 所建立的模組指定路徑 (選擇性) 和名稱。預設路徑為 $home\Documents\WindowsPowerShell\Modules。此參數為必要項。 如果 Export-PSSession 所建立的模組子目錄或任何檔案已經存在,此命令就會失敗。若要覆寫現有的檔案,請使用 Force 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="3"> <maml:name>CommandName</maml:name> <maml:description> <maml:para>只匯出有指定的名稱或名稱模式的命令。允許使用萬用字元。請使用 "CommandName" 或其別名 "Name"。 根據預設,Export-PSSession 會從 PSSession 匯出所有命令,但與目前工作階段中的命令同名的命令則除外。這樣可防止匯入的命令隱藏或取代目前工作階段中的命令。若要匯出所有命令,即使是隱藏或取代其他命令的那些命令,請使用 AllowClobber 參數。 如果您使用 CommandName 參數,則除非您使用 FormatTypeName 參數,否則不會匯出命令的格式化檔案。同樣地,如果您使用 FormatTypeName 參數,則除非您使用 CommandName 參數,否則不會匯出命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="4"> <maml:name>FormatTypeName</maml:name> <maml:description> <maml:para>只匯出指定之 Microsoft .NET Framework 型別的格式化指示。請輸入型別名稱。根據預設,Export-PSSession 會針對不在 System.Management.Automation 命名空間的所有 .NET Framework 型別匯出格式化指示。 這個參數的值必須是匯入命令之來源工作階段中的 Get-FormatData 命令所傳回的型別名稱。若要取得遠端工作階段中的所有格式化資料,請輸入 *。 如果您使用 FormatTypeName 參數,則除非您使用 CommandName 參數,否則不會匯出命令。 同樣地,如果您使用 CommandName 參數,則除非您使用 FormatTypeName 參數,否則不會匯出命令的格式化檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AllowClobber</maml:name> <maml:description> <maml:para>匯出指定的命令,即使這些命令與目前工作階段中的命令同名亦然。 如果您匯入與目前工作階段中的命令同名的命令,則匯入的命令會隱藏或取代原始命令。如需詳細資訊,請參閱 about_Command_Precedence。 Export-PSSession 不會匯入與目前工作階段中的命令同名的命令。預設行為的設計目的是要防止命令名稱發生衝突。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>ArgumentList</maml:name> <maml:description> <maml:para>匯出因使用指定的引數 (參數值) 所產生的命令變化。 例如,若要從 $s 的 PSSession 匯出憑證 (Cert:) 磁碟機中 Get-Item 命令的變化,請輸入"export-pssession -session $s -command get-item -argumentlist cert:"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CommandType</maml:name> <maml:description> <maml:para>只匯出指定類型的命令物件。請使用 "CommandType" 或其別名 "Type"。 有效的值包括: -- Alias:目前工作階段中的所有 Windows PowerShell 別名。 -- All:所有命令類型。它的作用相當於 "get-command *"。 -- Application:Path 環境變數 ($env:path) 所列出之路徑中所有非 Windows PowerShell 的檔案,包括 .txt、.exe 和 .dll 檔案。 -- Cmdlet:目前工作階段中的 Cmdlet。預設為 "Cmdlet"。 --ExternalScript:Path 環境變數 ($env:path) 所列出之路徑中的所有 .ps1 檔案。 -- Filter 和 Function:所有 Windows PowerShell 函數。 -- Script:目前工作階段中的指令碼區塊。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Alias</command:parameterValue> <command:parameterValue required="false" variableLength="false">Function</command:parameterValue> <command:parameterValue required="false" variableLength="false">Filter</command:parameterValue> <command:parameterValue required="false" variableLength="false">Cmdlet</command:parameterValue> <command:parameterValue required="false" variableLength="false">ExternalScript</command:parameterValue> <command:parameterValue required="false" variableLength="false">Application</command:parameterValue> <command:parameterValue required="false" variableLength="false">Script</command:parameterValue> <command:parameterValue required="false" variableLength="false">All</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定輸出檔的編碼。有效的值包括 "Unicode"、"UTF7"、"UTF8"、"ASCII"、"UTF32"、"BigEndianUnicode"、"Default" 和 "OEM"。預設為 "UTF-8"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>覆寫一個或多個現有的輸出檔案,即使檔案有唯讀屬性亦然。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Module</maml:name> <maml:description> <maml:para>只匯出指定的 Windows PowerShell 嵌入式管理單元和模組中的命令。請輸入嵌入式管理單元和模組的名稱。不允許使用萬用字元。 如需詳細資訊,請參閱 about_PSSnapins 和 Import-Module。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AllowClobber</maml:name> <maml:description> <maml:para>匯出指定的命令,即使這些命令與目前工作階段中的命令同名亦然。 如果您匯入與目前工作階段中的命令同名的命令,則匯入的命令會隱藏或取代原始命令。如需詳細資訊,請參閱 about_Command_Precedence。 Export-PSSession 不會匯入與目前工作階段中的命令同名的命令。預設行為的設計目的是要防止命令名稱發生衝突。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>ArgumentList</maml:name> <maml:description> <maml:para>匯出因使用指定的引數 (參數值) 所產生的命令變化。 例如,若要從 $s 的 PSSession 匯出憑證 (Cert:) 磁碟機中 Get-Item 命令的變化,請輸入"export-pssession -session $s -command get-item -argumentlist cert:"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="3"> <maml:name>CommandName</maml:name> <maml:description> <maml:para>只匯出有指定的名稱或名稱模式的命令。允許使用萬用字元。請使用 "CommandName" 或其別名 "Name"。 根據預設,Export-PSSession 會從 PSSession 匯出所有命令,但與目前工作階段中的命令同名的命令則除外。這樣可防止匯入的命令隱藏或取代目前工作階段中的命令。若要匯出所有命令,即使是隱藏或取代其他命令的那些命令,請使用 AllowClobber 參數。 如果您使用 CommandName 參數,則除非您使用 FormatTypeName 參數,否則不會匯出命令的格式化檔案。同樣地,如果您使用 FormatTypeName 參數,則除非您使用 CommandName 參數,否則不會匯出命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>工作階段中的所有命令。</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CommandType</maml:name> <maml:description> <maml:para>只匯出指定類型的命令物件。請使用 "CommandType" 或其別名 "Type"。 有效的值包括: -- Alias:目前工作階段中的所有 Windows PowerShell 別名。 -- All:所有命令類型。它的作用相當於 "get-command *"。 -- Application:Path 環境變數 ($env:path) 所列出之路徑中所有非 Windows PowerShell 的檔案,包括 .txt、.exe 和 .dll 檔案。 -- Cmdlet:目前工作階段中的 Cmdlet。預設為 "Cmdlet"。 -- ExternalScript:Path 環境變數 ($env:path) 所列出之路徑中的所有 .ps1 檔案。 -- Filter 和 Function:所有 Windows PowerShell 函數。 -- Script:目前工作階段中的指令碼區塊。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CommandTypes</command:parameterValue> <dev:type> <maml:name>CommandTypes</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>工作階段中的所有命令。</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定輸出檔的編碼。有效的值包括 "Unicode"、"UTF7"、"UTF8"、"ASCII"、"UTF32"、"BigEndianUnicode"、"Default" 和 "OEM"。預設為 "UTF-8"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>UTF-8</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>覆寫一個或多個現有的輸出檔案,即使檔案有唯讀屬性亦然。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="4"> <maml:name>FormatTypeName</maml:name> <maml:description> <maml:para>只匯出指定之 Microsoft .NET Framework 型別的格式化指示。請輸入型別名稱。根據預設,Export-PSSession 會針對不在 System.Management.Automation 命名空間的所有 .NET Framework 型別匯出格式化指示。 這個參數的值必須是匯入命令之來源工作階段中的 Get-FormatData 命令所傳回的型別名稱。若要取得遠端工作階段中的所有格式化資料,請輸入 *。 如果您使用 FormatTypeName 參數,則除非您使用 CommandName 參數,否則不會匯出命令。 同樣地,如果您使用 CommandName 參數,則除非您使用 FormatTypeName 參數,否則不會匯出命令的格式化檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Module</maml:name> <maml:description> <maml:para>只匯出指定的 Windows PowerShell 嵌入式管理單元和模組中的命令。請輸入嵌入式管理單元和模組的名稱。不允許使用萬用字元。 如需詳細資訊,請參閱 about_PSSnapins 和 Import-Module。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>工作階段中的所有命令。</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>OutputModule</maml:name> <maml:description> <maml:para>針對 Export-PSSession 所建立的模組指定路徑 (選擇性) 和名稱。預設路徑為 $home\Documents\WindowsPowerShell\Modules。此參數為必要項。 如果 Export-PSSession 所建立的模組子目錄或任何檔案已經存在,此命令就會失敗。若要覆寫現有的檔案,請使用 Force 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Session</maml:name> <maml:description> <maml:para>指定從中匯出命令的 PSSession。請輸入包含工作階段物件的變數或可取得工作階段物件的命令,例如 Get-PSSession 命令。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSSession</command:parameterValue> <dev:type> <maml:name>PSSession</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將物件輸出至 Export-PSSession。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.IO.FileInfo</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Export-PSSession 會傳回由它所建立之模組所組成的檔案清單。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> Export-PSSession 依存於 Windows PowerShell 遠端基礎結構。若要使用此 Cmdlet,電腦必須有設定遠端功能。如需詳細資訊,請參閱 about_Remote_Requirements。 您無法使用 Export-PSSession 匯出 Windows PowerShell 提供者。 匯出的命令會以隱含方式執行於其匯出的來源 PSSession。但是,在遠端執行命令的細節則是完全由 Windows PowerShell 處理。您可以執行匯出的命令,就像是執行本機命令一樣。 Export-Module 會在它所匯出的模組中擷取及儲存有關 PSSession 的資訊。如果當您匯入模組時,匯出這些命令的來源 PSSession 已關閉,而且相同的電腦上沒有使用中的 PSSessions,則此模組中的命令會嘗試重新建立 PSSession。如果嘗試重新建立 PSSession 的作業失敗,將不會執行匯出的命令。 Export-Module 在模組中所擷取及儲存的工作階段資訊並不包含工作階段選項,例如您在 $PSSessionOption 自動變數中指定的選項,或是使用 New-PSSession、Enter-PSSession 或 Invoke-Command Cmdlet 的 SessionOption 參數所指定的選項。如果當您匯入模組時,原始 PSSession 已關閉,此模組將會使用相同電腦上的另一個 PSSession (如果有的話)。若要讓匯入的命令能夠在正確設定的工作階段中執行,請使用您想要的選項來建立 PSSession,然後再匯入此模組。 為了尋找要匯出的命令,Export-PSSession 會使用 Invoke-Command Cmdlet 在 PSSession 中執行 Get-Command 命令。為了取得及儲存命令的格式化資料,它會使用 Get-FormatData 和 Export-FormatData Cmdlet。當您執行 Export-PSSession 命令時,您可能會看到來自 Invoke-Command、Get-Command、Get-FormatData 和 Export-FormatData 的錯誤訊息。此外,Export-PSSession 無法從未包含 Get-Command、Get-FormatData、Select-Object 和 Get-Help Cmdlet 的工作階段匯出命令。 Export-PSSession 會使用 Write-Progress Cmdlet 顯示命令的進度。您可能會在命令執行時看到進度列。 匯出的命令與其他遠端命令都有相同限制,包括無法啟動有使用者介面的程式,例如 [記事本]。 因為 Windows PowerShell 設定檔無法在 PSSessions 中執行,設定檔新增到工作階段中的命令將不會提供給 Export-PSSession。若要從設定檔匯出命令,請在匯出命令之前使用 Invoke-Command 命令,以手動方式在 PSSession 中執行設定檔。 Export-PSSession 所建立的模組可能包含格式化檔案,即使此命令未匯入格式化資料亦然。如果此命令未匯入格式化資料,所有建立的格式化檔案都不會包含格式化資料。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $s = new-pssession -computerName Server01 C:\PS> export-pssession -session $s -outputModule Server01 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>此範例的命令會從 Server01 電腦上的 PSSession 將所有命令匯出到本機電腦上的 Server01 模組,但與目前工作階段中的命令同名的命令則除外。它也會匯出命令的格式化資料。 第一個命令會在 Server01 電腦上建立 PSSession。第二個命令會將工作階段中的命令和格式化資料匯出到 Server01 模組。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $s = new-pssession -ConnectionUri http://exchange.microsoft.com/mailbox -credential exchangeadmin01@hotmail.com -authentication negotiate C:\PS> export-pssession -session $r -module exch* -commandname get-*, set-* -formattypename * -outputModule $pshome\Modules\Exchange -encoding ASCII </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會從遠端電腦上的 Microsoft Exchange Server 嵌入式管理單元,將 Get 和 Set 命令匯出到本機電腦上 $pshome\Modules 目錄的 Exchange 模組。 將此模組放在 $pshome\Module 目錄中可讓電腦的所有使用者更方便存取它。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $s = new-pssession -computerName Server01 -credential Server01\User01 C:\PS> export-pssession -session $s -outputModule TestCmdlets -type cmdlet -commandname *test* -formattypename * C:\PS> remove-pssession $s C:\PS> import-module TestCmdlets C:\PS> get-help test* C:\PS> test-files </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會從遠端電腦上的 PSSession 匯出 Cmdlet,並將其儲存到本機電腦上的模組。然後,這些命令會將模組中的 Cmdlet 加入至目前的工作階段,以便於使用。 第一個命令會在 Server01 電腦上建立 PSSession,然後將其儲存到 $s 變數。 第二個命令會從 $s 中的 PSSession 將名稱開頭為 "Test" 的 Cmdlet 匯出到本機電腦的 TestCmdlets 模組。 第三個命令會使用 Remove-PSSession Cmdlet 從目前工作階段中刪除 $s 中的 PSSession。這個命令顯示 PSSession 不需要使用中,也可以使用從它匯入的命令。 第四個命令會使用 Import-Module Cmdlet 將 TestCmdlets 模組中的 Cmdlet 加入至目前工作階段,而這個命令隨時都能在任何工作階段中執行。 第五個命令會使用 Get-Help Cmdlet 取得名稱開頭為 "Test" 之 Cmdlet 的說明。在將模組中的命令加入至目前工作階段之後,您就可以使用 Get-Help 和 Get-Command Cmdlet 深入了解匯入的命令,就如同工作階段中的任何命令一樣。 第六個命令會使用 Test-Files Cmdlet,此 Cmdlet 是從 Server01 電腦所匯出,然後再加入至工作階段而得來。 Test-Files 命令實際上是在此命令匯入來源之電腦上的遠端工作階段執行,但是這無法明顯看出來。Windows PowerShell 會從模組中所儲存的資訊建立工作階段。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> export-pssession -session $s -AllowClobber -outputModule AllCommands </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從 $s 變數中的 PSSession 將所有命令和所有格式化資料匯出到目前工作階段。這些命令會使用 AllowClobber 參數來包含與目前工作階段中的命令同名的命令。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $options = New-PSSessionOption -NoMachineProfile C:\PS> $s = new-pssession -computername Server01 -sessionoption $options C:\PS> export-pssession -session $s -outputModule Server01 C:\PS> remove-pssession $s C:\PS> new-pssession -computername Server01 -sessionoption $options C:\PS> import-module Server01 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例顯示當匯出這些命令的來源 PSSession 關閉時,如何在工作階段中使用特定的選項執行匯出的命令。 當您使用 Export-PSSession 時,它會在它所建立的模組中儲存有關原始 PSSession 的資訊。當您匯入此模組時,如果原始的遠端工作階段已關閉,此模組將會使用連接到原始電腦的任何開啟的遠端工作階段。 如果目前的工作階段並未包含與原始電腦之間的遠端工作階段,此模組中的命令將會重新建立與該電腦之間的工作階段。但是,Export-PSSession 並不會在模組中儲存特殊選項,例如使用 New-PSSession 的 SessionOption 參數所設定的選項。 因此,如果您想要在遠端工作階段中使用特定選項來執行匯出的命令,您必須使用您想要的選項來建立遠端工作階段,然後再匯入此模組。 第一個命令會使用 New-PSSessionOption Cmdlet 來建立 PSSessionOption 物件,並將此物件儲存在 $options 變數中。 第二個命令會建立包含指定之選項的 PSSession,此命令會使用 New-PSSession Cmdlet,在 Server01 電腦上建立 PSSession。此命令也會使用 SessionOption 參數提交 $options 中的選項物件。 第三個命令會使用 Export-PSSession Cmdlet,從 $s 中的 PSSession 將命令匯出到 Server01 模組。 第四個命令會使用 Remove-PSSession Cmdlet 刪除 $s 變數中的 PSSession。 第五個命令會使用 New-PSSession Cmdlet,建立連接至 Server01 電腦的新 PSSession。這個 PSSession 也會使用 $options 變數中的工作階段選項。 第六個命令會使用 Import-Module Cmdlet 匯入 Server01 模組中的命令,此模組中的命令會在 Server01 電腦上的 PSSession 中執行。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135213</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Command_Precedence</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-PSSession</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-PSSession</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-Module</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Invoke-Command</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_PSSessions</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Format-Custom </command:name> <maml:description> <maml:para>使用自訂檢視來格式化輸出。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Format</command:verb> <command:noun>Custom</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Format-Custom Cmdlet 會按照替代檢視中定義的方式,格式化命令的輸出。Format-Custom 是專為顯示純粹表格或純粹清單以外的檢視而設計。您可以使用 Windows PowerShell 目錄中 *format.PS1XML 檔案所定義的檢視,也可以在新的 PS1XML 檔案中自行建立檢視,再使用 Update-FormatData Cmdlet 將所建立的檢視加入至 Windows PowerShell。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Format-Custom</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定呈現在畫面上的物件屬性及其呈現的順序。允許使用萬用字元。 如果省略此參數,呈現在畫面上的屬性將依所顯示的物件而定。參數名稱 ("Property") 為選擇項。同一個命令不能同時使用 Property 和 View 參數。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Expression <字串> 或 <指令碼區塊> -- Depth <int32></maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Depth</maml:name> <maml:description> <maml:para>指定畫面上顯示的欄數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayError</maml:name> <maml:description> <maml:para>在命令列顯示錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Expand</maml:name> <maml:description> <maml:para>將集合物件連同集合中的物件一併格式化。此參數係設計為對支援 ICollection (System.Collections) 介面的物件進行格式化。預設值為 EnumOnly。 有效的值包括: -- EnumOnly:顯示集合中各物件的屬性。 -- CoreOnly:顯示集合物件的屬性。 -- Both:顯示集合物件的屬性,以及集合中各物件的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>指示 Cmdlet 顯示所有的錯誤資訊。請與 DisplayError 或 ShowError 參數搭配使用。根據預設,當錯誤物件寫入錯誤或顯示的資料流時,只會顯示一部分的錯誤資訊。 </maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>GroupBy</maml:name> <maml:description> <maml:para>依據共用屬性或值,將輸出格式化為群組。請輸入運算式或指定輸出的屬性。 GroupBy 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要格式化的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ShowError</maml:name> <maml:description> <maml:para>透過管線傳送錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>View</maml:name> <maml:description> <maml:para>指定替代格式或「檢視」的名稱。如果省略此參數,Format-Custom 會使用預設的自訂檢視。同一個命令不能同時使用 Property 和 View 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Depth</maml:name> <maml:description> <maml:para>指定畫面上顯示的欄數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayError</maml:name> <maml:description> <maml:para>在命令列顯示錯誤。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Expand</maml:name> <maml:description> <maml:para>將集合物件連同集合中的物件一併格式化。此參數係設計為對支援 ICollection (System.Collections) 介面的物件進行格式化。預設值為 EnumOnly。 有效的值包括: -- EnumOnly:顯示集合中各物件的屬性。 -- CoreOnly:顯示集合物件的屬性。 -- Both:顯示集合物件的屬性,以及集合中各物件的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>指示 Cmdlet 顯示所有的錯誤資訊。請與 DisplayError 或 ShowError 參數搭配使用。根據預設,當錯誤物件寫入錯誤或顯示的資料流時,只會顯示一部分的錯誤資訊。 </maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>GroupBy</maml:name> <maml:description> <maml:para>依據共用屬性或值,將輸出格式化為群組。請輸入運算式或指定輸出的屬性。 GroupBy 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要格式化的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定呈現在畫面上的物件屬性及其呈現的順序。允許使用萬用字元。 如果省略此參數,呈現在畫面上的屬性將依所顯示的物件而定。參數名稱 ("Property") 為選擇項。同一個命令不能同時使用 Property 和 View 參數。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Expression <字串> 或 <指令碼區塊> -- Depth <int32></maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ShowError</maml:name> <maml:description> <maml:para>透過管線傳送錯誤。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>View</maml:name> <maml:description> <maml:para>指定替代格式或「檢視」的名稱。如果省略此參數,Format-Custom 會使用預設的自訂檢視。同一個命令不能同時使用 Property 和 View 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Format-Custom </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>Microsoft.PowerShell.Commands.Internal.Format</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Format-Custom 會傳回代表顯示的格式物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> Format-Custom 是專為顯示純粹表格或純粹清單以外的檢視而設計。若要顯示替代表格檢視,請使用 Format-Table。若要顯示替代清單檢視,請使用 Format-List。 您也可以利用內建的別名 "fc" 來參照 Format-Custom。如需詳細資訊,請參閱 about_Aliases。 GroupBy 參數會假設物件已經過排序。在使用 Format-Custom 將物件分組之前,請先使用 Sort-Object 將物件排序。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-command start-transcript | format-custom -view MyView </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令使用 MyView 檢視 (使用者建立的自訂檢視) 定義的格式,將有關 Start-Transcript Cmdlet 的資訊格式化。若要成功執行這個命令,必須先建立新的 PS1XML 檔案、定義 MyView 檢視,然後使用 Update-FormatData 命令將 PS1XML 檔案加入至 Windows PowerShell。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process Winlogon | format-custom </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會以替代的自訂檢視來格式化 Winlogon 處理序的資訊。因為此命令沒有使用 View 參數,所以 Format-Custom 使用預設的自訂檢視來格式化資料。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113301</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Format-List </command:name> <maml:description> <maml:para>將輸出格式化成屬性的清單,其中每個屬性都會在新的一行中出現。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Format</command:verb> <command:noun>List</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Format-List Cmdlet 將命令的輸出格式化為屬性的清單,其中每個屬性都顯示在個別的一行中。您可以使用 Format-List 將物件的所有或所選屬性格式化並顯示為清單 (format-list *)。 因為每個項目在清單中,比在表格中有更多的空間可用,所以 Windows PowerShell 可在清單中顯示更多的物件屬性,而且屬性值也比較不可能被截斷。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Format-List</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定呈現在畫面上的物件屬性及其呈現的順序。允許使用萬用字元。 如果省略此參數,呈現在畫面上的屬性將依所顯示的物件而定。參數名稱 ("Property") 為選擇項。同一個命令不能同時使用 Property 和 View 參數。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayError</maml:name> <maml:description> <maml:para>在命令列顯示錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Expand</maml:name> <maml:description> <maml:para>將集合物件連同集合中的物件一併格式化。此參數係設計為對支援 ICollection (System.Collections) 介面的物件進行格式化。預設值為 EnumOnly。 有效的值包括: -- EnumOnly:顯示集合中各物件的屬性。 -- CoreOnly:顯示集合物件的屬性。 -- Both:顯示集合物件的屬性,以及集合中各物件的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>指示 Cmdlet 顯示所有的錯誤資訊。請與 DisplayError 或 ShowError 參數搭配使用。根據預設,當錯誤物件寫入錯誤或顯示的資料流時,只會顯示一部分的錯誤資訊。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>GroupBy</maml:name> <maml:description> <maml:para>依據共用屬性或值,將輸出格式化為群組。請輸入運算式或指定輸出的屬性。 GroupBy 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要格式化的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ShowError</maml:name> <maml:description> <maml:para>透過管線傳送錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>View</maml:name> <maml:description> <maml:para>指定替代清單格式或「檢視」的名稱。同一個命令不能同時使用 Property 和 View 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayError</maml:name> <maml:description> <maml:para>在命令列顯示錯誤。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Expand</maml:name> <maml:description> <maml:para>將集合物件連同集合中的物件一併格式化。此參數係設計為對支援 ICollection (System.Collections) 介面的物件進行格式化。預設值為 EnumOnly。 有效的值包括: -- EnumOnly:顯示集合中各物件的屬性。 -- CoreOnly:顯示集合物件的屬性。 -- Both:顯示集合物件的屬性,以及集合中各物件的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>指示 Cmdlet 顯示所有的錯誤資訊。請與 DisplayError 或 ShowError 參數搭配使用。根據預設,當錯誤物件寫入錯誤或顯示的資料流時,只會顯示一部分的錯誤資訊。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>GroupBy</maml:name> <maml:description> <maml:para>依據共用屬性或值,將輸出格式化為群組。請輸入運算式或指定輸出的屬性。 GroupBy 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要格式化的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定呈現在畫面上的物件屬性及其呈現的順序。允許使用萬用字元。 如果省略此參數,呈現在畫面上的屬性將依所顯示的物件而定。參數名稱 ("Property") 為選擇項。同一個命令不能同時使用 Property 和 View 參數。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ShowError</maml:name> <maml:description> <maml:para>透過管線傳送錯誤。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>View</maml:name> <maml:description> <maml:para>指定替代清單格式或「檢視」的名稱。同一個命令不能同時使用 Property 和 View 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Format-List。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>Microsoft.PowerShell.Commands.Internal.Format</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Format-List 會傳回代表清單的格式物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以利用內建的別名 "FL" 來參照 Format-List。如需詳細資訊,請參閱 about_Aliases。 格式 Cmdlet (如 Format-List) 會排列要顯示的資料,但是不會顯示資料。資料是透過 Windows PowerShell 的輸出功能以及包含 Out 動詞 (Out Cmdlet) 的 Cmdlet 顯示出來,例如 Out-Host、Out-File 和 Out-Printer。 如果沒有使用格式 cmdlet,Windows PowerShell 便會為顯示的每個物件套用預設格式。 GroupBy 參數會假設物件已經過排序。在使用 Format-Custom 將物件分組之前,請先使用 Sort-Object 將物件排序。 使用 View 參數可為表格指定替代格式。您可以使用 Windows PowerShell 目錄中 *.format.PS1XML 檔案所定義的檢視,也可以在新的 PS1XML 檔案中自行建立檢視,再使用 Update-FormatData Cmdlet 將所建立的檢視包含在 Windows PowerShell 中。 View 參數的替代檢視必須使用清單格式,否則命令會失敗。如果替代檢視是一份表格,請使用 Format-Table。如果替代檢視既不是清單也不是表格,請使用 Format-Custom。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-service | format-list </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將電腦中的服務相關資訊格式化為清單。根據預設,會將服務格式化為表格。Get-Service Cmdlet 會取得在電腦中代表服務的物件。管線運算子 (|) 透過管線將結果傳遞給 Format-List。接著,Format-List 命令會將服務資訊格式化為清單,再將它傳送到預設輸出 Cmdlet 以供顯示。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-childitem $pshome\*.ps1xml </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令將 Windows PowerShell 目錄中 PS1XML 檔案的相關資訊顯示為清單。第一個命令取得代表檔案的物件,再將它們儲存在 $a 變數中。第二個命令則使用 Format-List 將 $a 中所儲存之有關物件的資訊格式化。這個命令會使用 InputObject 參數將此變數傳遞給 Format-List,然後後者會將格式化的輸出傳送到預設輸出 Cmdlet 以供顯示。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | format-list -property name, basepriority, priorityclass </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示電腦中每個處理序的名稱、基本優先順序和優先類別。它會使用 Get-Process Cmdlet 來取得代表每個處理序的物件。管線運算子 (|) 透過管線將處理序物件傳遞給 Format-List。Format-List 會將處理序格式化為指定的屬性清單。"Property" 參數名稱為選擇項,因此可以省略。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process winlogon | format-list -property * </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示 Winlogon 處理序的所有屬性。它會使用 Get-Process Cmdlet 來取得代表 Winlogon 處理序的物件。管線運算子 (|) 會透過管線將 Winlogon 處理序物件傳遞給 Format-List。命令使用 Property 參數來指定屬性,並以 * 表示所有屬性。因為 Property 參數的名稱為選擇性,您可以加以省略,而將命令輸入為:"format-list *"。Format-List 會自動將結果傳送到預設輸出 Cmdlet 以供顯示。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113302</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Format-Table </command:name> <maml:description> <maml:para>將輸出格式化為表格。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Format</command:verb> <command:noun>Table</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Format-Table Cmdlet 會將命令的輸出格式化為表格,其中每一欄都包含物件的選定屬性。物件類型決定每一欄顯示的預設配置和屬性,但是您可以使用 Property 參數來選取您想要看到的屬性。 您也可以使用雜湊表,將計算屬性新增到物件後再顯示物件,並指定表格中的欄標題。若要加入計算屬性,請使用 Property 或 GroupBy 參數。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Format-Table</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定呈現在畫面上的物件屬性及其呈現的順序。請輸入一個或多個屬性名稱 (用逗號分隔),或是使用雜湊表顯示計算屬性。允許使用萬用字元。 如果省略此參數,呈現在畫面上的屬性將依所顯示的物件而定。參數名稱 ("Property") 為選擇項。同一個命令不能同時使用 Property 和 View 參數。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串> -- Width <int32> -- Alignment (值可以是 "Left"、"Center" 或 "Right")</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AutoSize</maml:name> <maml:description> <maml:para>根據資料的寬度來調整欄大小和欄數。預設情況下,欄大小和欄數是由檢視決定。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayError</maml:name> <maml:description> <maml:para>在命令列顯示錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Expand</maml:name> <maml:description> <maml:para>將集合物件連同集合中的物件一併格式化。此參數係設計為對支援 ICollection (System.Collections) 介面的物件進行格式化。預設值為 EnumOnly。 有效的值包括: -- EnumOnly:顯示集合中各物件的屬性。 -- CoreOnly:顯示集合物件的屬性。 -- Both:顯示集合物件的屬性,以及集合中各物件的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>指示 Cmdlet 顯示所有的錯誤資訊。請與 DisplayError 或 ShowError 參數搭配使用。根據預設,當錯誤物件寫入錯誤或顯示的資料流時,只會顯示一部分的錯誤資訊。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>GroupBy</maml:name> <maml:description> <maml:para>依據屬性值,將已排序過的輸出排列在個別表格內。例如,GroupBy 可用來依據服務的狀態,將服務列入個別表格中。 請輸入運算式或指定輸出的屬性。輸出必須經過排序,才能傳送給 Format-Table。 GroupBy 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>HideTableHeaders</maml:name> <maml:description> <maml:para>剔除表格的欄標題。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要格式化的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ShowError</maml:name> <maml:description> <maml:para>透過管線傳送錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>View</maml:name> <maml:description> <maml:para>指定替代表格格式或「檢視」的名稱。同一個命令不能同時使用 Property 和 View 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Wrap</maml:name> <maml:description> <maml:para>將超過欄寬的文字顯示於下一行。預設情況下,超過欄寬的文字會被截斷。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AutoSize</maml:name> <maml:description> <maml:para>根據資料的寬度來調整欄大小和欄數。預設情況下,欄大小和欄數是由檢視決定。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayError</maml:name> <maml:description> <maml:para>在命令列顯示錯誤。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Expand</maml:name> <maml:description> <maml:para>將集合物件連同集合中的物件一併格式化。此參數係設計為對支援 ICollection (System.Collections) 介面的物件進行格式化。預設值為 EnumOnly。 有效的值包括: -- EnumOnly:顯示集合中各物件的屬性。 -- CoreOnly:顯示集合物件的屬性。 -- Both:顯示集合物件的屬性,以及集合中各物件的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>指示 Cmdlet 顯示所有的錯誤資訊。請與 DisplayError 或 ShowError 參數搭配使用。根據預設,當錯誤物件寫入錯誤或顯示的資料流時,只會顯示一部分的錯誤資訊。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>GroupBy</maml:name> <maml:description> <maml:para>依據屬性值,將已排序過的輸出排列在個別表格內。例如,GroupBy 可用來依據服務的狀態,將服務列入個別表格中。 請輸入運算式或指定輸出的屬性。輸出必須經過排序,才能傳送給 Format-Table。 GroupBy 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>HideTableHeaders</maml:name> <maml:description> <maml:para>剔除表格的欄標題。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要格式化的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定呈現在畫面上的物件屬性及其呈現的順序。請輸入一個或多個屬性名稱 (用逗號分隔),或是使用雜湊表顯示計算屬性。允許使用萬用字元。 如果省略此參數,呈現在畫面上的屬性將依所顯示的物件而定。參數名稱 ("Property") 為選擇項。同一個命令不能同時使用 Property 和 View 參數。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串> -- Width <int32> -- Alignment (值可以是 "Left"、"Center" 或 "Right")</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ShowError</maml:name> <maml:description> <maml:para>透過管線傳送錯誤。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>View</maml:name> <maml:description> <maml:para>指定替代表格格式或「檢視」的名稱。同一個命令不能同時使用 Property 和 View 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Wrap</maml:name> <maml:description> <maml:para>將超過欄寬的文字顯示於下一行。預設情況下,超過欄寬的文字會被截斷。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Format-Table。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>Microsoft.PowerShell.Commands.Internal.Format</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Format-Table 會傳回代表表格的格式物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以利用內建的別名 "FT" 來參照 Format-Table。如需詳細資訊,請參閱 about_Aliases。 GroupBy 參數會假設物件已經過排序。在使用 Format-Custom 將物件分組之前,請先使用 Sort-Object 將物件排序。 使用 View 參數可為表格指定替代格式。您可以使用 Windows PowerShell 目錄中 *.format.PS1XML 檔案所定義的檢視,也可以在新的 PS1XML 檔案中自行建立檢視,再使用 Update-FormatData Cmdlet 將所建立的檢視包含在 Windows PowerShell 中。 View 參數的替代檢視必須使用表格格式,否則此命令會失敗。如果替代檢視是一份清單,請使用 Format-List。如果替代檢視既不是清單也不是表格,請使用 Format-Custom。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-pssnapin | format-table -auto </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將 Windows PowerShell 嵌入式管理單元的相關資訊格式化在表格中。根據預設,會將它們格式化在清單中。Get-PSSnapin Cmdlet 會取得代表嵌入式管理單元的物件。管線運算子 (|) 會將物件傳遞給 Format-Table 命令,Format-Table 會將表格中的物件格式化。Autosize 參數會調整欄寬以避免截斷的情況。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | sort-object -property basepriority | format-table -groupby basepriority -wrap </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會以相同基本優先順序的分組方式來顯示電腦上的處理序。 Get-Process Cmdlet 會取得代表電腦中每個處理序的物件。管線運算子 (|) 會將物件傳遞給 Sort-Object Cmdlet,讓後者依照物件的基本優先順序來排序物件。 另一個管線運算子則會將結果傳遞給 Format-Table 命令。GroupBy 參數會根據處理序的 BasePriority 屬性值,將其相關資料分別安排到各群組中。Wrap 參數可確保資料不會被截斷。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | sort-object starttime | format-table -view starttime </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令根據處理序的開始日期,將電腦上處理序的相關資訊分別顯示在各群組中。它會使用 Get-Process Cmdlet 來取得代表電腦中處理序的物件。管線運算子 (|) 會將 Get-Process 的輸出傳送到 Sort-Object Cmdlet,此 Cmdlet 再根據 StartTime 屬性加以排序。另一個管線運算子會將排序的結果傳送到 Format-Table。 View 參數用於選取 System.Diagnostics.Process 物件之 DotNetTypes.format.ps1xml 格式化檔案中所定義的 StartTime 檢視,例如由 Get-Process 傳回的物件。這個檢視將處理序的 StartTime 轉換為簡短日期,然後依據開始日期將處理序分組。 DotNetTypes.format.ps1xml 格式化檔案也包含處理序的 Priority 檢視,因此您可以利用自訂檢視來建立自己的 format.ps1xml 檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-service | format-table -property Name, DependentServices </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令以 Name 和 DependentServices 這兩欄,將電腦上的所有服務顯示在表格中。此命令會使用 Get-Service Cmdlet 取得電腦上的所有服務。管線運算子 (|) 會將結果傳送到 Format-Table Cmdlet,該 Cmdlet 會將輸出格式化於表格中。Property 參數指定要在表格中顯示成一欄的屬性。Property 參數的名稱為選擇性,因此可以省略 ("format-table name, dependentservices")。 Property 和 DependentServices 只是服務物件中的兩個屬性。若要檢視所有屬性,請輸入 "get-service | get-member"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process notepad | format-table ProcessName, ` @{Label="TotalRunningTime"; Expression={(get-date) - $_.StartTime}} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示如何在表格中使用計算屬性。命令顯示一個表格,內含本機電腦中所有「記事本」處理序的名稱及總執行時間。總執行時間的計算方式是將目前的時間減去每個處理序的開始時間。 此命令使用 Get-Process Cmdlet 來取得本機電腦中所有名為 "Notepad" 的處理序。管線運算子 (|) 會將結果傳送到 Format-Table,後者再顯示內含兩欄的表格:ProcessName (處理序的標準屬性) 和 TotalRunningTime (計算屬性)。 TotalRunningTime 屬性是由包含 Label 及 Expression 這兩個索引鍵的雜湊表所指定。屬性的名稱會指派給 Label 索引鍵。計算部分則指派給 Expression 索引鍵。此運算式會取得每個處理序物件的 StartTime 屬性,再從 Get-Date 命令的結果中減去這個屬性值 (這個命令會取得目前的日期和時間)。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $processes = get-wmiobject -ComputerName Server01 win32_process -filter "name='notepad.exe'" C:\PS> $processes | format-table ProcessName, @{ Label = "Total Running Time"; ` Expression={(get-date) - $_.ConvertToDateTime($_.CreationDate)}} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令類似於前一個命令,例外之處在於這些命令會使用 Get-WmiObject Cmdlet 和 Win32_Process 類別,在遠端電腦上顯示有關「記事本」處理序的資訊。 這個命令會使用 Get-WmiObject Cmdlet 取得 Windows Management Instrumentation (WMI) Win32_Process 類別的執行個體,此類別描述 Server01 電腦上所有名為 Notepad.exe 的處理序。這個命令會將處理序資訊儲存到 $processes 變數。 第二個命令會使用管線運算子 (|) 將處理序資訊以 $processes 變數傳送到 Format-Table Cmdlet,此 Cmdlet 會一併顯示每個處理序的 ProcessName 以及新的計算屬性。 此命令會將新的計算屬性名稱 Total Running Time 指派給 Label 索引鍵。指派給 Expression 索引鍵的指令碼區塊會將目前的日期減去處理序的建立日期,來計算處理序執行了多久。Get-Date Cmdlet 會取得目前的日期。ConvertToDateTime 方法會將 Win32_Process 物件的 CreationDate 屬性,從 WMI CIM_DATETIME 物件轉換為 Microsoft .NET Framework DateTime 物件,以便能夠與 Get-Date 的輸出進行比較。接著,從目前的日期減去轉換過的建立日期。結果即是 Total Running Time 的值。 倒引號字元 (`) 是一行的接續字元。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113303</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Format-List</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Format-Wide</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Format-Custom</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Format-Wide </command:name> <maml:description> <maml:para>將物件格式化為每個物件僅顯示一個屬性的寬表格。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Format</command:verb> <command:noun>Wide</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Format-Wide Cmdlet 會將物件格式化為寬表格,只顯示每個物件中的一個屬性。您可以使用 Property 參數來決定顯示哪一個屬性。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Format-Wide</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定呈現在畫面上的物件屬性及其呈現的順序。允許使用萬用字元。 如果省略此參數,呈現在畫面上的屬性將依所顯示的物件而定。參數名稱 ("Property") 為選擇項。同一個命令不能同時使用 Property 和 View 參數。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AutoSize</maml:name> <maml:description> <maml:para>根據資料的寬度來調整欄大小和欄數。預設情況下,欄大小和欄數是由檢視決定。同一個命令不能同時使用 AutoSize 和 Column 參數。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Column</maml:name> <maml:description> <maml:para>指定畫面上顯示的欄數。同一個命令不能同時使用 AutoSize 和 Column 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayError</maml:name> <maml:description> <maml:para>在命令列顯示錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Expand</maml:name> <maml:description> <maml:para>將集合物件連同集合中的物件一併格式化。此參數係設計為對支援 ICollection (System.Collections) 介面的物件進行格式化。預設值為 EnumOnly。 有效的值包括: -- EnumOnly:顯示集合中各物件的屬性。 -- CoreOnly:顯示集合物件的屬性。 -- Both:顯示集合物件的屬性,以及集合中各物件的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>覆蓋限制以免命令無法成功執行,但僅限於變更不會危害安全性的部分。例如,Force 將會覆蓋唯讀屬性,或建立目錄以構成完整的檔案路徑,但不會嘗試變更檔案權限。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>GroupBy</maml:name> <maml:description> <maml:para>依據共用屬性或值,將輸出格式化為群組。請輸入運算式或指定輸出的屬性。 GroupBy 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要格式化的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ShowError</maml:name> <maml:description> <maml:para>透過管線傳送錯誤。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>View</maml:name> <maml:description> <maml:para>指定替代表格格式或「檢視」的名稱。同一個命令不能同時使用 Property 和 View 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AutoSize</maml:name> <maml:description> <maml:para>根據資料的寬度來調整欄大小和欄數。預設情況下,欄大小和欄數是由檢視決定。同一個命令不能同時使用 AutoSize 和 Column 參數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Column</maml:name> <maml:description> <maml:para>指定畫面上顯示的欄數。同一個命令不能同時使用 AutoSize 和 Column 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayError</maml:name> <maml:description> <maml:para>在命令列顯示錯誤。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Expand</maml:name> <maml:description> <maml:para>將集合物件連同集合中的物件一併格式化。此參數係設計為對支援 ICollection (System.Collections) 介面的物件進行格式化。預設值為 EnumOnly。 有效的值包括: -- EnumOnly:顯示集合中各物件的屬性。 -- CoreOnly:顯示集合物件的屬性。 -- Both:顯示集合物件的屬性,以及集合中各物件的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>覆蓋限制以免命令無法成功執行,但僅限於變更不會危害安全性的部分。例如,Force 將會覆蓋唯讀屬性,或建立目錄以構成完整的檔案路徑,但不會嘗試變更檔案權限。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>GroupBy</maml:name> <maml:description> <maml:para>依據共用屬性或值,將輸出格式化為群組。請輸入運算式或指定輸出的屬性。 GroupBy 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要格式化的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定呈現在畫面上的物件屬性及其呈現的順序。允許使用萬用字元。 如果省略此參數,呈現在畫面上的屬性將依所顯示的物件而定。參數名稱 ("Property") 為選擇項。同一個命令不能同時使用 Property 和 View 參數。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Expression <字串> 或 <指令碼區塊> -- FormatString <字串></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ShowError</maml:name> <maml:description> <maml:para>透過管線傳送錯誤。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>View</maml:name> <maml:description> <maml:para>指定替代表格格式或「檢視」的名稱。同一個命令不能同時使用 Property 和 View 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Format-Wide。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>Microsoft.PowerShell.Commands.Internal.Format</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Format-Wide 會傳回代表表格的格式物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以利用內建的別名 "fw" 來參照 Format-Wide。如需詳細資訊,請參閱 about_Aliases。 GroupBy 參數會假設物件已經過排序。在使用 Format-Custom 將物件分組之前,請先使用 Sort-Object 將物件排序。 使用 -View 參數可以為表格指定替代格式。您可以使用 Windows PowerShell 目錄中 *.format.PS1XML 檔案所定義的檢視,也可以在新的 PS1XML 檔案中自行建立檢視,再使用 Update-FormatData Cmdlet 將所建立的檢視包含在 Windows PowerShell 中。 View 參數的替代檢視必須使用表格格式,否則此命令會失敗。如果替代檢視是一份清單,請使用 Format-List。如果替代檢視既不是清單也不是表格,請使用 Format-Custom。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | format-wide -column 3 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令在螢幕上的三欄中顯示目前目錄中的檔案名稱。Get-ChildItem Cmdlet 會取得代表目錄中每個檔案的物件。管線運算子 (|) 透過管線將檔案物件傳遞給 Format-Wide,後者再將它們格式化以供輸出。Column 參數可指定欄數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem HKCU:\software\microsoft | format-wide -property pschildname -autosize </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示 HKEY_CURRENT_USER\Software\Microsoft 機碼中的登錄機碼名稱。Get-ChildItem Cmdlet 會取得代表機碼的物件。路徑指定為 "HKCU:" (Windows PowerShell 登錄提供者所公開的其中一個磁碟機),後面接著機碼路徑。管線運算子 (|) 會透過管線將登錄機碼物件傳遞給 Format-Wide,後者再將它們格式化以供輸出。Property 參數會指定屬性的名稱,而 AutoSize 參數則調整欄的大小以提高可讀性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113304</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-Alias </command:name> <maml:description> <maml:para>取得目前工作階段的別名。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>Alias</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-Alias Cmdlet 會取得目前工作階段中的別名 (命令及可執行檔的交替名稱),包括內建的別名、已經設定或匯入的別名,以及已經新增到 Windows PowerShell 設定檔的別名。 根據預設,Get-Alias 會取得別名並傳回命令名稱。當您使用 Definition 參數時,Get-Alias 會取得命令名稱並傳回其別名。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-Alias</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定要擷取的別名。允許使用萬用字元。根據預設,Get-Alias 會擷取所有為目前工作階段定義的別名。參數名稱 ("Name") 為選擇項。您也可經由管道將別名輸出至 Get-Alias。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。此參數的值會限定 Name 和 Definition 參數。請輸入名稱、定義或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>只取得指定之範圍中的別名。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Get-Alias</maml:name> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="named"> <maml:name>Definition</maml:name> <maml:description> <maml:para>取得指定之項目的別名。請輸入 Cmdlet、函數、指令碼、檔案或可執行檔的名稱。 此參數稱為 Definition,因在別名物件的 Definition 屬性中搜尋項目名稱而得名。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。此參數的值會限定 Name 和 Definition 參數。請輸入名稱、定義或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>只取得指定之範圍中的別名。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="named"> <maml:name>Definition</maml:name> <maml:description> <maml:para>取得指定之項目的別名。請輸入 Cmdlet、函數、指令碼、檔案或可執行檔的名稱。 此參數稱為 Definition,因在別名物件的 Definition 屬性中搜尋項目名稱而得名。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。此參數的值會限定 Name 和 Definition 參數。請輸入名稱、定義或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定要擷取的別名。允許使用萬用字元。根據預設,Get-Alias 會擷取所有為目前工作階段定義的別名。參數名稱 ("Name") 為選擇項。您也可經由管道將別名輸出至 Get-Alias。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>只取得指定之範圍中的別名。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將別名輸出至 Get-Alias。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.AliasInfo</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-Alias 會傳回代表每個別名的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 別名是 cmdlet、函數或執行檔的交替名稱或暱稱。若要執行 cmdlet、函數或執行檔,您可以使用其全名或任何別名。如需詳細資訊,請參閱 about_Aliases。 若要建立新的別名,請使用 Set-Alias 或 New-Alias。若要刪除別名,請使用 Remove-Item。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-alias </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得目前工作階段中的所有別名。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-alias -name g*, s* -exclude get-* </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得所有以 "g" 或 "s" 開頭的別名,但以 "get-" 開頭的別名則除外。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-alias -definition Get-ChildItem </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得 Get-ChildItem Cmdlet 的別名。 根據預設,Get-Alias Cmdlet 會在指定別名的情況下取得項目名稱。Definition 參數會在指定項目名稱的情況下取得別名。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-alias | where-object {$_.Options -match "ReadOnly"} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令擷取其 Options 屬性值為 ReadOnly 的所有別名。這個命令提供了快速的方式來尋找 Windows PowerShell 內建的別名,因為這些別名具有 ReadOnly 選項。 Options 只是 Get-Alias 所取得的 AliasInfo 物件的其中一個屬性。若要找出 AliasInfo 物件的所有屬性和方法,請輸入 "get-alias | get-member"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-alias -definition "*-pssession" -exclude e* -scope global </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會取得以 "-pssession" 結尾之命令名稱的別名,但以 "e" 開頭的別名則除外。 這個範例會使用 Scope 參數將命令套用於全域範圍。當您要取得工作階段中的別名時,此參數對指令碼很有幫助。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113306</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Aliases</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Alias Provider</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-Culture </command:name> <maml:description> <maml:para>取得作業系統中的目前文化特性設定。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>Culture</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-Culture Cmdlet 會取得有關目前文化特性設定的資訊,包括系統目前語言設定 (如鍵盤配置) 以及項目顯示格式 (如數字、貨幣和日期) 等相關資訊。 您也可以使用 Get-UICulture Cmdlet,它也會取得系統目前的使用者介面 (UI) 文化特性。使用者介面 (UI) 文化特性決定哪些文字字串會用於使用者介面元素,例如功能表和訊息。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-Culture</maml:name> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Globalization.CultureInfo</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-Culture 會傳回代表目前文化特性的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以使用 $PsCulture 和 $PsUICulture 變數。$PsCulture 變數會儲存目前文化特性的名稱,而 $PsUICulture 變數會儲存目前 UI 文化特性的名稱。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-culture </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示電腦中地區設定的相關資訊。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $c = get-culture C:\PS> $c | format-list -property * Parent : en LCID : 1033 KeyboardLayoutId : 1033 Name : en-US IetfLanguageTag : en-US DisplayName : English (United States) NativeName : English (United States) EnglishName : English (United States) TwoLetterISOLanguageName : en ThreeLetterISOLanguageName : eng ThreeLetterWindowsLanguageName : ENU CompareInfo : CompareInfo - 1033 TextInfo : TextInfo - 1033 IsNeutralCulture : False CultureTypes : SpecificCultures, InstalledWin32Cultures, FrameworkCultures NumberFormat : System.Globalization.NumberFormatInfo DateTimeFormat : System.Globalization.DateTimeFormatInfo Calendar : System.Globalization.GregorianCalendar OptionalCalendars : {System.Globalization.GregorianCalendar, System.Globalization.GregorianCalendar} UseUserOverride : True IsReadOnly : False C:\PS> $c.calendar MinSupportedDateTime : 1/1/0001 12:00:00 AM MaxSupportedDateTime : 12/31/9999 11:59:59 PM AlgorithmType : SolarCalendar CalendarType : Localized Eras : {1} TwoDigitYearMax : 2029 IsReadOnly : False C:\PS> $c.datetimeformat AMDesignator : AM Calendar : System.Globalization.GregorianCalendar DateSeparator : / FirstDayOfWeek : Sunday CalendarWeekRule : FirstDay FullDateTimePattern : dddd, MMMM dd, yyyy h:mm:ss tt LongDatePattern : dddd, MMMM dd, yyyy LongTimePattern : h:mm:ss tt MonthDayPattern : MMMM dd PMDesignator : PM RFC1123Pattern : ddd, dd MMM yyyy HH':'mm':'ss 'GMT' ShortDatePattern : M/d/yyyy ShortTimePattern : h:mm tt SortableDateTimePattern : yyyy'-'MM'-'dd'T'HH':'mm':'ss TimeSeparator : : UniversalSortableDateTimePattern : yyyy'-'MM'-'dd HH':'mm':'ss'Z' YearMonthPattern : MMMM, yyyy AbbreviatedDayNames : {Sun, Mon, Tue, Wed...} ShortestDayNames : {Su, Mo, Tu, We...} DayNames : {Sunday, Monday, Tuesday, Wednesday...} AbbreviatedMonthNames : {Jan, Feb, Mar, Apr...} MonthNames : {January, February, March, April...} IsReadOnly : False NativeCalendarName : Gregorian Calendar AbbreviatedMonthGenitiveNames : {Jan, Feb, Mar, Apr...} MonthGenitiveNames : {January, February, March, April...} C:\PS> $c.datetimeformat.firstdayofweek Sunday </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例呈現大量的文化特性物件資料,並示範如何顯示文化特性物件的屬性及子屬性。 第一個命令會使用 Get-Culture Cmdlet 取得電腦目前的文化特性設定,然後將產生的文化特性物件儲存到 $c 變數。 第二個命令會顯示文化特性物件的所有屬性。它會使用管線運算子 (|) 將 $c 中的文化特性物件傳送給 Format-List Cmdlet,並使用 Property 參數顯示文化特性物件的所有 (*) 屬性 (您可以將此命令縮短為 "$c | fl *")。 其他命令會以點標記法來瀏覽文化特性物件的屬性,以便顯示物件屬性的值。這種標記法可以用來顯示物件的任何屬性值。 第三個命令會以點標記法來顯示文化特性物件的 Calendar 屬性值。 第四個命令會以點標記法來顯示文化特性物件的 DataTimeFormat 屬性值。 許多物件屬性都有屬性。第五個命令會以點標記法來顯示 DateTimeFormat 屬性的 FirstDayOfWeek 屬性值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113312</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-Date </command:name> <maml:description> <maml:para>取得目前日期和時間。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>Date</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-Date Cmdlet 會取得代表目前日期或所指定之日期的 DateTime 物件。此 Cmdlet 能以多種 Windows 和 UNIX 格式來設定日期和時間格式。您可以使用 Get-Date 產生日期或時間字元字串,然後將字串傳送給其他 Cmdlet 或程式。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-Date</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Format</maml:name> <maml:description> <maml:para>顯示格式規範所指示之 Microsoft .NET Framework 格式的日期和時間。請輸入格式規範。如需可用的格式規範清單,請參閱 MSDN (Microsoft Developer Network) Library (http://go.microsoft.com/fwlink/?LinkId=143638) 中的<DateTimeFormatInfo 類別>(英文)。 當您使用 Format 參數時,Windows PowerShell 只會擷取顯示指定之格式日期所需的 DateTime 物件屬性。因此,DateTime 物件的部分屬性和方法可能無法使用。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Date</maml:name> <maml:description> <maml:para>指定日期和時間。根據預設,Get-Date 會取得系統目前的日期和時間。 請以系統地區設定的標準格式來輸入日期,例如 dd-MM-yyyy (德文 [德國]) 或 MM/dd/yyyy (英文 [美國])。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Day</maml:name> <maml:description> <maml:para>指定要顯示的當月日期。請輸入 1 至 31 之間的一個值,顯示這個值可代替當天日期。 如果指定的值大於當月天數,Windows PowerShell 會累加當月天數並顯示結果。例如,"get-date -month 2 -day 31" 會顯示「3 月 3 日」而非「2 月 31 日」。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayHint</maml:name> <maml:description> <maml:para>決定所要顯示的日期和時間元素 有效的值包括: -- Date:僅顯示日期 -- Time:僅顯示時間 -- DateTime:顯示日期和時間 預設為 DateTime。 這個參數不會影響 Get-Date 所擷取的 DateTime 物件。 </maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Date</command:parameterValue> <command:parameterValue required="false" variableLength="false">Time</command:parameterValue> <command:parameterValue required="false" variableLength="false">DateTime</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Hour</maml:name> <maml:description> <maml:para>指定要顯示的小時。請輸入 1 至 23 之間的一個值,顯示這個值可代替目前小時。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Minute</maml:name> <maml:description> <maml:para>指定要顯示的分鐘。請輸入 1 至 59 之間的一個值。顯示這個值可代替目前分鐘。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Month</maml:name> <maml:description> <maml:para>指定要顯示的月份。請輸入 1 至 12 之間的一個值。顯示這個值可代替目前月份。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Second</maml:name> <maml:description> <maml:para>指定要顯示的秒。請輸入 1 至 59 之間的一個值。顯示這個值可代替目前秒數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Year</maml:name> <maml:description> <maml:para>指定要顯示的年份。請輸入 1 至 9999 之間的一個值。顯示這個值可代替目前年份。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Get-Date</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UFormat</maml:name> <maml:description> <maml:para>顯示 UNIX 格式的日期和時間。如需格式規範的清單,請參閱 Notes 區段。 當您使用 UFormat 參數時,Windows PowerShell 只會擷取顯示指定之格式日期所需的 DateTime 物件屬性。因此,DateTime 物件的部分屬性和方法可能無法使用。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Date</maml:name> <maml:description> <maml:para>指定日期和時間。根據預設,Get-Date 會取得系統目前的日期和時間。 請以系統地區設定的標準格式來輸入日期,例如 dd-MM-yyyy (德文 [德國]) 或 MM/dd/yyyy (英文 [美國])。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Day</maml:name> <maml:description> <maml:para>指定要顯示的當月日期。請輸入 1 至 31 之間的一個值,顯示這個值可代替當天日期。 如果指定的值大於當月天數,Windows PowerShell 會累加當月天數並顯示結果。例如,"get-date -month 2 -day 31" 會顯示「3 月 3 日」而非「2 月 31 日」。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayHint</maml:name> <maml:description> <maml:para>決定所要顯示的日期和時間元素 有效的值包括: -- Date:僅顯示日期 -- Time:僅顯示時間 -- DateTime:顯示日期和時間 預設為 DateTime。 這個參數不會影響 Get-Date 所擷取的 DateTime 物件。 </maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Date</command:parameterValue> <command:parameterValue required="false" variableLength="false">Time</command:parameterValue> <command:parameterValue required="false" variableLength="false">DateTime</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Hour</maml:name> <maml:description> <maml:para>指定要顯示的小時。請輸入 1 至 23 之間的一個值,顯示這個值可代替目前小時。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Minute</maml:name> <maml:description> <maml:para>指定要顯示的分鐘。請輸入 1 至 59 之間的一個值。顯示這個值可代替目前分鐘。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Month</maml:name> <maml:description> <maml:para>指定要顯示的月份。請輸入 1 至 12 之間的一個值。顯示這個值可代替目前月份。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Second</maml:name> <maml:description> <maml:para>指定要顯示的秒。請輸入 1 至 59 之間的一個值。顯示這個值可代替目前秒數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Year</maml:name> <maml:description> <maml:para>指定要顯示的年份。請輸入 1 至 9999 之間的一個值。顯示這個值可代替目前年份。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Date</maml:name> <maml:description> <maml:para>指定日期和時間。根據預設,Get-Date 會取得系統目前的日期和時間。 請以系統地區設定的標準格式來輸入日期,例如 dd-MM-yyyy (德文 [德國]) 或 MM/dd/yyyy (英文 [美國])。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue> <dev:type> <maml:name>DateTime</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Day</maml:name> <maml:description> <maml:para>指定要顯示的當月日期。請輸入 1 至 31 之間的一個值,顯示這個值可代替當天日期。 如果指定的值大於當月天數,Windows PowerShell 會累加當月天數並顯示結果。例如,"get-date -month 2 -day 31" 會顯示「3 月 3 日」而非「2 月 31 日」。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayHint</maml:name> <maml:description> <maml:para>決定所要顯示的日期和時間元素 有效的值包括: -- Date:僅顯示日期 -- Time:僅顯示時間 -- DateTime:顯示日期和時間 預設為 DateTime。 這個參數不會影響 Get-Date 所擷取的 DateTime 物件。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DisplayHintType</command:parameterValue> <dev:type> <maml:name>DisplayHintType</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Format</maml:name> <maml:description> <maml:para>顯示格式規範所指示之 Microsoft .NET Framework 格式的日期和時間。請輸入格式規範。如需可用的格式規範清單,請參閱 MSDN (Microsoft Developer Network) Library (http://go.microsoft.com/fwlink/?LinkId=143638) 中的<DateTimeFormatInfo 類別>(英文)。 當您使用 Format 參數時,Windows PowerShell 只會擷取顯示指定之格式日期所需的 DateTime 物件屬性。因此,DateTime 物件的部分屬性和方法可能無法使用。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Hour</maml:name> <maml:description> <maml:para>指定要顯示的小時。請輸入 1 至 23 之間的一個值,顯示這個值可代替目前小時。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Minute</maml:name> <maml:description> <maml:para>指定要顯示的分鐘。請輸入 1 至 59 之間的一個值。顯示這個值可代替目前分鐘。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Month</maml:name> <maml:description> <maml:para>指定要顯示的月份。請輸入 1 至 12 之間的一個值。顯示這個值可代替目前月份。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Second</maml:name> <maml:description> <maml:para>指定要顯示的秒。請輸入 1 至 59 之間的一個值。顯示這個值可代替目前秒數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UFormat</maml:name> <maml:description> <maml:para>顯示 UNIX 格式的日期和時間。如需格式規範的清單,請參閱 Notes 區段。 當您使用 UFormat 參數時,Windows PowerShell 只會擷取顯示指定之格式日期所需的 DateTime 物件屬性。因此,DateTime 物件的部分屬性和方法可能無法使用。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Year</maml:name> <maml:description> <maml:para>指定要顯示的年份。請輸入 1 至 9999 之間的一個值。顯示這個值可代替目前年份。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.DateTime 或 System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 Format 或 UFormat 參數時,輸出物件為 System.String。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 根據預設,會以系統地區設定的完整日期和完整時間格式來顯示日期時間。 當您經由管道將物件輸出至 Add-Content 這類只接受字串輸入的 Cmdlet 時,Windows PowerShell 會將 DateTime 物件轉換成字串後才將它新增到檔案中。預設的 ToString() 格式為簡短日期和完整時間。若要指定其他格式,請使用 Get-Date 的 Format 或 UFormat 參數。 Uformat 值: 下列是 UFormat 參數的值。命令的格式如下: get-date -uformat %<值> 例如, get-date -uformat %d 日期時間: 完整的日期和時間 (預設) (2006 年 6 月 16 日 星期五 上午 10:31:27) c 簡短的日期和時間 (星期五 六月 16 16 10:31:27 2006) 日期: D mm/dd/yy 格式的日期 (06/14/06) x 地區設定中的標準格式日期 (「英文-美國」的 09/12/07) 年: C 世紀 (2006 的 20) Y 4 位數格式的年份 (2006) y 2 位數格式的年份 (06) G 如同 'Y' g 如同 'y' 月: b 縮寫的月份名稱 (Jan) B 完整月份名稱 (January) h 如同 'b' m 月份 (06) 週: W 年中的週 (00-52) V 年中的週 (01-53) U 如同 'W' 日: a 星期幾 - 縮寫名稱 (Mon) A 星期幾 - 完整名稱 (Monday) u 星期幾 - 數字 (星期一 = 1) d 月中的日 - 2 位數 (05) e 月中的日 - 數字前加上空格 ( 5) j 年中的日 - (1-366) w 如同 'u' 時間: p 上午或下午 r 12 小時制時間 (上午 09:15:36) R 24 小時制時間 - 沒有秒 (17:45) T 24 小時制時間 (17:45:52) X 如同 'T' Z 與世界標準時間 (UTC) 的時區時差 (-07) 小時: H 24 小時制的小時 (17) I 12 小時制的小時 (05) k 如同 'H' l 如同 'I' (大寫 I = 小寫 L) 分鐘及秒: M 分鐘數 (35) S 秒數 (05) s 自 1970 年 1 月 1 日 00:00:00 起經過的秒數 (1150451174.95705) 特殊字元: n 新行字元 (\n) t 定位字元 (\t) </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-date -DisplayHint date Tuesday, June 13, 2006 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會擷取 DateTime 物件,但是只顯示日期。它會使用 DisplayHint 參數,表示只要顯示日期。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-date -format g 6/13/2006 12:43 PM </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會擷取目前的日期和時間,並使用簡短日期和簡短時間格式加以格式化。它會使用 .NET Framework "g" 格式規範 (General [簡短日期和簡短時間]) 來指定格式。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-date -uformat "%Y / %m / %d / %A / %Z" 2006 / 06 / 13 / Tuesday / -07 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會擷取目前的日期和時間,並依照命令的指定加以格式化。在此例中,格式包含完整年份 (%Y)、兩位數的數字月份 (%m)、日期 (%d)、完整的星期幾 (%A) 以及與 UTC 的時差 ("Zulu")。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> (get-date -year 2000 -month 12 -day 31).dayofyear 366 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示目前日期為當年的第幾日。例如,12 月 31 日是 2006 年的第 365 日,然而是 2000 年的第 366 日。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-date C:\PS> $a.IsDaylightSavingTime() True </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會告訴您目前的日期和時間是否已調整為目前地區設定中的日光節約時間, 第一個命令會建立 $a 變數,然後將 Get-Date 擷取的物件指派給 $a 變數。接著它會在 $a 中的物件上使用 IsDaylightSavingTime 方法。 若要查看 DateTime 物件的屬性和方法,請輸入: "get-date | get-member".</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-date C:\PS> $a.ToUniversalTime() Tuesday, June 13, 2006 8:09:19 PM </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令將目前的日期和時間轉換為 UTC 時間, 第一個命令會建立 $a 變數,然後將 Get-Date 擷取的物件指派給 $a 變數。接著,它會在 $a 中的物件上使用 ToUniversalTime 方法。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-wmiobject win32_bios -computer server01 $a | format-list -property Name, @{Label="BIOS Age"; ` Expression={(get-date) - $_.ConvertToDateTime($_.ReleaseDate)}} Name : Default System BIOS BIOS Age : 1345.17:31:07.1091047 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>Windows Management Instrumentation (WMI) 使用的日期時間物件與 Get-Date 傳回的 .NET Framework 日期時間物件不同。若要在命令中搭配來自 Get-Date 的日期時間資訊,與 WMI 中的日期時間資訊一起使用,您必須使用 ConvertToDateTime 方法,將 WMI CIM_DATETIME 物件轉換為 .NET Framework DateTime 物件。 此範例中的命令顯示遠端電腦 Server01 上的 BIOS 名稱及使用時間長度。 第一個命令使用 Get-WmiObject Cmdlet,在 Server01 上取得 Win32_BIOS 類別的執行個體,然後將它儲存在 $a 變數中。 第二個命令使用管線運算子 (|),將儲存在 $a 中的 WMI 物件傳送至 Format-List Cmdlet。Format-List 的 Property 參數用於指定兩個要顯示在清單中的屬性:"Name" 和 "BIOS Age"。"BIOS Age" 屬性是在雜湊表中指定的。此表格包含 Label 索引鍵 (指定屬性的名稱) 和 Expression 索引鍵 (內含計算 BIOS 使用時間長度的運算式)。此運算式使用 ConvertToDateTime 方法,將 ReleaseDate 的每個執行個體轉換為 .NET Framework DateTime 物件。接著,從 Get-Date Cmdlet 的傳回值 (不使用參數所取得的目前日期) 中減去這個值。 倒引號字元 (`) 在 Windows PowerShell 中代表一行的接續字元。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 8 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-date Tuesday, June 13, 2006 12:43:42 PM </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得 DateTime 物件,並以系統地區設定的完整日期和完整時間格式來顯示目前的日期時間,如同輸入 "get-date -format F" 一樣。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 9 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-date C:\PS> Tuesday, September 26, 2006 11:25:31 AM c:\PS>(get-date).ToString() 9/26/2006 11:25:31 AM C:\PS>get-date | add-content test.txt # Adds 9/26/2006 11:25:31 AM C:\PS>get-date -format F | add-content test.txt # Adds Tuesday, September 26, 2006 11:25:31 AM </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令示範如何使用 Get-Date 搭配 Add-Content 與其他 Cmdlet,將 Get-Date 所產生的 DateTime 物件轉換成字串。 第一個命令會顯示 "get-date" 命令的預設顯示格式是完整日期和完整時間。 第二個命令顯示 DateTime 物件的 ToString() 方法的預設顯示格式是簡短日期和簡短時間。 第三個命令會使用管線運算子將 DateTime 物件傳送給 Add-Content Cmdlet,讓後者將內容新增到 Test.txt 檔案中。因為 Add-Content 使用 DateTime 物件的 ToString() 方法,因此所新增的日期是簡短日期和簡短時間格式。 第四個命令會使用 Get-Date 的 Format 參數指定格式。當您使用 Format 或 UFormat 參數時,Get-Date 會產生字串而非 DateTime 物件。所以,在將字串傳送給 Add-Content 時,它會直接將字串新增到 Test.txt 檔案而不做變更。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113313</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-Date</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-TimeSpan</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-Event </command:name> <maml:description> <maml:para>取得事件佇列中的事件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>Event</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-Event Cmdlet 會取得目前工作階段的 Windows PowerShell 事件佇列中的事件。您可以取得所有事件或使用 EventIdentifier 或 SourceIdentifier 參數指定事件。 當事件發生時會新增到事件佇列。事件佇列內包含了已註冊的事件、使用 New-Event Cmdlet 所建立的事件,以及 Windows PowerShell 結束時所引發的事件。您可以使用 Get-Event 或 Wait-Event 取得事件。 此 Cmdlet 並不會取得事件檢視器記錄檔中的事件。若要取得那些事件,請使用 Get-WinEvent 或 Get-EventLog。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-Event</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>EventIdentifier</maml:name> <maml:description> <maml:para>只取得有指定之事件識別元的事件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Get-Event</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>只取得有指定的來源識別元的事件。預設為事件佇列中的所有事件。不允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>EventIdentifier</maml:name> <maml:description> <maml:para>只取得有指定之事件識別元的事件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>只取得有指定的來源識別元的事件。預設為事件佇列中的所有事件。不允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>所有事件</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSEventArgs</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-Event 會針對每一個事件各傳回一個 PSEventArgs 物件。若要查看這個物件的描述,請輸入 "get-help get-event -full" 及查看說明主題的 Notes 區段。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 事件、事件訂閱和事件佇列只存在於目前的工作階段中。如果關閉目前的工作階段,則會捨棄事件佇列並取消事件訂閱。 Get-Event Cmdlet 會傳回具有下列屬性的 PSEventArgs 物件 (System.Management.Automation.PSEventArgs)。 -- ComputerName:事件發生所在的電腦名稱。只有當從遠端電腦轉送此事件時,才會填入這個屬性值。 -- RunspaceId:可唯一識別事件發生所在之工作階段的 GUID。只有當從遠端電腦轉送此事件時,才會填入這個屬性值。 -- EventIdentifier:可唯一識別目前工作階段中之事件通知的整數 (Int32)。 -- Sender:產生事件的物件。在 Action 參數的值中,$Sender 自動變數會包含 sender 物件。 -- SourceEventArgs:衍生自 EventArgs 的第一個參數 (如果存在的話)。例如,在計時器的 Elapsed 事件中 (其簽章的形式為 "Object sender, Timers.ElapsedEventArgs e"),SourceEventArgs 屬性將會包含 Timers.ElapsedEventArgs。在 Action 參數的值中,$SourceEventArgs 自動變數會包含這個值。 -- SourceArgs:原始事件簽章的所有參數。如果是標準事件簽章,$args[0] 代表 sender,$args[1] 則代表 SourceEventArgs。在 Action 參數的值中,$SourceArgs 自動變數會包含這個值。 -- SourceIdentifier:可識別事件訂閱的字串。在 Action 參數的值中,$Event 自動變數的 SourceIdentifier 屬性會包含這個值。 -- TimeGenerated:代表事件產生時間的 DateTime 物件。在 Action 參數的值中,$Event 自動變數的 TimeGenerated 屬性會包含這個值。 --MessageData:與事件訂閱有關聯的資料。當使用者註冊事件時,便會指定這個資料。在 Action 參數的值中,$Event 自動變數的 MessageData 屬性會包含這個值。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-event </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得事件佇列中的所有事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-event -sourceIdentifier "PowerShell.ProcessCreated" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得 SourceIdentifier 屬性值為 "PowerShell.ProcessCreated" 的事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $events = get-event C:\PS> $events[0] | format-list -property * ComputerName : RunspaceId : c2153740-256d-46c0-a57c-b805917d1b7b EventIdentifier : 1 Sender : System.Management.ManagementEventWatcher SourceEventArgs : System.Management.EventArrivedEventArgs SourceArgs : {System.Management.ManagementEventWatcher, System.Management.EventArrivedEventArgs} SourceIdentifier : ProcessStarted TimeGenerated : 11/13/2008 12:09:32 PM MessageData : C:\PS> get-event | where {$_.TimeGenerated -ge "11/13/2008 12:15:00 PM"} ComputerName : RunspaceId : c2153740-256d-46c0-a57c-b8059325d1a0 EventIdentifier : 1 Sender : System.Management.ManagementEventWatcher SourceEventArgs : System.Management.EventArrivedEventArgs SourceArgs : {System.Management.ManagementEventWatcher, System.Management.EventArrivedEventArgs} SourceIdentifier : ProcessStarted TimeGenerated : 11/13/2008 12:15:00 PM MessageData : </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用 SourceIdentifier 以外的屬性來取得事件。 第一個命令會取得事件佇列中的所有事件,然後將它們儲存到 $events 變數。 第二個命令會以陣列標記法來取得 $events 變數陣列中的第一個 (以零為起始的索引) 事件。第二命令會使用管線運算子 (|) 將事件傳送給 Format-List 命令,讓後者以清單方式顯示事件的所有屬性。這樣您就可以查看事件物件的屬性。 第三個命令示範如何根據事件的產生時間使用 Where-Object Cmdlet 取得事件 。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-event -eventIdentifier 2 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得事件識別碼為 2 的事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113453</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-ObjectEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-EngineEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-WmiEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Unregister-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Wait-Event</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-EventSubscriber </command:name> <maml:description> <maml:para>取得目前工作階段中的事件訂閱者。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>EventSubscriber</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-EventSubscriber Cmdlet 會取得目前工作階段中的事件訂閱者。 當您使用 Register 事件 Cmdlet 訂閱事件時,事件訂閱者會加入至 Windows PowerShell 工作階段,而您所訂閱的事件會在引發時加入至事件佇列。若要取消事件訂閱,請使用 Unregister-Event Cmdlet 刪除事件訂閱者。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-EventSubscriber</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SubscriptionId</maml:name> <maml:description> <maml:para>只取得指定的訂閱識別碼。根據預設,Get-EventSubscriber 會取得工作階段中的所有事件訂閱者。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Force</maml:name> <maml:description> <maml:para>取得所有事件訂閱者,包括已經使用 Register-ObjectEvent、Register-WmiEvent 和 Register-EngineEvent 的 SupportEvent 參數隱藏的事件訂閱者。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Get-EventSubscriber</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>只取得有指定的 SourceIdentifier 屬性值的事件訂閱者。根據預設,Get-EventSubscriber 會取得工作階段中的所有事件訂閱者。不允許使用萬用字元。此參數有大小寫之分。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Force</maml:name> <maml:description> <maml:para>取得所有事件訂閱者,包括已經使用 Register-ObjectEvent、Register-WmiEvent 和 Register-EngineEvent 的 SupportEvent 參數隱藏的事件訂閱者。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Force</maml:name> <maml:description> <maml:para>取得所有事件訂閱者,包括已經使用 Register-ObjectEvent、Register-WmiEvent 和 Register-EngineEvent 的 SupportEvent 參數隱藏的事件訂閱者。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>只取得有指定的 SourceIdentifier 屬性值的事件訂閱者。根據預設,Get-EventSubscriber 會取得工作階段中的所有事件訂閱者。不允許使用萬用字元。此參數有大小寫之分。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>所有事件訂閱者</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SubscriptionId</maml:name> <maml:description> <maml:para>只取得指定的訂閱識別碼。根據預設,Get-EventSubscriber 會取得工作階段中的所有事件訂閱者。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSEventSubscriber</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-EventSubscriber 會傳回代表每個事件訂閱者的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> New-Event Cmdlet 會建立自訂事件,但卻不會產生訂閱者。因此,Get-EventSubscriber Cmdlet 將不會尋找這些事件的訂閱者物件。不過,如果您使用 Register-EngineEvent Cmdlet 訂閱自訂事件 (以便於轉送事件或指定動作),Get-EventSubscriber 則將會尋找 Register-EngineEvent 所產生的訂閱者。 事件、事件訂閱和事件佇列只存在於目前的工作階段中。如果關閉目前的工作階段,則會捨棄事件佇列並取消事件訂閱。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $timer = New-Object Timers.Timer C:\PS> $timer | Get-Member -Type Event C:\PS> Register-ObjectEvent -inputObject $timer -EventName Elapsed -SourceIdentifier Timer.Elapsed C:\PS> Get-EventSubscriber C:\PS> $timer = New-Object Timers.Timer C:\PS> $timer | Get-Member -Type Event TypeName: System.Timers.Timer Name MemberType Definition ---- ---------- ---------- Disposed Event System.EventHandler Disposed(System.Object, System.EventArgs) Elapsed Event System.Timers.ElapsedEventHandler Elapsed(System.Object, System.Timers.ElapsedEventArgs) C:\PS> Register-ObjectEvent -InputObject $timer -EventName Elapsed -SourceIdentifier Timer.Elapsed C:\PS> Get-EventSubscriber SubscriptionId : 4 SourceObject : System.Timers.Timer EventName : Elapsed SourceIdentifier : Timer.Elapsed Action : HandlerDelegate : SupportEvent : False ForwardEvent : False </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會使用 Get-EventSubscriber 命令取得計時器事件的事件訂閱者。 第一個命令會使用 New-Object Cmdlet 來建立計時器物件的執行個體。此命令會將新的計時器物件儲存在 $timer 變數中。 第二個命令會使用 Get-Member Cmdlet 顯示可供計時器物件使用的事件。此命令會使用具有 Event 值之 Get-Member Cmdlet 的 Type 參數。 第三個命令會使用 Register-ObjectEvent Cmdlet 來註冊計時器物件上的 Elapsed 事件。 第四個命令會使用 Get-EventSubscriber Cmdlet 取得 Elapsed 事件的事件訂閱者。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $timer = New-Object Timers.Timer C:\PS> $timer.Interval = 500 C:\PS> Register-ObjectEvent -inputObject $timer -eventName Elapsed -sourceIdentifier Timer.Random -Action { $random = Get-Random -Min 0 -Max 100 } Id Name State HasMoreData Location Command -- ---- ----- ----------- -------- ------- 3 Timer.Random NotStarted False $random = Get-Random ... C:\PS> $timer.Enabled = $true C:\PS> $subscriber = Get-EventSubcriber -sourceIdentifer Timer.Random C:\PS> ($subscriber.action).gettype().fullname PSEventJob C:\PS> $subscriber.action | format-list -property * State : Running Module : __DynamicModule_6b5cbe82-d634-41d1-ae5e-ad7fe8d57fe0 StatusMessage : HasMoreData : True Location : Command : $random = Get-Random -Min 0 -Max 100 JobStateInfo : Running Finished : System.Threading.ManualResetEvent InstanceId : 88944290-133d-4b44-8752-f901bd8012e2 Id : 1 Name : Timer.Random ChildJobs : {} ... C:\PS> & $subscriber.action.module {$random} 96 C:\PS> & $subscriber.action.module {$random} 23 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會示範如何將 PSEventJob 物件中的動態模組用於事件訂閱者的 Action 屬性中。 第一個命令會使用 New-Object Cmdlet 來建立計時器物件。第二個命令會將計時器的間隔設定為 500 (毫秒)。 第三個命令會使用 Register-ObjectEvent Cmdlet 來註冊計時器物件的 Elapsed 事件。該命令包含處理事件的動作。每當經過計時器間隔時,就會引發事件並且執行動作中的命令。在這個範例中,Get-Random Cmdlet 會產生介於 0 與 100 之間的隨機數字,並將它儲存在 $random 變數中。事件的來源識別元為 Timer.Random。 當您在 Register-ObjectEvent 命令中使用 Action 參數時,該命令就會傳回代表動作的 PSEventJob 物件。 第四個命令會啟用計時器。 第五個命令會使用 Get-EventSubscriber Cmdlet 取得 Timer.Random 事件的事件訂閱者。它會將事件訂閱者物件儲存在 $subscriber 變數中。 第六個命令顯示事件訂閱者物件的 Action 屬性包含 PSEventJob 物件。事實上,它會包含 Register-ObjectEvent 命令所傳回的相同 PSEventJob 物件。 第七個命令會使用 Format-List Cmdlet,在清單中顯示 Action 屬性內 PSEventJob 物件的所有屬性。結果顯示 PSEventJob 物件具有 Module 屬性,其中包含實作動作的動態指令碼模組。 其他命令則使用呼叫運算子 (&) 來呼叫模組中的命令,並且顯示 $random 變數的值。您可以使用呼叫運算子來呼叫模組中的任何命令,包括尚未匯出的命令。在這個範例中,這些命令會顯示發生 Elapsed 事件時所產生的隨機數字。 如需模組的詳細資訊,請參閱 about_Modules。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135155</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-ObjectEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-EngineEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-WmiEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Unregister-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Wait-Event</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-FormatData </command:name> <maml:description> <maml:para>取得目前工作階段中的格式化資料。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>FormatData</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-FormatData Cmdlet 會取得目前工作階段中的格式化資料。 工作階段中的格式化資料包括 Format.ps1xml 格式化檔案中的格式化資料 (例如 $pshome 目錄中的資料)、您匯入工作階段之模組的格式化資料,以及您使用 Import-PSSession Cmdlet 匯入工作階段之命令的格式化資料。 您可以用這個 Cmdlet 來檢查格式化資料。然後,您可以使用 Export-FormatData Cmdlet 來序列化物件 (將其轉換成 XML),並將其儲存在 Format.ps1xml 檔案中。 如需 Windows PowerShell 中格式化檔案的詳細資訊,請參閱 about_Format.ps1xml。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-FormatData</maml:name> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="1"> <maml:name>TypeName</maml:name> <maml:description> <maml:para>只取得具有指定之型別名稱的格式化資料。請輸入型別名稱。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="1"> <maml:name>TypeName</maml:name> <maml:description> <maml:para>只取得具有指定之型別名稱的格式化資料。請輸入型別名稱。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.ExtendedTypeDefinition</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-formatdata </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得工作階段中的所有格式化資料。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-formatdata -typename Microsoft.Wsman* </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得名稱開頭為 "Microsoft.Wsman" 的格式化資料項目。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $f = get-formatdata -typename helpinfoshort C:\PS> $f TypeName FormatViewDefinition -------- -------------------- HelpInfoShort {help , TableControl} C:\PS> $f.FormatViewDefinition[0].control Headers Rows ------- ---- {System.Management.Automation.TableControlColumnHeader, System.Manageme... {System.Management.Automation.TableControlRow} C:\PS> $f.FormatViewDefinition[0].control.headers Label Alignment Width ----- --------- ----- Name Left 33 Category Left 9 Undefined 0 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何取得格式化資料物件及檢查物件的屬性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-formatdata C:\PS> import-module bitstransfer C:\PS> $b = get-formatdata C:\PS> compare-object $a $b InputObject SideIndicator ----------- ------------- Microsoft.BackgroundIntelligentTransfer.Management.BitsJob => C:\PS> get-formatdata *bits* | export-formatdata -filepath c:\test\bits.format.ps1xml C:\PS> get-content c:\test\bits.format.ps1xml <?xml version="1.0" encoding="utf-8"?><Configuration><ViewDefinitions> <View><Name>Microsoft.BackgroundIntelligentTransfer.Management.BitsJob</Name> ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>此範例示範如何使用 Get-FormatData 和 Export-FormatData 來匯出模組所加入的格式化資料。 前四個命令會使用 Get-FormatData、Import-Module 和 Compare-Object Cmdlet 來識別 BitsTransfer 模組加入至工作階段的格式類型。 第五個命令會使用 Get-FormatData Cmdlet 來取得 BitsTransfer 模組加入的格式類型。它會使用管線運算子 (|) 將格式類型物件傳送給 Export-FormatData Cmdlet,此 Cmdlet 會將它轉換回 XML,並將其儲存在指定的 format.ps1xml 檔案中。 最後一個命令會顯示 format.ps1xml 檔案內容的摘要。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=144303</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-FormatData</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Update-FormatData</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-Host </command:name> <maml:description> <maml:para>取得代表目前主控程式的物件。此外,預設也會顯示 Windows PowerShell 版本和地區資訊。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>Host</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-Host Cmdlet 會取得代表主控 Windows PowerShell 之程式的物件。 預設的顯示包含主控程式所使用的 Windows PowerShell 版本號碼及目前的地區和語言設定,但主物件則包含大量的資訊,其中包括目前正在執行的 Windows PowerShell 版本以及 Windows PowerShell 的目前文化特性和 UI 文化特性等詳細資訊。您也可以使用此 Cmdlet 自訂主控程式使用者介面的外觀,例如文字和背景色彩。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-Host</maml:name> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.Internal.Host.InternalHost</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-Host 會傳回 System.Management.Automation.Internal.Host.InternalHost 物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> $host 自動變數包含的物件與 Get-Host 傳回的物件相同,因此您可以用相同方式來處理。同樣地,$PSCulture 和 $PSUICulture 自動變數包含的與主控物件的 CurrentCulture 和 CurrentUICulture 屬性包含的也是同一個物件,因此這些功能可以交換使用。 如需詳細資訊,請參閱 about_Automatic_Variables。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-host Name : ConsoleHost Version : 2.0 InstanceId : e4e0ab54-cc5e-4261-9117-4081f20ce7a2 UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : en-US CurrentUICulture : en-US PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示 Windows PowerShell 主控台 (為本例中 Windows PowerShell 目前的主控程式) 的相關資訊,包括主控程式的名稱、執行在主控程式中的 Windows PowerShell 版本,以及目前的文化特性和 UI 文化特性。 Version、UI、CurrentCulture、CurrentUICulture、PrivateData 和 Runspace 屬性各包含有著非常實用屬性的物件。稍後的範例會檢查這些屬性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $h = get-host C:\PS> $win = $h.ui.rawui.windowsize C:\PS> $win.height = 10 C:\PS> $win.width = 10 C:\PS> $h.ui.rawui.set_windowsize($win) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將 Windows PowerShell 視窗的大小調整為 10 x 10 個像素。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> (get-host).version | format-list -property * Major : 2 Minor : 0 Build : -1 Revision : -1 MajorRevision : -1 MinorRevision : -1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得有關執行在主控程式中的 Windows PowerShell 版本的詳細資訊。您可以檢視這些值,但無法進行變更。 Get-Host 的 Version 屬性包含 System.Version 物件。這個命令會使用管線運算子 (|) 將版本物件傳送給 Format-List Cmdlet。Format-List 命令會使用值為全部 (*) 的 Property 參數來顯示版本物件的所有屬性和屬性值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> (get-host).currentculture | format-list -property * Parent : en LCID : 1033 KeyboardLayoutId : 1033 Name : en-US IetfLanguageTag : en-US DisplayName : English (United States) NativeName : English (United States) EnglishName : English (United States) TwoLetterISOLanguageName : en ThreeLetterISOLanguageName : eng ThreeLetterWindowsLanguageName : ENU CompareInfo : CompareInfo - 1033 TextInfo : TextInfo - 1033 IsNeutralCulture : False CultureTypes : SpecificCultures, InstalledWin32Cultures, FrameworkCultures NumberFormat : System.Globalization.NumberFormatInfo DateTimeFormat : System.Globalization.DateTimeFormatInfo Calendar : System.Globalization.GregorianCalendar OptionalCalendars : {System.Globalization.GregorianCalendar, System.Globalization.GregorianCalendar} UseUserOverride : True IsReadOnly : False </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得有關執行在主控程式中的 Windows PowerShell 目前文化特性設定的詳細資訊。這就是 Get-Culture Cmdlet 傳回的那個資訊。 (同樣地,CurrentUICulture 屬性傳回的與主控物件的 Get-UICulture 傳回的也是同一個物件)。 主控物件的 CurrentCulture 屬性包含 System.Globalization.CultureInfo 物件。這個命令會使用管線運算子 (|) 將 CultureInfo 物件傳送給 Format-List Cmdlet。Format-List 命令會使用值為全部 (*) 的 Property 參數來顯示 CultureInfo 物件的所有屬性和屬性值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> (get-host).currentculture.DateTimeFormat | format-list -property * AMDesignator : AM Calendar : System.Globalization.GregorianCalendar DateSeparator : / FirstDayOfWeek : Sunday CalendarWeekRule : FirstDay FullDateTimePattern : dddd, MMMM dd, yyyy h:mm:ss tt LongDatePattern : dddd, MMMM dd, yyyy LongTimePattern : h:mm:ss tt MonthDayPattern : MMMM dd PMDesignator : PM RFC1123Pattern : ddd, dd MMM yyyy HH':'mm':'ss 'GMT' ShortDatePattern : M/d/yyyy ShortTimePattern : h:mm tt SortableDateTimePattern : yyyy'-'MM'-'dd'T'HH':'mm':'ss TimeSeparator : : UniversalSortableDateTimePattern : yyyy'-'MM'-'dd HH':'mm':'ss'Z' YearMonthPattern : MMMM, yyyy AbbreviatedDayNames : {Sun, Mon, Tue, Wed...} ShortestDayNames : {Su, Mo, Tu, We...} DayNames : {Sunday, Monday, Tuesday, Wednesday...} AbbreviatedMonthNames : {Jan, Feb, Mar, Apr...} MonthNames : {January, February, March, April...} IsReadOnly : False NativeCalendarName : Gregorian Calendar AbbreviatedMonthGenitiveNames : {Jan, Feb, Mar, Apr...} MonthGenitiveNames : {January, February, March, April...} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會傳回 Windows PowerShell 所使用之目前文化特性的 DateTimeFormat 的詳細資訊。 主控物件的 CurrentCulture 屬性包含 CultureInfo 物件,後者則有許多非常實用的屬性。在這兩者之間,DateTimeFormat 屬性包含有著非常實用屬性的 DateTimeFormatInfo 物件。 若要尋找儲存在物件屬性中的物件型別,請使用 Get-Member Cmdlet。若要顯示物件的屬性值,請使用 Format-List Cmdlet。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> (get-host).ui.rawui | format-list -property * ForegroundColor : DarkYellow BackgroundColor : DarkBlue CursorPosition : 0,390 WindowPosition : 0,341 CursorSize : 25 BufferSize : 120,3000 WindowSize : 120,50 MaxWindowSize : 120,81 MaxPhysicalWindowSize : 182,81 KeyAvailable : False WindowTitle : Windows PowerShell 2.0 (04/11/2008 00:08:14) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示主控物件之 RawUI 屬性的屬性。藉由變更這些值,您可以變更主控程式的外觀。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> (get-host).ui.rawui.backgroundcolor = "Black" C:\PS> cls </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將 Windows PowerShell 主控台的背景色彩變更為紅色。"cls" 命令是 Clear-Host 函數的別名,這個命令會將畫面清除,並將整個畫面變更為新的色彩。 這項變更只對目前的工作階段有效。若要為所有工作階段變更主控台的背景色彩,請將該命令加入至 Windows PowerShell 設定檔。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 8 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $host.privatedata.errorbackgroundcolor = "white" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將錯誤訊息的背景色彩變更為白色。 這個命令會使用 $host 自動變數,它包含目前主控程式的主控物件,而 Get-Host 傳回的與 $host 包含的是同一個物件,因此您可以交替使用它們。 這個命令會以 $host 的 PrivateData 屬性當做其 ErrorBackgroundColor 屬性。若要查看 $host.privatedata 屬性中物件的所有屬性,請輸入 "$host.privatedata | format-list * "。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113318</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Read-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Host</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-Member </command:name> <maml:description> <maml:para>取得物件的屬性和方法。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>Member</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-Member Cmdlet 會取得物件的「成員」(屬性和方法)。 若要指定物件,請使用 InputObject 參數,或經由管道將物件輸出至 Get-Member。若要擷取靜態成員 (類別的成員,而非執行個體的成員) 的相關資訊,請使用 Static 參數。若只要取得特定型別的成員,例如 NoteProperties,請使用 MemberType 參數。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-Member</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>為物件的一個或多個屬性或方法指定名稱。Get-Member 只會取得指定的屬性和方法。 如果使用 Name 參數搭配 MemberType、View 或 Static 參數,Get-Member 只會取得符合所有參數條件的成員。 若要依名稱取得靜態成員,請使用 Static 參數搭配 Name 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>將內建成員 (PSBase、PSAdapted、PSObject、PSTypeNames) 和編譯器產生的 get_ 與 set_ 方法新增到顯示端。根據預設,Get-Member 會取得所有檢視中的這些屬性 ("Base" 和 "Adapted" 除外),但不加以顯示。 下列清單說明使用 Force 參數時所新增的屬性。 -- PSBase:.NET Framework 物件的最原始且不經過擴充或改寫的屬性。這些屬性是針對物件類別定義的,您可以在 MSDN 中找到它們。 -- PSAdapted:定義在 Windows PowerShell 擴充型別系統中的屬性和方法。 -- PSExtended:Types.ps1xml 檔案中或以 Add-Member Cmdlet 所加入的屬性和方法。 -- PSObject:用來將基底物件轉換成 Windows PowerShell PSObject 物件的介面卡。 -- PSTypeNames:按照特性描述物件的物件型別清單。在格式化物件時,Windows PowerShell 會在 Windows PowerShell 安裝目錄 ($pshome) 的 Format.ps1xml 檔案中搜尋型別,並使用它所找到的第一個型別的格式定義。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要擷取其成員的物件。 使用 InputObject 參數與經由管道將物件輸出至 Get-Member,這兩種方式並不相同。其差異如下: -- 當您經由管道將物件的集合輸出至 Get-Member 時,Get-Member 會取得集合中個別物件的成員,例如整數陣列中整數的屬性。 -- 當您使用 InputObject 參數送出物件的集合時,Get-Member 會取得集合的成員,例如整數陣列中陣列的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>MemberType</maml:name> <maml:description> <maml:para>只取得有指定的成員型別的成員。預設為 All。 此參數的有效值為: -- AliasProperty:為現有屬性定義新名稱的屬性。 -- CodeMethod:參考 .NET Framework 類別之靜態方法的某個方法。 -- CodeProperty:參考 .NET Framework 類別之靜態屬性的某個屬性。 -- Event:表示物件傳送訊息來表示動作或變更所處的狀態。 -- MemberSet:屬性及方法的預先定義的集合,例如 PSBase、PSObject 和 PSTypeNames。 -- Method:基礎 .NET Framework 物件的方法。 -- NoteProperty:有靜態值的屬性。 -- ParameterizedProperty:接受參數和參數值的屬性。 -- Property:基礎 .NET Framework 物件的屬性。 -- PropertySet:物件屬性的預先定義的集合。 -- ScriptMethod:值為指令碼輸出的方法。 -- ScriptProperty:值為指令碼輸出的屬性。 -- All:取得所有成員型別。 -- Methods:取得物件方法的所有型別 (例如 Method、CodeMethod、ScriptMethod)。 -- Properties:取得物件屬性的所有型別 (例如 Property、CodeProperty、AliasProperty、ScriptProperty)。 並不是所有物件都有全部的成員型別。如果指定物件所沒有的成員型別,Windows PowerShell 就會傳回 null 值。 若要取得成員的相關型別,例如所有的擴充成員,請使用 View 參數。如果使用 MemberType 參數搭配 Static 或 View 參數,Get-Member 會取得屬於這兩個集合的成員。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">AliasProperty</command:parameterValue> <command:parameterValue required="false" variableLength="false">CodeProperty</command:parameterValue> <command:parameterValue required="false" variableLength="false">Property</command:parameterValue> <command:parameterValue required="false" variableLength="false">NoteProperty</command:parameterValue> <command:parameterValue required="false" variableLength="false">ScriptProperty</command:parameterValue> <command:parameterValue required="false" variableLength="false">Properties</command:parameterValue> <command:parameterValue required="false" variableLength="false">PropertySet</command:parameterValue> <command:parameterValue required="false" variableLength="false">Method</command:parameterValue> <command:parameterValue required="false" variableLength="false">CodeMethod</command:parameterValue> <command:parameterValue required="false" variableLength="false">ScriptMethod</command:parameterValue> <command:parameterValue required="false" variableLength="false">Methods</command:parameterValue> <command:parameterValue required="false" variableLength="false">ParameterizedProperty</command:parameterValue> <command:parameterValue required="false" variableLength="false">MemberSet</command:parameterValue> <command:parameterValue required="false" variableLength="false">Event</command:parameterValue> <command:parameterValue required="false" variableLength="false">All</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Static</maml:name> <maml:description> <maml:para>只取得物件的靜態屬性和方法。 靜態屬性和方法定義於物件的類別,而非於類別的特定執行個體。 如果使用 Static 參數搭配 View 參數,則會忽略 View 參數。如果使用 Static 參數搭配 MemberType 參數,Get-Member 只會取得屬於這兩個集合的成員。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>View</maml:name> <maml:description> <maml:para>只取得特定型別的成員 (屬性和方法)。請指定一個或多個值。預設為 "Adapted, Extended"。 有效的值包括: -- Base:只取得 .NET Framework 物件最原始 (不經過擴充或改寫) 的屬性和方法。 -- Adapted:只取得定義在 Windows PowerShell 擴充型別系統中的屬性和方法。 -- Extended:只取得 Types.ps1xml 檔案中或以 Add-Member Cmdlet 所加入的屬性和方法。 -- All:取得 Base、Adapted 和 Extended 檢視中的成員。 View 參數會決定擷取的成員,而不只是顯示這些成員而已。 若要取得特定的成員型別,例如指令碼屬性,請使用 MemberType 參數。如果在同一個命令中同時使用 MemberType 和 View 參數,Get-Member 會取得屬於這兩個集合的成員。如果在同一個命令中同時使用 Static 和 View 參數,則會忽略 View 參數。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Extended</command:parameterValue> <command:parameterValue required="false" variableLength="false">Adapted</command:parameterValue> <command:parameterValue required="false" variableLength="false">Base</command:parameterValue> <command:parameterValue required="false" variableLength="false">All</command:parameterValue> </command:parameterValueGroup> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>將內建成員 (PSBase、PSAdapted、PSObject、PSTypeNames) 和編譯器產生的 get_ 與 set_ 方法新增到顯示端。根據預設,Get-Member 會取得所有檢視中的這些屬性 ("Base" 和 "Adapted" 除外),但不加以顯示。 下列清單說明使用 Force 參數時所新增的屬性。 -- PSBase:.NET Framework 物件的最原始且不經過擴充或改寫的屬性。這些屬性是針對物件類別定義的,您可以在 MSDN 中找到它們。 -- PSAdapted:定義在 Windows PowerShell 擴充型別系統中的屬性和方法。 -- PSExtended:Types.ps1xml 檔案中或以 Add-Member Cmdlet 所加入的屬性和方法。 -- PSObject:用來將基底物件轉換成 Windows PowerShell PSObject 物件的介面卡。 -- PSTypeNames:按照特性描述物件的物件型別清單。在格式化物件時,Windows PowerShell 會在 Windows PowerShell 安裝目錄 ($pshome) 的 Format.ps1xml 檔案中搜尋型別,並使用它所找到的第一個型別的格式定義。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要擷取其成員的物件。 使用 InputObject 參數與經由管道將物件輸出至 Get-Member,這兩種方式並不相同。其差異如下: -- 當您經由管道將物件的集合輸出至 Get-Member 時,Get-Member 會取得集合中個別物件的成員,例如整數陣列中整數的屬性。 -- 當您使用 InputObject 參數送出物件的集合時,Get-Member 會取得集合的成員,例如整數陣列中陣列的屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>MemberType</maml:name> <maml:description> <maml:para>只取得有指定的成員型別的成員。預設為 All。 此參數的有效值為: -- AliasProperty:為現有屬性定義新名稱的屬性。 -- CodeMethod:參考 .NET Framework 類別之靜態方法的某個方法。 -- CodeProperty:參考 .NET Framework 類別之靜態屬性的某個屬性。 -- Event:表示物件傳送訊息來表示動作或變更所處的狀態。 -- MemberSet:屬性及方法的預先定義的集合,例如 PSBase、PSObject 和 PSTypeNames。 -- Method:基礎 .NET Framework 物件的方法。 -- NoteProperty:有靜態值的屬性。 -- ParameterizedProperty:接受參數和參數值的屬性。 -- Property:基礎 .NET Framework 物件的屬性。 -- PropertySet:物件屬性的預先定義的集合。 -- ScriptMethod:值為指令碼輸出的方法。 -- ScriptProperty:值為指令碼輸出的屬性。 -- All:取得所有成員型別。 -- Methods:取得物件方法的所有型別 (例如 Method、CodeMethod、ScriptMethod)。 -- Properties:取得物件屬性的所有型別 (例如 Property、CodeProperty、AliasProperty、ScriptProperty)。 並不是所有物件都有全部的成員型別。如果指定物件所沒有的成員型別,Windows PowerShell 就會傳回 null 值。 若要取得成員的相關型別,例如所有的擴充成員,請使用 View 參數。如果使用 MemberType 參數搭配 Static 或 View 參數,Get-Member 會取得屬於這兩個集合的成員。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSMemberTypes</command:parameterValue> <dev:type> <maml:name>PSMemberTypes</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>為物件的一個或多個屬性或方法指定名稱。Get-Member 只會取得指定的屬性和方法。 如果使用 Name 參數搭配 MemberType、View 或 Static 參數,Get-Member 只會取得符合所有參數條件的成員。 若要依名稱取得靜態成員,請使用 Static 參數搭配 Name 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Static</maml:name> <maml:description> <maml:para>只取得物件的靜態屬性和方法。 靜態屬性和方法定義於物件的類別,而非於類別的特定執行個體。 如果使用 Static 參數搭配 View 參數,則會忽略 View 參數。如果使用 Static 參數搭配 MemberType 參數,Get-Member 只會取得屬於這兩個集合的成員。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>View</maml:name> <maml:description> <maml:para>只取得特定型別的成員 (屬性和方法)。請指定一個或多個值。預設為 "Adapted, Extended"。 有效的值包括: -- Base:只取得 .NET Framework 物件最原始 (不經過擴充或改寫) 的屬性和方法。 -- Adapted:只取得定義在 Windows PowerShell 擴充型別系統中的屬性和方法。 -- Extended:只取得 Types.ps1xml 檔案中或以 Add-Member Cmdlet 所加入的屬性和方法。 -- All:取得 Base、Adapted 和 Extended 檢視中的成員。 View 參數會決定擷取的成員,而不只是顯示這些成員而已。 若要取得特定的成員型別,例如指令碼屬性,請使用 MemberType 參數。如果在同一個命令中同時使用 MemberType 和 View 參數,Get-Member 會取得屬於這兩個集合的成員。如果在同一個命令中同時使用 Static 和 View 參數,則會忽略 View 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSMemberViewTypes</command:parameterValue> <dev:type> <maml:name>PSMemberViewTypes</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Get-Member </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>Microsoft.PowerShell.Commands.MemberDefinition</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-Member 會針對它所取得的每一個屬性或方法各傳回一個物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您可以使用 InputObject 參數,或經由管道將物件 (前面加上逗號) 輸出至 Get-Member,藉以擷取集合物件的相關資訊。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-service | get-member TypeName: System.ServiceProcess.ServiceController Name MemberType Definition ---- ---------- ---------- Name AliasProperty Name = ServiceName Close Method System.Void Close() Continue Method System.Void Continue() CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(Type requestedType) Dispose Method System.Void Dispose() Equals Method System.Boolean Equals(Object obj) ExecuteCommand Method System.Void ExecuteCommand(Int32 command) GetHashCode Method System.Int32 GetHashCode() GetLifetimeService Method System.Object GetLifetimeService() GetType Method System.Type GetType() InitializeLifetimeService Method System.Object InitializeLifetimeService() Pause Method System.Void Pause() Refresh Method System.Void Refresh() Start Method System.Void Start(), System.Void Start(String[] args) Stop Method System.Void Stop() ToString Method System.String ToString() WaitForStatus Method System.Void WaitForStatus(ServiceControllerStatus desiredStatus), System.Voi... CanPauseAndContinue Property System.Boolean CanPauseAndContinue {get;} CanShutdown Property System.Boolean CanShutdown {get;} CanStop Property System.Boolean CanStop {get;} Container Property System.ComponentModel.IContainer Container {get;} DependentServices Property System.ServiceProcess.ServiceController[] DependentServices {get;} DisplayName Property System.String DisplayName {get;set;} MachineName Property System.String MachineName {get;set;} ServiceHandle Property System.Runtime.InteropServices.SafeHandle ServiceHandle {get;} ServiceName Property System.String ServiceName {get;set;} ServicesDependedOn Property System.ServiceProcess.ServiceController[] ServicesDependedOn {get;} ServiceType Property System.ServiceProcess.ServiceType ServiceType {get;} Site Property System.ComponentModel.ISite Site {get;set;} Status Property System.ServiceProcess.ServiceControllerStatus Status {get;} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示由 Get-Service Cmdlet 所產生之處理序物件 (System.ServiceProcess.ServiceController) 的屬性和方法。 它會使用管線運算子 (|) 將 Get-Service 命令的輸出傳送給 Get-Member。 因為整個命令的 Get-Member 部分沒有任何參數,所以 Get-Member 會使用所有預設值。Get-Member 本身會取得所有成員型別,但不會取得靜態成員,也不會顯示內建成員。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-service | get-member -force C:\PS> (get-service -schedule).psbase </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會取得由 Get-Service Cmdlet 所擷取之服務物件 (System.ServiceProcess.ServiceController) 的所有成員 (屬性和方法),包括像是 PSBase 和 PSObject 等內建成員以及 get_ 和 set_ 方法。 第一個命令會使用 Get-Service Cmdlet 取得代表系統服務的物件,並使用管線運算子 (|) 將服務物件傳遞給 Get-Member Cmdlet。 Get-Member 命令會使用 Force 參數將內建的物件成員和編譯器產生的物件成員新增到顯示端。Get-Member 會取得這些成員,但預設會加以隱藏。 您可以像使用物件的適當方法一樣使用這些屬性和方法。第二個命令示範如何顯示排程服務的 PSBase 屬性值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-service | get-member -view extended TypeName: System.ServiceProcess.ServiceController Name MemberType Definition ---- ---------- ---------- Name AliasProperty Name = ServiceName </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得使用 Types.ps1xml 檔案或 Add-Member Cmdlet 所擴充之服務物件的方法和屬性。 Get-Member 命令會使用 View 參數,以便只取得服務物件的擴充成員。在此例中,擴充成員是 Name 屬性,它是 ServiceName 屬性的別名屬性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-eventlog -log system | gm -membertype scriptproperty TypeName: System.Diagnostics.EventLogEntry Name MemberType Definition ---- ---------- ---------- EventID ScriptProperty System.Object EventID {get=$this.get_EventID() -band 0xFFFF;} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得事件檢視器的系統記錄檔中事件記錄檔物件的指令碼屬性。在此例中,唯一的指令碼屬性是 EventID。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-eventlog -log system | get-member -membertype scriptproperty TypeName: System.Diagnostics.EventLogEntry Name MemberType Definition ---- ---------- ---------- EventID ScriptProperty System.Object EventID {get=$this.get_EventID() -band 0xFFFF;} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得事件檢視器的系統記錄檔中事件記錄檔物件的指令碼屬性。 它會使用 MemberType 參數,只取得 MemberType 屬性值為 ScriptProperty 的物件。 此命令會傳回 EventLog 物件的 EventID 屬性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = "get-process", "get-service", "get-culture", "get-psdrive", "get-executionpolicy" C:\PS> foreach ($cmdlet in $a) {invoke-expression $cmdlet | get-member -name machinename} TypeName: System.Diagnostics.Process Name MemberType Definition ---- ---------- ---------- MachineName Property System.String MachineName {get;} TypeName: System.ServiceProcess.ServiceController Name MemberType Definition ---- ---------- ---------- MachineName Property System.String MachineName {get;set;} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從 Cmdlet 清單取得有 MachineName 屬性的物件。 第一個命令會將數個 Cmdlet 的名稱儲存到 $a 變數。 第二個命令會使用 ForEach 陳述式,叫用每個命令、將結果傳送給 Get-Member,以及將來自 Get-Member 的結果限制成名稱為 "MachineName" 的成員。 結果會顯示只有處理序物件 (System.Diagnostics.Process) 和服務物件 (System.ServiceProcess.ServiceController) 有 MachineName 屬性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-member -inputobject @(1) C:\PS>$a.count 1 C:\PS> $a = get-member -inputobject 1,2,3 TypeName: System.Object[] Name MemberType Definition ---- ---------- ---------- Count AliasProperty Count = Length Address Method System.Object& Address(Int32 ) Clone Method System.Object Clone() ... C:\PS>$a.count 1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何在只有一個指定的型別物件的情況下,找出物件陣列的屬性和方法。 因為整個命令的目標是要找出陣列的屬性,所以第一個命令會使用 InputObject 參數,並以 "at" 符號 (@) 來表示陣列。在此例中,陣列只有一個物件,即整數 1。 第三個命令會使用 Get-Member Cmdlet 取得整數陣列的屬性和方法,而這個命令會將它們儲存到 $a 變數中。 第四個命令會使用陣列的 Count 屬性,以找出 $a 變數中的物件數目。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113322</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Add-Member</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Help</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Command</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSDrive</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-PSBreakpoint </command:name> <maml:description> <maml:para>取得目前工作階段中所設定的中斷點。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>PSBreakpoint</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-PSBreakPoint Cmdlet 會取得目前工作階段中所設定的中斷點。您可以使用 Cmdlet 參數取得特定的中斷點。 中斷點是命令或指令碼中的一個位置,只要指令碼執行到此處就會暫停執行,讓您可以檢查指令碼中的指令。Get-PSBreakpoint 是其中幾個專為偵錯 Windows PowerShell 指令碼或命令所設計的 Cmdlet。如需 Windows PowerShell 偵錯工具的詳細資訊,請參閱 about_Debuggers。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-PSBreakpoint</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Script</maml:name> <maml:description> <maml:para>只取得指定的指令碼中的中斷點。請輸入一個或多個指令碼檔的路徑 (選擇性) 和名稱。預設位置為目前目錄。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Get-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Command</maml:name> <maml:description> <maml:para>取得指定的命令名稱上所設定的命令中斷點。請輸入命令名稱,例如 Cmdlet 或函數的名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Script</maml:name> <maml:description> <maml:para>只取得指定的指令碼中的中斷點。請輸入一個或多個指令碼檔的路徑 (選擇性) 和名稱。預設位置為目前目錄。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Get-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Id</maml:name> <maml:description> <maml:para>取得有指定的中斷點識別碼的中斷點。請以逗號分隔的清單輸入識別碼。您也可經由管道將中斷點識別碼輸出至 Get-PSBreakpoint。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Get-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Type</maml:name> <maml:description> <maml:para>只取得指定的型別的中斷點。請輸入一個或多個型別。有效的值為 Line、Command 和 Variable。您也可經由管道將中斷點型別輸出至 Get-PSBreakpoint。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">BreakpointType[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Script</maml:name> <maml:description> <maml:para>只取得指定的指令碼中的中斷點。請輸入一個或多個指令碼檔的路徑 (選擇性) 和名稱。預設位置為目前目錄。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Get-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Variable</maml:name> <maml:description> <maml:para>取得指定的變數名稱上所設定的變數中斷點。請輸入變數名稱,但不要加上貨幣符號。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Script</maml:name> <maml:description> <maml:para>只取得指定的指令碼中的中斷點。請輸入一個或多個指令碼檔的路徑 (選擇性) 和名稱。預設位置為目前目錄。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Command</maml:name> <maml:description> <maml:para>取得指定的命令名稱上所設定的命令中斷點。請輸入命令名稱,例如 Cmdlet 或函數的名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>所有中斷點</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Id</maml:name> <maml:description> <maml:para>取得有指定的中斷點識別碼的中斷點。請以逗號分隔的清單輸入識別碼。您也可經由管道將中斷點識別碼輸出至 Get-PSBreakpoint。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> <dev:type> <maml:name>Int32[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>所有中斷點</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Script</maml:name> <maml:description> <maml:para>只取得指定的指令碼中的中斷點。請輸入一個或多個指令碼檔的路徑 (選擇性) 和名稱。預設位置為目前目錄。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>所有中斷點</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Type</maml:name> <maml:description> <maml:para>只取得指定的型別的中斷點。請輸入一個或多個型別。有效的值為 Line、Command 和 Variable。您也可經由管道將中斷點型別輸出至 Get-PSBreakpoint。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">BreakpointType[]</command:parameterValue> <dev:type> <maml:name>BreakpointType[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>所有中斷點</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Variable</maml:name> <maml:description> <maml:para>取得指定的變數名稱上所設定的變數中斷點。請輸入變數名稱,但不要加上貨幣符號。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>所有中斷點</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Int32、Microsoft.PowerShell.Commands.BreakpointType</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將中斷點識別碼和中斷點型別輸出至 Get-PSBreakpoint。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>中斷點物件 (System.Management.Automation.LineBreakpoint、System.Management.Automation.VariableBreakpoint、System.Management.Automation.CommandBreakpoint)</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-PSBreakPoint 會傳回代表工作階段內中斷點的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您可以使用 Get-PSBreakpoint 或其別名 "gbp"。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-psbreakpoint </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得目前工作階段中所有指令碼和函數上所設定的所有中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-psbreakpoint -Id 2 Function : Increment Action : Enabled : True HitCount : 0 Id : 2 Script : C:\ps-test\sample.ps1 ScriptName : C:\ps-test\sample.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得中斷點識別碼為 2 的中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $b = set-psbreakpoint -script sample.ps1 -function increment C:\PS> $b.Id | get-psbreakpoint </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令示範如何經由管道將中斷點識別碼輸出至 Get-PSBreakpoint 來取得中斷點。 第一個命令會使用 Set-PSBreakpoint Cmdlet 在 Sample.ps1 指令碼的 Increment 函數上建立中斷點,然後將中斷點物件儲存到 $b 變數。 第二個命令會以點運算子 (.) 來取得 $b 變數中的中斷點物件的 Id 屬性,並使用管線運算子 (|) 將識別碼傳送給 Get-PSBreakpoint Cmdlet。 因此,Get-PSBreakpoint 便會取得有指定的識別碼的中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-psbreakpoint -script Sample.ps1, SupportScript.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得 Sample.ps1 和 SupportScript.ps1 檔案中的所有中斷點。 這個命令不會取得工作階段中其他指令碼或函數上可能設定的其他中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-psbreakpoint -command Read-Host, Write-Host -script Sample.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得 Sample.ps1 檔案中 Read-Host 或 Write-Host 命令上所設定的所有命令中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-psbreakpoint -type Command -script Sample.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得 Sample.ps1 檔案中的所有命令中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-psbreakpoint -variable Index, Swap </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得目前工作階段中 $index 和 $swap 變數上所設定的中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 8 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-psbreakpoint -type line, variable -script Sample.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得 Sample.ps1 指令碼中的所有行中斷點和變數中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113325</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Debuggers</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Disable-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Enable-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSCallStack</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-PSCallStack </command:name> <maml:description> <maml:para>顯示目前的呼叫堆疊。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>PSCallStack</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-PSCallStack Cmdlet 會顯示目前的呼叫堆疊。 儘管此 Cmdlet 是設計用於 Windows PowerShell 偵錯工具,您還是可以用它來在偵錯工具以外顯示指令碼或函數中的呼叫堆疊。 若要在偵錯工具中執行 Get-PSCallStack 命令,請輸入 "k" 或 "get-pscallstack"。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-PSCallStack</maml:name> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將物件輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.CallStackFrame</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-PSCallStack 會傳回代表呼叫堆疊內之項目的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> function my-alias { $p = $args[0] get-alias | where {$_.definition -like "*$p"} | ft definition, name -auto } PS C:\ps-test> set-psbreakpoint -command my-alias Command : my-alias Action : Enabled : True HitCount : 0 Id : 0 Script : prompt PS C:\ps-test> my-alias get-content Entering debug mode. Use h or ? for help. Hit Command breakpoint on 'prompt:my-alias' my-alias get-content [DBG]: PS C:\ps-test> s $p = $args[0] DEBUG: Stepped to ': $p = $args[0] ' [DBG]: PS C:\ps-test> s get-alias | Where {$_.Definition -like "*$p*"} | ft Definition, [DBG]: PS C:\ps-test>get-pscallstack Name CommandLineParameters UnboundArguments Location ---- --------------------- ---------------- -------- prompt {} {} prompt my-alias {} {get-content} prompt prompt {} {} prompt [DBG]: PS C:\ps-test> o Definition Name ---------- ---- Get-Content gc Get-Content cat Get-Content type </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 Get-PSCallStack Cmdlet 顯示 My-Alias 函數的呼叫堆疊,而這個簡單函數可以取得 Cmdlet 名稱的別名。 第一個命令是在 Windows PowerShell 命令提示字元下輸入該函數。第二個命令會使用 Set-PSBreakpoint Cmdlet 在 My-Alias 函數上設定中斷點。第三個命令會使用 My-Alias 函數,以便為 Get-Content Cmdlet 取得目前工作階段中的所有別名。 在呼叫該函數時,偵錯工具會進入命令列。兩個連續的逐步執行命令會開始逐行執行該函數。然後,Get-PSCallStack 會被用來擷取呼叫堆疊。 最後一個命令是 Step-Out 命令 (o),它會結束偵錯工具並繼續執行完指令碼。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113326</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Debuggers</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Enable-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Disable-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-Random </command:name> <maml:description> <maml:para>取得隨機數字,或從集合中隨機選取物件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>Random</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-Random Cmdlet 會取得隨機選取的數字。如果將物件的集合送出給 Get-Random,它就會從集合取得一個或多個隨機選取的物件。 若沒有使用參數或輸入,"Get-Random" 命令就會傳回一個介於 0 (零) 到 Int32.MaxValue (即 0x7FFFFFFF,也就是 2,147,483,647) 之間的隨機選取的 32 位元、不帶正負號的整數。 您可以使用 Get-Random 參數指定種子號碼、最小和最大值,以及從送出的集合傳回的物件數目。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-Random</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定物件的集合。Get-Random 會從集合以隨機順序取得隨機選取的物件。請輸入物件、含有物件的變數或是可取得物件的命令或運算式。您也可經由管道將物件的集合輸出至 Get-Random。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Count</maml:name> <maml:description> <maml:para>決定傳回的物件數目。預設為 1。如果 Count 的值超過集合中的物件數目,Get-Random 會以隨機順序傳回所有物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SetSeed</maml:name> <maml:description> <maml:para>指定亂數產生器的種子值。這個種子值將一直用於目前的命令和目前工作階段中的所有後續 Get-Random 命令,直到您再次使用 SetSeed 或關閉工作階段為止。您無法將種子重設回預設值,這個值會因時而異。 SetSeed 參數不是必要的。根據預設,Get-Random 會以系統時鐘來產生種子值。通常只有在嘗試重新產生行為 (例如對包含 Get-Random 命令的指令碼進行偵錯或分析) 的情況下才使用 SetSeed,因為它會造成非隨機的行為。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Get-Random</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Maximum</maml:name> <maml:description> <maml:para>指定亂數的最大值。Get-Random 會傳回小於 (不等於) 最大值的值。請輸入 32 位元整數或雙精度浮點數,或是輸入可轉換成整數或雙精度浮點數的物件,例如數值字串 ("100")。Maximum 的值必須大於 (不等於) Minimum 的值。 如果 Maximum 或 Minimum 的值為浮點數,Get-Random 會傳回隨機選取的浮點數。 如果 Minimum 的值為雙精度浮點數 (Double),Maximum 的預設值則為 Double.MaxValue,否則預設值為 Int32.MaxValue (2,147,483,647 或 0x7FFFFFFF)。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Minimum</maml:name> <maml:description> <maml:para>指定亂數的最小值。請輸入 32 位元整數或雙精度浮點數,或是輸入可轉換成整數或雙精度浮點數的物件,例如數值字串 ("100")。預設值為 0 (零)。 Minimum 的值必須小於 (不等於) Maximum 的值。如果 Maximum 或 Minimum 的值為浮點數,Get-Random 會傳回隨機選取的浮點數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SetSeed</maml:name> <maml:description> <maml:para>指定亂數產生器的種子值。這個種子值將一直用於目前的命令和目前工作階段中的所有後續 Get-Random 命令,直到您再次使用 SetSeed 或關閉工作階段為止。您無法將種子重設回預設值,這個值會因時而異。 SetSeed 參數不是必要的。根據預設,Get-Random 會以系統時鐘來產生種子值。通常只有在嘗試重新產生行為 (例如對包含 Get-Random 命令的指令碼進行偵錯或分析) 的情況下才使用 SetSeed,因為它會造成非隨機的行為。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Count</maml:name> <maml:description> <maml:para>決定傳回的物件數目。預設為 1。如果 Count 的值超過集合中的物件數目,Get-Random 會以隨機順序傳回所有物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>1</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定物件的集合。Get-Random 會從集合以隨機順序取得隨機選取的物件。請輸入物件、含有物件的變數或是可取得物件的命令或運算式。您也可經由管道將物件的集合輸出至 Get-Random。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Maximum</maml:name> <maml:description> <maml:para>指定亂數的最大值。Get-Random 會傳回小於 (不等於) 最大值的值。請輸入 32 位元整數或雙精度浮點數,或是輸入可轉換成整數或雙精度浮點數的物件,例如數值字串 ("100")。Maximum 的值必須大於 (不等於) Minimum 的值。 如果 Maximum 或 Minimum 的值為浮點數,Get-Random 會傳回隨機選取的浮點數。 如果 Minimum 的值為雙精度浮點數 (Double),Maximum 的預設值則為 Double.MaxValue,否則預設值為 Int32.MaxValue (2,147,483,647 或 0x7FFFFFFF)。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Int32.MaxValue</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Minimum</maml:name> <maml:description> <maml:para>指定亂數的最小值。請輸入 32 位元整數或雙精度浮點數,或是輸入可轉換成整數或雙精度浮點數的物件,例如數值字串 ("100")。預設值為 0 (零)。 Minimum 的值必須小於 (不等於) Maximum 的值。如果 Maximum 或 Minimum 的值為浮點數,Get-Random 會傳回隨機選取的浮點數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>0</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SetSeed</maml:name> <maml:description> <maml:para>指定亂數產生器的種子值。這個種子值將一直用於目前的命令和目前工作階段中的所有後續 Get-Random 命令,直到您再次使用 SetSeed 或關閉工作階段為止。您無法將種子重設回預設值,這個值會因時而異。 SetSeed 參數不是必要的。根據預設,Get-Random 會以系統時鐘來產生種子值。通常只有在嘗試重新產生行為 (例如對包含 Get-Random 命令的指令碼進行偵錯或分析) 的情況下才使用 SetSeed,因為它會造成非隨機的行為。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>系統時鐘</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Object</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將一個或多個物件輸出至 Get-Random。Get-Random 會從管道物件隨機選取值。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Object</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-Random 會傳回整數或浮點數,或是從送出的集合隨機選取的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 當工作階段開始時,Get-Random 會根據系統時鐘設定每個工作階段的預設種子。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-random 3951433 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得一個介於 0 (零) 到 Int32.MaxValue 之間的隨機整數。 </maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-random -maximum 100 47 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得一個介於 0 (零) 到 99 之間的隨機整數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-random -minimum -100 -maximum 100 -56 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得一個介於 -100 到 99 之間的隨機整數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-random -min 10.7 -max 20.93 18.08467273887 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得一個大於或等於 10.7 且小於 20.92 的隨機浮點數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-random -input 1, 2, 3, 5, 8, 13 8 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從指定的陣列取得隨機選取的數字。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-random -input 1, 2, 3, 5, 8, 13 -count 3 3 1 13 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從陣列以隨機順序取得三個隨機選取的數字。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-random -input 1, 2, 3, 5, 8, 13 -count ([int]::MaxValue) 2 3 5 1 8 13 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會以隨機順序傳回整個集合。Count 參數值是整數的 MaxValue 靜態屬性。 若要以隨機順序傳回整個集合,請輸入任何大於或等於集合中的物件數目的數字。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 8 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-random -input "red", "yellow", "blue" yellow </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從非數值集合傳回隨機值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 9 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | get-random Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 144 4 2080 488 36 0.48 3164 wmiprvse </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從電腦上的處理序集合取得隨機選取的處理序。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 10 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-content servers.txt | get-random -count (get-content servers.txt).count | foreach {invoke-expression -computer $_ -command 'get-process powershell'} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會以隨機順序在一連串的遠端電腦上執行命令。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 11 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-random -max 100 -setseed 23 # Commands with the default seed are pseudorandom PS C:\ps-test> get-random -max 100 59 PS C:\ps-test> get-random -max 100 65 PS C:\ps-test> get-random -max 100 21 # Commands with the same seed are not random PS C:\ps-test> get-random -max 100 -setseed 23 74 PS C:\ps-test> get-random -max 100 -setseed 23 74 PS C:\ps-test> get-random -max 100 -setseed 23 74 # SetSeed results in a repeatable series PS C:\ps-test> get-random -max 100 -setseed 23 74 PS C:\ps-test> get-random -max 100 56 PS C:\ps-test> get-random -max 100 84 PS C:\ps-test> get-random -max 100 46 PS C:\ps-test> get-random -max 100 -setseed 23 74 PS C:\ps-test> get-random -max 100 56 PS C:\ps-test> get-random -max 100 84 PS C:\ps-test> get-random -max 100 46 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範 SetSeed 參數的使用效果。SetSeed 通常只用於重新產生結果 (例如對指令碼進行偵錯或分析的時候),因為它會造成非隨機的行為。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 12 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $files = dir -path c:\* -recurse C:\PS> $sample = $files | get-random -count 50 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會從本機電腦的 C : 磁碟機取得隨機抽選的 50 個檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 13 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-random 10001 7600 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得一個小於 10001 的隨機整數。因為 Maximum 參數的位置為 1,所以當這個參數的值在命令中是第一個或唯一未具名的參數時,您就可以省略它的參數名稱。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113446</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-TraceSource </command:name> <maml:description> <maml:para>取得執行追蹤所配備的 Windows PowerShell 元件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>TraceSource</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-TraceSource Cmdlet 可以為目前使用中的 Windows PowerShell 元件取得追蹤來源。您可以使用資料來判斷可追蹤哪一個 Windows PowerShell 元件。進行追蹤時,此元件會產生詳細訊息列出每個內部處理步驟的相關資訊。開發人員可使用追蹤資料來監視資料流程、程式執行與錯誤。追蹤 Cmdlet 是專為 Windows PowerShell 開發人員而設計,但是也能提供給所有的使用者使用。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-TraceSource</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>只取得指定的追蹤來源。允許使用萬用字元。參數名稱 ("Name") 為選擇項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>只取得指定的追蹤來源。允許使用萬用字元。參數名稱 ("Name") 為選擇項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可以經由管道將包含追蹤來源名稱的字串輸出至 Get-TraceSource。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSTraceSource</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-TraceSource 會傳回代表追蹤來源的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-traceSource *provider* </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令取得其名稱包含 "provider" 的所有追蹤來源。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-tracesource </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令取得所有可追蹤的 Windows PowerShell 元件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113333</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-TraceSource</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Trace-Command</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-UICulture </command:name> <maml:description> <maml:para>取得作業系統中的目前使用者介面 (UI) 文化特性設定。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>UICulture</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-UICulture Cmdlet 會取得有關 Windows 目前使用者介面 (UI) 文化特性設定的資訊。UI 文化特性決定哪些文字字串會用於使用者介面元素,例如功能表和訊息。 您也可以使用 Get-Culture Cmdlet,它也會取得系統目前的文化特性。文化特性決定項目 (如數字、貨幣和日期) 的顯示格式。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-UICulture</maml:name> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Globalization.CultureInfo</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-UICulture 會傳回代表目前 UI 文化特性的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以使用 $PsCulture 和 $PsUICulture 變數。$PsCulture 變數會儲存目前文化特性的名稱,而 $PsUICulture 變數會儲存目前 UI 文化特性的名稱。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-uiculture </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令取得目前的 UI 文化特性資訊。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-uiculture | format-list * </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將目前 UI 文化特性的所有屬性值顯示在清單中。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> (get-uiculture).calendar </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示目前 UI 文化特性的目前 Calendar 屬性值。Calendar 只是 UI 文化特性的其中一個屬性。若要查看所有屬性,請輸入 "get-uiculture | get-member"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> (get-uiculture).datetimeformat.shortdatepattern </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示目前 UI 文化特性的簡短日期模式。若要查看 UI 文化特性之 DateTimeFormat 屬性的所有子屬性,請輸入 "(get-uiculture).datetimeformat | gm"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113334</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-Unique </command:name> <maml:description> <maml:para>從排序清單傳回唯一項目。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>Unique</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-Unique Cmdlet 會將排序清單中的每個項目與下一個項目做比較、刪除重複項目,然後只傳回每個項目的一個執行個體。清單必須經過排序,才能使 cmdlet 正確執行。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-Unique</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AsString</maml:name> <maml:description> <maml:para>將資料視為字串。若沒有此參數,資料會被視為物件,因此當您將相同型別的物件集合 (例如檔案集合) 送出給 Get-Unique 時,它就只會傳回一個物件 (第一個物件)。使用此參數可找出物件屬性 (例如檔案名稱) 未重複的值。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>接受 Get-Unique 的輸入。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。 Get-Unique 會將以 InputObject 參數送出的輸入視為集合,而且不會列舉集合中的個別項目。由於集合是單一項目,使用 InputObject 所提交的輸入始終都將原封不動地傳回。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Get-Unique</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>OnType</maml:name> <maml:description> <maml:para>每一種類型只傳回一個物件。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>接受 Get-Unique 的輸入。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。 Get-Unique 會將以 InputObject 參數送出的輸入視為集合,而且不會列舉集合中的個別項目。由於集合是單一項目,使用 InputObject 所提交的輸入始終都將原封不動地傳回。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AsString</maml:name> <maml:description> <maml:para>將資料視為字串。若沒有此參數,資料會被視為物件,因此當您將相同型別的物件集合 (例如檔案集合) 送出給 Get-Unique 時,它就只會傳回一個物件 (第一個物件)。使用此參數可找出物件屬性 (例如檔案名稱) 未重複的值。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>接受 Get-Unique 的輸入。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。 Get-Unique 會將以 InputObject 參數送出的輸入視為集合,而且不會列舉集合中的個別項目。由於集合是單一項目,使用 InputObject 所提交的輸入始終都將原封不動地傳回。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>OnType</maml:name> <maml:description> <maml:para>每一種類型只傳回一個物件。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件類型輸出至 Get-Unique。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-Unique 所傳回的物件類型是由輸入所決定。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以利用內建的別名 "gu" 來參照 Get-Unique。如需詳細資訊,請參閱 about_Aliases。 若要排序清單,請使用 Sort-Object。您也可以使用 Sort-Object 的 Unique 參數,在清單中尋找唯一項目。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = $(foreach ($line in get-content C:\Test1\File1.txt) {$line.tolower().split(" ")}) | sort | get-unique C:\PS> $a.count </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令將找出文字檔中共有多少不同的單字。 第一個命令取得 File.txt 檔案的內容,並將每一行文字轉換為小寫字母,然後在空格 (" ") 處,將每個單字分割到個別的一行。接著,依字母順序 (預設) 排序產生的清單,並使用 Get-Unique Cmdlet 來刪除任何重複的單字。結果會儲存在 $a 變數中。 第二個命令使用 $a 中的字串集合的 Count 屬性來判斷 $a 內有多少項目。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> 1,1,1,1,12,23,4,5,4643,5,3,3,3,3,3,3,3 | sort-object | Get-Unique </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將找出一組整數中的唯一成員。第一個命令接受命令列輸入的整數陣列,並經由管道輸出至 Sort-Object Cmdlet 進行排序,然後再經由管道輸出至 Get-Unique,以刪除結果中的重複項目。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | sort-object {$_.GetType()} | unique -OnType </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 Get-ChildItem Cmdlet 來擷取本機目錄的內容,此目錄含有檔案及其他目錄。管線運算子 (|) 會將結果傳送到 Sort-Object Cmdlet。"$_.GetType()" 陳述式將 GetType 方法套用到每個檔案或目錄。接著,Sort-Object 會依據類型排序項目。另一個管線運算子會將結果傳送至 Get-Unique。OnType 參數指示 Get-Unique 只傳回每個類型中的一個物件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | sort-object | select processname | get-unique -asstring </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令取得電腦上執行的處理序名稱,並刪除重複的名稱。 Get-Process 命令會取得電腦上的所有處理序。管線運算子 (|) 會將結果傳遞給 Sort-Object,後者預設會根據 ProcessName 的字母順序排序處理序。結果會經由管道輸出至 Select-Object Cmdlet,此 Cmdlet 只會選取每個物件中的 ProcessName 屬性值。然後結果會經由管道輸出至 Get-Unique 以刪除重複項目。 AsString 參數指示 Get-Unique 將 ProcessName 值當做字串來處理。不使用這個參數,Get-Unique 就會將 ProcessName 值當做物件處理,然後只傳回一個物件執行個體,也就是清單中的第一個處理序名稱。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113335</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Select-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Sort-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Get-Variable </command:name> <maml:description> <maml:para>取得目前主控台中的變數。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Get</command:verb> <command:noun>Variable</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Get-Variable Cmdlet 會取得目前主控台中的 Windows PowerShell 變數。您可以指定 ValueOnly 參數,只擷取變數的值,然後依據名稱篩選傳回的變數。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Get-Variable</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定變數的名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>指定僅限此 Cmdlet 將對其執行的項目,排除其餘所有項目。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>只取得指定之範圍中的變數。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ValueOnly</maml:name> <maml:description> <maml:para>只取得變數的值。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>指定僅限此 Cmdlet 將對其執行的項目,排除其餘所有項目。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定變數的名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>只取得指定之範圍中的變數。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ValueOnly</maml:name> <maml:description> <maml:para>只取得變數的值。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含變數名稱的字串輸出至 Get-Variable。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>變數物件</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Get-Variable 會針對它取得的每一個變數各傳回一個 System.Management.Automation 變數物件。物件類型取決於變數。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 這個 cmdlet 並不管理環境變數。若要管理環境變數,您可以使用環境變數提供者。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-variable m* </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示名稱開頭為字母 "m" 的變數,同時也會顯示變數的值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-variable m* -valueonly </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令只顯示名稱開頭為字母 "m" 之變數的值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-variable -include M*,P* | sort-object name </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得以字母 "M" 或字母 "P" 開頭之變數的相關資訊。結果會經由管道輸出至 Sort-Object Cmdlet,然後依據名稱排序後顯示出來。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-variable -scope 0 C:\PS> compare-object (get-variable -scope 0) (get-variable -scope 1) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>第一個命令只會取得定義在區域範圍中的變數。此命令相當於 "get-variable -scope local",而且可縮短為 "gv -s 0"。 第二個命令會使用 Compare-Object Cmdlet 找出定義在父範圍 (範圍 1) 但只顯示在區域範圍 (範圍 0) 中的變數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113336</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Clear-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Group-Object </command:name> <maml:description> <maml:para>將指定的屬性含有相同屬性值的物件歸為群組。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Group</command:verb> <command:noun>Object</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Group-Object Cmdlet 會根據指定的屬性值來分組顯示的物件。Group-Object 會傳回一個表格,其中每個屬性值各為一列,而欄則顯示有該值的項目數。 如果您指定一個以上的屬性,Group-Object 會先依據第一個屬性的值進行分組,然後在每個屬性群組內再依據下一個屬性的值進行分組。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Group-Object</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AsHashTable</maml:name> <maml:description> <maml:para>以雜湊表形式傳回群組。雜湊表的索引鍵是分組物件所依據的屬性值,而雜湊表的值則是有該屬性值的物件。 AsHashTable 參數會自行傳回每個雜湊表,當中每個索引鍵都是分組物件的執行個體。此參數與 AsString 參數搭配使用時,雜湊表中的索引鍵會是字串。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AsString</maml:name> <maml:description> <maml:para>將雜湊表索引鍵轉換成字串。根據預設,雜湊表索引鍵是分組物件的執行個體。此參數只有與 AsHashTable 參數搭配使用時才有效。 </maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定分組的屬性。物件將會依照指定的屬性值進行分組。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請建立一個包含 Expression 索引鍵的雜湊表,此索引鍵會指定字串或指令碼區塊值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CaseSensitive</maml:name> <maml:description> <maml:para>讓分組有大小寫之分。若沒有此參數,物件的屬性值在群組中可能會有不同的大小寫。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Culture</maml:name> <maml:description> <maml:para>指定比較字串時所要使用的文化特性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要分組的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。 當您使用 InputObject 參數將物件的集合送出給 Group-Object 時,Group-Object 會接收一個代表集合的物件,因此它會建立一個有該物件的群組做為其成員。 若要將集合中的物件進行分組,請經由管道將物件輸出至 Group-Object。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoElement</maml:name> <maml:description> <maml:para>將群組的成員從結果中省略。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AsHashTable</maml:name> <maml:description> <maml:para>以雜湊表形式傳回群組。雜湊表的索引鍵是分組物件所依據的屬性值,而雜湊表的值則是有該屬性值的物件。 AsHashTable 參數會自行傳回每個雜湊表,當中每個索引鍵都是分組物件的執行個體。此參數與 AsString 參數搭配使用時,雜湊表中的索引鍵會是字串。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>GroupInfo 物件</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AsString</maml:name> <maml:description> <maml:para>將雜湊表索引鍵轉換成字串。根據預設,雜湊表索引鍵是分組物件的執行個體。此參數只有與 AsHashTable 參數搭配使用時才有效。 </maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>GroupInfo 物件</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CaseSensitive</maml:name> <maml:description> <maml:para>讓分組有大小寫之分。若沒有此參數,物件的屬性值在群組中可能會有不同的大小寫。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Culture</maml:name> <maml:description> <maml:para>指定比較字串時所要使用的文化特性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要分組的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。 當您使用 InputObject 參數將物件的集合送出給 Group-Object 時,Group-Object 會接收一個代表集合的物件,因此它會建立一個有該物件的群組做為其成員。 若要將集合中的物件進行分組,請經由管道將物件輸出至 Group-Object。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoElement</maml:name> <maml:description> <maml:para>將群組的成員從結果中省略。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定分組的屬性。物件將會依照指定的屬性值進行分組。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請建立一個包含 Expression 索引鍵的雜湊表,此索引鍵會指定字串或指令碼區塊值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Group-Object </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>Microsoft.PowerShell.Commands.GroupInfo 或 System.Collections.Hashtable</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 AsHashTable 參數時,Group-Object 會傳回雜湊表。否則,它會傳回 GroupInfo 物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以使用格式化 Cmdlet (例如 Format-Table [m2] 和 Format-List [m2]) 的 GroupBy 參數來分組物件。不像 Group-Object 在建立每個屬性值各為一列的單一表格時,GroupBy 參數會為每個屬性值各建立一個表格,其中每一個有屬性值的項目各為一列。 Group-Object 不要求分組的物件必須屬於相同 Microsoft .NET Framework 型別。對不同 .NET Framework 型別的物件進行分組時,Group-Object 會使用下列規則: -- 屬性名稱和型別都相同:如果物件的屬性有指定的名稱,而且屬性值有相同的 .NET Framework 型別,則會以相同的規則 (用於相同型別的物件) 來分組屬性值。 -- 屬性名稱相同但型別不同:如果物件的屬性有指定的名稱,但是屬性值在不同的物件中各有不同的 .NET Framework 型別,則 Group-Object 會使用第一個出現之屬性的 .NET Framework 型別做為該屬性群組的 .NET Framework 型別。當物件有不同型別的屬性時,Group-Object 會將屬性值轉換成該群組的型別。如果型別轉換失敗,則不會將物件列入該群組。 -- 缺少屬性:沒有指定屬性的物件視為不可分組。不可分組物件會在名為 AutomationNull.Value 群組的最終 GroupInfo 物件輸出中出現。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem *.doc | group-object -property length </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得目前位置中副檔名為 .doc 的檔案,然後依大小進行分組。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | sort-object -property extension | group-object -property extension </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得目前位置中的檔案,然後依副檔名排序檔案,再依副檔名進行分組。請注意,先排序再分組檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> 1..35 | group-object -property {$_ % 2},{$_ % 3} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用指令碼區塊做為 Property 參數的值。 這個命令會顯示從 1 到 35 的整數,並依據除以 2 或 3 所得之餘數來分組。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $events = get-eventlog -logname system -newest 1000 C:\PS> $events | group-object -property eventID Count Name Group ----- ---- ----- 44 Information {System.Diagnostics.EventLogEntry, 5 Error {System.Diagnostics.EventLogEntry, 1 Warning {System.Diagnostics.EventLogEntry} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會顯示系統事件記錄檔中最新的 1,000 個項目,並依據事件識別碼進行分組。 第一個命令會使用 Get-EventLog Cmdlet 擷取事件,並使用指派運算子 (=) 將這些事件儲存到 $events 變數。 第二個命令會使用管線運算子 (|) 將 $events 變數中事件傳送給 Group-Object Cmdlet,並使用 Property 參數指定事件應該依據 EventID 屬性的值進行分組。 在輸出中,Count 欄代表每個群組中的項目數、Name 欄代表 EventID 值 (每個值各定義一個群組),而 Group 欄則代表每個群組中的物件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | group-object -property priorityclass Count Name Group ----- ---- ----- 55 Normal {System.Diagnostics.Process (AdtAgent), System.Diagnostics.Process (alg), System.Dia... 1 {System.Diagnostics.Process (Idle)} 3 High {System.Diagnostics.Process (Newproc), System.Diagnostics.Process (winlogon), System.D... 2 BelowNormal {System.Diagnostics.Process (winperf), C:\PS>get-process | group-object -property company -noelement Count Name ----- ---- 55 Normal 1 3 High 2 BelowNormal </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範 NoElement 參數的效果。這些命令會依據優先類別將電腦上的處理序進行分組。 第一個命令會使用 Get-Process Cmdlet 取得電腦上的處理序,並使用管線運算子 (|) 將結果傳送給 Group-Object,讓後者依照處理序的 PriorityClass 屬性值來分組物件。 第二個命令會使用 NoElement 參數將群組的成員從結果中排除,除這點以外與第一個命令無異。結果為一個只有計數和屬性名稱的表格。 下列範例的輸出會顯示結果。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-eventlog -logname system -newest 1000 | group-object -property {$_.TimeWritten - $_.TimeGenerated} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令示範如何提供 Property 參數的值做為指令碼區塊。 這個命令顯示系統事件記錄檔中最新的 1,000 個項目,並依據從產生項目到寫入記錄檔的期間加以分組。 此命令會使用 Get-EventLog Cmdlet 取得事件記錄檔項目。它會使用管線運算子 (|) 傳送項目給 Group-Object Cmdlet。Property 參數值被指定為指令碼區塊 (大括號內的運算式)。指令碼區塊評估所得結果為產生日誌項目與此項目寫入日誌之間的期間。這個值會用來將 1000 個最新的事件分組。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | group-object extension -noelement Count Name ----- ---- 21 82 .txt 9 .cmd 5 .log 12 .xml 5 .htm 36 .ps1 1 .psc1 3 .exe 6 .csv 1 .psd1 2 .bat </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會依據副檔名將目前目錄中的項目進行分組,並使用 NoElement 省略群組的成員。 下列範例的輸出會顯示結果。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 8 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> "a", "b", "c", "c", "d" | get-unique a b c d C:\PS> "a", "b", "c", "c", "d" | group-object -noelement | where {$_.Count -gt 1} Count Name ----- ---- 2 c C:\PS> get-process | group-object -property Name -noelement | where {$_.count -gt 1} Count Name ----- ---- 2 csrss 5 svchost 2 winlogon 2 wmiprvse </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何找出集合中唯一的和非唯一的 (重複的) 屬性值。 第一個命令會經由管道將陣列輸出至 Get-Unique Cmdlet,以取得陣列的唯一的元素。 第二個命令會取得陣列的非唯一元素,並經由管道將陣列輸出至 Group-Object Cmdlet,讓後者依據值來分組物件。產生的群組會經由管道輸出至 Where-Object Cmdlet,讓後者選取有一個以上的群組成員的物件。 第三個命令示範這項技巧的實用用途,並以相同方法來找出電腦上同名的處理序。 下列範例的輸出會顯示結果。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 9 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-command get-*, set-* -type cmdlet | group-object -property verb -ashashtable -asstring C:\PS> $a Name Value ---- ----- Get {Get-PSCallStack, Get-PSBreakpoint, Get-PSDrive, Get-PSSession...} Set {Set-Service, Set-StrictMode, Set-PSDebug, Set-PSSessionConfiguration...} C:\PS> $a.get CommandType Name Definition ----------- ---- ---------- Cmdlet Get-PSCallStack Get-PSCallStack [-Verbose] [-Debug] [-ErrorAction <ActionPrefer... Cmdlet Get-PSBreakpoint Get-PSBreakpoint [[-Id] <Int32[]>] [-Verbose] [-Debug] [-ErrorA... Cmdlet Get-PSDrive Get-PSDrive [[-Name] <String[]>] [-Scope <String>] [-PSProvider... ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會使用 AsHashTable 和 AsString 參數,以雜湊表形式 (也就是以索引鍵值組的集合形式) 傳回群組。 在產生的雜湊表中,每個屬性值都是一個索引鍵,而群組元素則為值。因為每個索引鍵都是雜湊表物件的屬性,您可以使用點標記法來顯示值。 第一個命令會取得工作階段中的 Get 和 Set Cmdlet,接著依據動詞進行分組,然後以雜湊表形式傳回群組,再將雜湊表儲存到 $a 變數。 第二個命令會顯示 $a 中的雜湊表。索引鍵值組有兩組,一組用於 Get Cmdlet,另一組用於 Set Cmdlet。 第三個命令會以點標記法來顯示 $a 中 Get 索引鍵的值。這些值為 CmdletInfo 物件。AsString 參數並不會將群組中的物件轉換成字串。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113338</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Import-Alias </command:name> <maml:description> <maml:para>從檔案匯入別名清單。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Import</command:verb> <command:noun>Alias</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Import-Alias Cmdlet 會從檔案匯入別名清單。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Import-Alias</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定匯出別名資訊的檔案所在路徑。允許使用萬用字元,但解析結果必須是單一名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 匯入已定義的唯讀別名。使用下列命令可顯示目前已定義別名的相關資訊: get-alias | select-object name,Options 如果對應的別名為唯讀,則 Options 屬性值將包含 "ReadOnly"。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表別名的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定匯入別名的目標範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 匯入已定義的唯讀別名。使用下列命令可顯示目前已定義別名的相關資訊: get-alias | select-object name,Options 如果對應的別名為唯讀,則 Options 屬性值將包含 "ReadOnly"。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表別名的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定匯出別名資訊的檔案所在路徑。允許使用萬用字元,但解析結果必須是單一名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定匯入別名的目標範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含路徑的字串輸出至 Import-Alias。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.AliasInfo</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 Passthru 參數時,Import-Alias 會傳回代表別名的 System.Management.Automation.AliasInfo 物件,否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> import-alias test.txt </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從名為 test.txt 的檔案匯入別名資訊。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113339</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Import-Clixml </command:name> <maml:description> <maml:para>將 CLIXML 檔案匯入 Windows PowerShell 並建立對應的物件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Import</command:verb> <command:noun>Clixml</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Import-Clixml Cmdlet 會將包含了代表 Microsoft .NET Framework 物件之資料的 CLIXML 檔案匯入,並在 Windows PowerShell 中建立這些物件。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Import-Clixml</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定要轉換成 Windows PowerShell 物件之 XML 檔案的位置。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定要轉換成 Windows PowerShell 物件之 XML 檔案的位置。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含路徑的字串輸出至 Import-Clixml。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Import-Clixml 會傳回已經從儲存的 XML 檔案中還原序列化的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 若要為參數指定多重數值,請使用逗號來分隔數值。例如:"<參數名稱> <值1>, <值2>"。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | export-clixml pi.xml C:\PS> $processes = import-clixml pi.xml </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 Export-Clixml Cmdlet 來儲存 Get-Process 所傳回之處理序資訊的序列化副本。它接著使用 Import-Clixml 來擷取序列化檔案的內容,並重新建立儲存在 $processes 變數中的物件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113340</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Import-CSV </command:name> <maml:description> <maml:para>將以逗號分隔值 (CSV) 檔案中的物件屬性轉換成原始物件的 CSV 版本。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Import</command:verb> <command:noun>CSV</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Import-CSV Cmdlet 會從 Export-CSV Cmdlet 所產生之變動長度的 CSV 檔案建立物件。 您可以使用 Import-CSV Cmdlet 的參數指定欄標頭列 (用來決定產生之物件的屬性名稱)、指定項目分隔符號,或是指示 Import-CSV 將目前文化特性的清單分隔符號當成項目分隔符號。 Import-CSV 建立的物件是原始物件的 CSV 版本,而 CSV 物件的屬性值是原始物件的屬性值的字串版本。物件的 CSV 版本沒有任何方法。 您也可以使用 ConvertTo-CSV 和 ConvertFrom-CSV Cmdlet,將物件轉換成 CSV 字串 (反之亦然)。除了不將 CSV 字串儲存到檔案中以外,這兩個 Cmdlet 與 Export-CSV 和 Import-CSV Cmdlet 都相同。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Import-CSV</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Delimiter</maml:name> <maml:description> <maml:para>指定用來在 CSV 檔案中分隔屬性值的分隔符號。預設為逗號 (,)。請輸入字元,例如分號 (:)。若要指定分號 (;),請將其置於引號內。 如果您指定的字元不是檔案中所使用的實際字串分隔符號,Import-CSV 便無法從 CSV 字串建立物件,而是會傳回字串。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">char</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定要匯入的 CSV 檔案所在路徑。您也可經由管道將路徑輸出至 Import-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Header</maml:name> <maml:description> <maml:para>為匯入的檔案指定其他的欄標頭列。欄標頭決定 Import-CSV 所建立之物件的屬性名稱。 請輸入逗號分隔欄標頭的清單,並以引號 (單引號或雙引號) 括住每一個項目,但不要以引號括住標頭字串。如果您輸入比實際欄數量還要少的欄標頭,剩餘的欄會沒有標頭。如果輸入比實際欄數量還要多的欄標頭,則會忽略多餘的欄標頭。 使用 Header 參數時,請從 CSV 檔案刪除原始的標頭列,否則 Import-CSV 會從標頭列的項目建立多餘的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Import-CSV</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UseCulture</maml:name> <maml:description> <maml:para>使用目前文化特性的清單分隔符號做為項目分隔符號。預設為逗號 (,)。 若要尋找文化特性的清單分隔符號,請使用下列命令:(Get-Culture).TextInfo.ListSeparator。如果您指定的字元不是 CSV 字串中所使用的分隔字元,ConvertFrom-CSV 會無法從 CSV 字串建立物件,而是會傳回字串。</maml:para> </maml:description> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定要匯入的 CSV 檔案所在路徑。您也可經由管道將路徑輸出至 Import-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Header</maml:name> <maml:description> <maml:para>為匯入的檔案指定其他的欄標頭列。欄標頭決定 Import-CSV 所建立之物件的屬性名稱。 請輸入逗號分隔欄標頭的清單,並以引號 (單引號或雙引號) 括住每一個項目,但不要以引號括住標頭字串。如果您輸入比實際欄數量還要少的欄標頭,剩餘的欄會沒有標頭。如果輸入比實際欄數量還要多的欄標頭,則會忽略多餘的欄標頭。 使用 Header 參數時,請從 CSV 檔案刪除原始的標頭列,否則 Import-CSV 會從標頭列的項目建立多餘的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Delimiter</maml:name> <maml:description> <maml:para>指定用來在 CSV 檔案中分隔屬性值的分隔符號。預設為逗號 (,)。請輸入字元,例如分號 (:)。若要指定分號 (;),請將其置於引號內。 如果您指定的字元不是檔案中所使用的實際字串分隔符號,Import-CSV 便無法從 CSV 字串建立物件,而是會傳回字串。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">char</command:parameterValue> <dev:type> <maml:name>char</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>,</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Header</maml:name> <maml:description> <maml:para>為匯入的檔案指定其他的欄標頭列。欄標頭決定 Import-CSV 所建立之物件的屬性名稱。 請輸入逗號分隔欄標頭的清單,並以引號 (單引號或雙引號) 括住每一個項目,但不要以引號括住標頭字串。如果您輸入比實際欄數量還要少的欄標頭,剩餘的欄會沒有標頭。如果輸入比實際欄數量還要多的欄標頭,則會忽略多餘的欄標頭。 使用 Header 參數時,請從 CSV 檔案刪除原始的標頭列,否則 Import-CSV 會從標頭列的項目建立多餘的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定要匯入的 CSV 檔案所在路徑。您也可經由管道將路徑輸出至 Import-CSV。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UseCulture</maml:name> <maml:description> <maml:para>使用目前文化特性的清單分隔符號做為項目分隔符號。預設為逗號 (,)。 若要尋找文化特性的清單分隔符號,請使用下列命令:(Get-Culture).TextInfo.ListSeparator。如果您指定的字元不是 CSV 字串中所使用的分隔字元,ConvertFrom-CSV 會無法從 CSV 字串建立物件,而是會傳回字串。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>逗號</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含路徑的字串輸出至 Import-CSV。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>Object。</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Import-CSV 會傳回 CSV 檔案中內容所描述的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 因為匯入的物件是物件型別的 CSV 版本,Windows PowerShell 型別格式化項目 (用來格式化物件型別的非 CSV 版本) 無法識別和格式化這些物件。 在 CSV 檔案中,每個物件都會由逗號分隔物件屬性值的清單來代表。屬性值會轉換成字串 (利用物件的 ToString() 方法),所以一般由屬性值的名稱來代表。Export-CSV 並不會匯出物件的方法。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | export-csv processes.csv C:\PS> $p = import-CSV processes.csv C:\PS> $p | get-member TypeName: CSV:System.Diagnostics.Process Name MemberType Definition ---- ---------- ---------- Equals Method System.Boolean Equals(Object obj) GetHashCode Method System.Int32 GetHashCode() GetType Method System.Type GetType() ToString Method System.String ToString() BasePriority NoteProperty System.String BasePriority=8 Company NoteProperty System.String Company=Microsoft Corporation ... C:\PS> $p | out-gridview </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何將 Microsoft .NET Framework 物件的 CSV 檔案匯出後再匯入。 第一個命令會使用 Get-Process Cmdlet 取得本機電腦上的處理序,並使用管線運算子 (|) 將處理序物件傳送給 Export-CSV Cmdlet,讓後者將處理序物件匯出到目前目錄中的 Processes.csv 檔案。 第二個命令會使用 Import-CSV Cmdlet 匯入 Import-CSV 檔案中的處理序,然後將產生的處理序物件儲存到 $p 變數。 第三個命令會使用管線運算子將匯入的物件傳送給 Get-Member Cmdlet。結果會顯示這些物件是 CSV:System.Diagnostic.Process 物件,而不是 Get-Process 傳回的 System.Diagnostic.Process 物件。 再者,因為在處理序物件的 CSV 版本的格式化檔案中沒有項目型別,因此不會像格式化標準處理序物件一樣格式化這些物件。 若要顯示物件,請使用格式化 Cmdlet (如 Format-Table 和 Format-List),或經由管道將物件輸出至 Out-GridView。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | export-csv processes.csv -Delimiter : C:\PS> $p = import-csv processes.csv -Delimiter : </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用 Import-CSV 的 Delimiter 參數。在這個範例中,處理序會匯出到以冒號 (:) 當做分隔符號的檔案中。 在匯入時,Import-CSV 檔案會使用 Delimiter 參數來代表檔案中所使用的分隔符號。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $p = import-csv processes.csv -UseCulture C:\PS> (get-culture).textinfo.listseparator , </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用 Import-CSV 的 UseCulture 參數。 第一個命令會將 Processes.csv 檔案中的物件匯入 $p 變數,並以 UseCulture 參數來指示 Import-CSV 使用為目前文化特性定義的清單分隔符號。 第二個命令會顯示目前文化特性的清單分隔符號。此命令會使用 Get-Culture Cmdlet 取得目前的文化特性,以及使用點 (.) 方法取得目前文化特性的 TextInfo 屬性和 TextInfo 中物件的 ListSeparator 屬性。在這個範例中,此命令會傳回逗號。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> start-job -scriptblock { get-process } | export-csv jobs.csv C:\PS> $header = "MoreData","StatusMessage","Location","Command","State","Finished","InstanceId","SessionId","Name","ChildJobs","Output","Error","Progress","Verbose","Debug","Warning","StateChanged" # Delete header from file C:\PS> $a = (get-content jobs.csv) C:\PS> $a = $a[0], $a[2..($a.count - 1)] C:\PS> $a > jobs.csv C:\PS> $j = import-csv jobs.csv -header $header C:\PS> $j MoreData : True StatusMessage : Location : localhost Command : get-process State : Running Finished : System.Threading.ManualResetEvent InstanceId : 135bdd25-40d6-4a20-bd68-05282a59abd6 SessionId : 1 Name : Job1 ChildJobs : System.Collections.Generic.List`1[System.Management.Automation.Job] Output : System.Management.Automation.PSDataCollection`1[System.Management.Automation.PSObject] Error : System.Management.Automation.PSDataCollection`1[System.Management.Automation.ErrorRecord] Progress : System.Management.Automation.PSDataCollection`1[System.Management.Automation.ProgressRecord] Verbose : System.Management.Automation.PSDataCollection`1[System.String] Debug : System.Management.Automation.PSDataCollection`1[System.String] Warning : System.Management.Automation.PSDataCollection`1[System.String] StateChanged : </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用 Import-CSV 的 Header 參數變更產生之匯入物件內的屬性名稱。 第一個命令會使用 Start-Job Cmdlet 啟動一個在本機電腦上執行 Get-Process 命令的背景工作。管線運算子 (|) 會將產生的工作物件傳送給 Export-CSV Cmdlet,讓後者將工作物件轉換成 CSV 格式。指派運算子 (=) 會將產生的 CSV 儲存到 Jobs.csv 檔案。 第二個命令會將標頭儲存到 $header 變數。此標頭與預設標頭不同之處在於它以 "MoreData" 來代替 "HasMoreData",而且以 "State" 來代替 "JobStateInfo"。 接下來的三個命令會從 Jobs.csv 檔案刪除原始標頭 (第二行)。 第六個命令會使用 Import-CSV Cmdlet 匯入 Jobs.csv 檔案,並將 CSV 字串轉換成工作物件的 CSV 版本。這個命令會使用 Header 參數送出其他的標頭。結果會儲存到 $j 變數。 第七個命令會顯示 $j 變數中的物件。產生的物件有 "MoreData" 和 "State" 屬性,如命令輸出所示。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> ".\processes.csv" | import-csv </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從 Processes.csv 檔案匯入物件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113341</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertTo-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertFrom-CSV</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Import-LocalizedData </command:name> <maml:description> <maml:para>根據為作業系統選取的 UI 文化特性,將特定語言的資料匯入指令碼和函數。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Import</command:verb> <command:noun>LocalizedData</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Import-LocalizedData Cmdlet 會從子目錄動態擷取字串,該子目錄的名稱符合目前作業系統使用者的 UI 語言設定。它是專門用來讓指令碼以目前使用者所選取的 UI 語言顯示使用者訊息。 Import-LocalizedData 會匯入指令碼目錄的語言特有子目錄中 .psd1 檔案的資料,並將其儲存於命令中所指定的區域變數內。此 Cmdlet 會根據 $PSUICulture 自動變數的值選取子目錄和檔案。當您使用指令碼中的區域變數顯示使用者訊息時,該訊息便會以使用者的 UI 語言顯示。 Import-LocalizedData 的參數可以用來指定替代 UI 文化特性、路徑和檔名,以及用來加入支援的命令及隱藏找不到 psd1 檔案時所出現的錯誤訊息。 Import-LocalizedData Cmdlet 在 Windows PowerShell 2.0 中支援指令碼國際化。此措施的目的便是要讓指令碼更容易以目前使用者的 UI 語言顯示使用者訊息,為全球使用者提供更好的服務。如需這部分內容及 .psd1 檔案格式的詳細資訊,請參閱 about_Script_Internationalization。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Import-LocalizedData</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>BindingVariable</maml:name> <maml:description> <maml:para>指定匯入文字字串的目標變數。請輸入變數名稱,但不要加上貨幣符號 ($)。 使用 Import-LocalizedData 取代指令碼的 DATA 區段中所指定的預設文字字串時,請指派 DATA 區段給變數,並在 BindingVariable 參數的值中輸入 DATA 區段變數的名稱。那麼,Import-LocalizedData 將匯入的內容儲存到 BindingVariable 時,匯入的資料就會取代預設的文字字串。如果您未指定預設文字字串,可以選取任何變數名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>UICulture</maml:name> <maml:description> <maml:para>指定其他的 UI 文化特性。預設為 $PsUICulture 自動變數的值。請以 "<language>-<region>" 格式輸入 UI 文化特性,例如 en-US、de-DE 或 ar-SA。 UICulture 參數的值決定 Import-LocalizedData Cmdlet 從中取得指令碼的 .psd1 檔案的特定語言子目錄 (位於基底目錄內)。 此 Cmdlet 會搜尋與 UICulture 參數或 $PsUICulture 自動變數的值同名的子目錄,例如 "de-DE" 或 "ar-SA"。如果它找不到該目錄,或該目錄未包含指令碼的 .psd1 檔案,則會搜尋與語言代碼同名的子目錄,例如 "de" 或 "ar"。如果它找不到該子目錄或 .psd1 檔案,則命令會失敗,而且資料會以指令碼中指定的預設語言顯示。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>BaseDirectory</maml:name> <maml:description> <maml:para>指定 .psd1 檔案所在的基底目錄。預設為指令碼所在的目錄。Import-LocalizedData 會在基底目錄的特定語言子目錄中搜尋指令碼的 .psd1 檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>FileName</maml:name> <maml:description> <maml:para>指定要匯入的 .psd1 檔名。請輸入檔名,但不要加上副檔名。 預設為指令碼的名稱。例如,若指令碼為 FindFiles.ps1,Import-LocalizedData 會搜尋 FindFiles.psd1。您可以使用此參數指示 Import-LocalizedData 搜尋不同的 .psd1 檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>SupportedCommand</maml:name> <maml:description> <maml:para>指定只產生資料的 Cmdlet 和函數。 使用這個參數是用來包含您已撰寫或測試的 Cmdlet 和函數。如需詳細資訊,請參閱 about_Script_Internationalization。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>BaseDirectory</maml:name> <maml:description> <maml:para>指定 .psd1 檔案所在的基底目錄。預設為指令碼所在的目錄。Import-LocalizedData 會在基底目錄的特定語言子目錄中搜尋指令碼的 .psd1 檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>BindingVariable</maml:name> <maml:description> <maml:para>指定匯入文字字串的目標變數。請輸入變數名稱,但不要加上貨幣符號 ($)。 使用 Import-LocalizedData 取代指令碼的 DATA 區段中所指定的預設文字字串時,請指派 DATA 區段給變數,並在 BindingVariable 參數的值中輸入 DATA 區段變數的名稱。那麼,Import-LocalizedData 將匯入的內容儲存到 BindingVariable 時,匯入的資料就會取代預設的文字字串。如果您未指定預設文字字串,可以選取任何變數名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>FileName</maml:name> <maml:description> <maml:para>指定要匯入的 .psd1 檔名。請輸入檔名,但不要加上副檔名。 預設為指令碼的名稱。例如,若指令碼為 FindFiles.ps1,Import-LocalizedData 會搜尋 FindFiles.psd1。您可以使用此參數指示 Import-LocalizedData 搜尋不同的 .psd1 檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>SupportedCommand</maml:name> <maml:description> <maml:para>指定只產生資料的 Cmdlet 和函數。 使用這個參數是用來包含您已撰寫或測試的 Cmdlet 和函數。如需詳細資訊,請參閱 about_Script_Internationalization。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>UICulture</maml:name> <maml:description> <maml:para>指定其他的 UI 文化特性。預設為 $PsUICulture 自動變數的值。請以 "<language>-<region>" 格式輸入 UI 文化特性,例如 en-US、de-DE 或 ar-SA。 UICulture 參數的值決定 Import-LocalizedData Cmdlet 從中取得指令碼的 .psd1 檔案的特定語言子目錄 (位於基底目錄內)。 此 Cmdlet 會搜尋與 UICulture 參數或 $PsUICulture 自動變數的值同名的子目錄,例如 "de-DE" 或 "ar-SA"。如果它找不到該目錄,或該目錄未包含指令碼的 .psd1 檔案,則會搜尋與語言代碼同名的子目錄,例如 "de" 或 "ar"。如果它找不到該子目錄或 .psd1 檔案,則命令會失敗,而且資料會以指令碼中指定的預設語言顯示。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Collections.Hashtable</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Import-LocalizedData 會將雜湊表儲存在 BindingVariable 參數值所指定的變數中。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 使用 Import-LocalizedData 之前,請先將您的使用者訊息當地語系化。針對每個地區設定 (UI 文化特性),以索引鍵值組的雜湊表形式格式化使用者訊息,然後將雜湊表儲存到與指令碼同名且副檔名為 .psd1 的檔案中。針對每個支援的 UI 文化特性,在指令碼目錄下建立目錄,然後將每個 UI 文化特性的 .psd1 檔案儲存到與 UI 文化特性同名的目錄。 例如,針對 de-DE 地區設定,將您的使用者訊息當地語系化,然後以雜湊表形式加以格式化。接著,將雜湊表儲存到 <ScriptName>.psd1 檔案,然後在指令碼目錄下建立 de-DE 子目錄,再將 de-DE <ScriptName>.psd1 檔案儲存到 de-DE 子目錄。針對每個所能支援的地區設定,重複上述方法。 Import-LocalizedData 會針對指令碼的當地語系化使用者訊息執行結構化搜尋。 Import-LocalizedData 會在指令碼檔所在的目錄 (或 BaseDirectory 參數的值) 中開始進行搜尋,然後在基底目錄內搜尋與 $PsUICulture 變數的值 (或 UICulture 參數的值) 同名的子目錄,例如 "de-DE" 或 "ar-SA",再在該子目錄中搜尋與指令碼 (或 FileName 參數的值) 同名的 .psd1 檔案。 如果 Import-LocalizedData 找不到與 UI 文化特性同名的子目錄,或該子目錄並未包含指令碼的 .psd1 檔案,則會在與語言代碼同名的子目錄 (如 "de" 或 "ar") 中搜尋指令碼的 .psd1 檔案。如果它找不到該子目錄或 .psd1 檔案,則命令會失敗、資料會以指令碼中的預設語言顯示,而且出現一個錯誤訊息,說明無法匯入資料。若要隱藏這個訊息,而且讓失敗不嚴重,請使用值為 SilentlyContinue 的一般參數 ErrorAction。 如果 Import-LocalizedData 找到該子目錄和 .psd1 檔案,則會將使用者訊息的雜湊表匯入命令中的 BindingVariable 參數值。然後,當您顯示來自變數中的雜湊表的訊息時,即會顯示當地語系化訊息。 如需詳細資訊,請參閱 about_Script_Internationalization。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> import-localizeddata -bindingVariable messages </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將文字字串匯入 $messages 變數,並使用 Cmdlet 參數的所有預設值。 如果在 C:\test 目錄中的 Archives.ps1 指令碼內包含命令,而且 $PsUICulture 自動變數的值為 zh-CN,Import-LocalizedData 則會匯入 C:\test\zh-CN 目錄中的 Archives.psd1 檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> import-localizeddata -bindingVariable msgTbl -uiculture ar-SA -filename Simple -baseDirectory C:\Data\Localized </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將文字字串匯入指令碼的 $msgTbl 變數。 它會使用 UICulture 參數指示 Cmdlet 從 C:\Data\Localized 的 ar-SA 子目錄中的 Simple.psd1 檔案匯入資料。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> # In C:\Test\en-US\test.psd1: ConvertFrom-StringData @' # English strings Msg1 = "The Name parameter is missing from the command." Msg2 = "This command requires the credentials of a member of the Administrators group on the computer." Msg3 = "Use $_ to represent the object that is being processed." '@ # In C:\Test\Test.ps1 import-localizeddata -bindingvariable messages write-host $messages.msg2 # In Windows PowerShell C:\PS> .\test.ps1 This command requires the credentials of a member of the Administrators group on the computer. </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用簡單指令碼中的當地語系化資料。 這個範例的第一部分是顯示 Test.psd1 檔案的內容,其中包含 ConvertFrom-StringData 命令,此命令會將一連串的具名文字字串轉換成雜湊表。test.psd1 檔案位於 C:\Test 目錄 (內含指令碼) 的 en-US 子目錄。 這個範例的第二部分是顯示 Test.ps1 指令碼的內容,其中包含 Import-LocalizedData 命令 (此命令可將相符之 .psd1 檔案中的資料匯入 $Messages 變數中) 及 Write-Host 命令 (此命令可將 $Messages 變數中的其中一個訊息寫入主程式中)。 此範例的最後一個部分會執行指令碼。輸出顯示它會使用目前作業系統使用者的 UI 語言設定來顯示正確的使用者訊息。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> # In TestScript.ps1 $UserMessages = DATA { ConvertFrom-StringData @' # English strings Msg1 = "Enter a name." Msg2 = "Enter your employee ID." Msg3 = "Enter your building number." '@ } Import-LocalizedData -bindingVariable UserMessages $UserMessages.Msg1 ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用 Import-LocalizedData 取代指令碼的 DATA 區段中所定義的預設文字字串。 在此範例中,TestScript.ps1 指令碼的 DATA 區段包含 ConvertFrom-StringData 命令,此命令會將 DATA 區段的內容轉換成雜湊表,並儲存在 $UserMessages 變數的值中。 此指令碼也包含 Import-LocalizedData 命令,此命令會從 $PsUICulture 變數值所指定之子目錄中的 TestScript.psd1 檔案匯入翻譯文字字串的雜湊表。如果此命令找到 .psd1 檔案,它會將檔案中的翻譯字串儲存到同一個 $UserMessages 變數的值中,覆寫 DATA 區段邏輯所儲存的雜湊表。 第三個命令會顯示 $UserMessages 變數中的第一個訊息。 如果 Import-LocalizedData 命令找到 $PsUICulture 語言的 .psd1 檔案,$UserMessages 變數的值就會包含翻譯文字字串。若因任何原因而使得命令失敗,此命令會顯示指令碼的 DATA 區段中所定義的預設文字字串。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> # In Day1.ps1 Import-LocalizedData -bindingVariable Day Day.MessageDate # In Day2.ps1 Import-LocalizedData -bindingVariable Day -errorAction:silentlycontinue Day.MessageDate C:\PS> .\Day1.ps1 Import-LocalizedData : Cannot find PowerShell data file 'Day1.psd1' in directory 'C:\ps-test\fr-BE\' or any parent culture directories. At C:\ps-test\Day1.ps1:17 char:21 + Import-LocalizedData <<<< Day Today is Tuesday C:\PS> .\Day2.ps1 Today is Tuesday </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何隱藏 Import-LocalizedData 找不到與使用者 UI 文化特性對應的目錄或在那些目錄中找不到指令碼的 .psd1 檔案時所顯示的錯誤訊息。 您可以使用值為 "SilentlyContinue" 的一般 ErrorAction 參數,隱藏錯誤訊息。當您已經以預設或「遞補」語言提供使用者訊息,而且不需要任何錯誤訊息時,這種做法特別有用。 這個範例比較兩個都包含 Import-LocalizedData 命令的指令碼:Day1.ps1 與 Day2.ps1。Day2 使用值為 SilentlyContinue 的一般 ErrorAction 參數,除這點以外兩個指令碼完全相同。 當 UI 文化特性設為 fr-BE,而且沒有與該 UI 文化特性對應的檔案或目錄時,範例輸出會顯示執行這兩個指令碼的結果。Day1.ps1 顯示錯誤訊息和英文輸出。Day2.ps1 只顯示英文輸出。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113342</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Script_Internationalization</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Import-PSSession </command:name> <maml:description> <maml:para>將另一個工作階段的命令匯入目前的工作階段。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Import</command:verb> <command:noun>PSSession</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Import-PSSession Cmdlet 會從本機或遠端電腦上的 PSSession 將 Cmdlet、函數和別名等命令匯入目前的工作階段。您可以匯入 Get-Command 能在 PSSession 中找到的任何命令。 Import-PSSession 命令可用來從自訂殼層 (如 Microsoft Exchange Server 殼層) 或是從工作階段來匯入命令,該工作階段包含了 Windows PowerShell 模組和嵌入式管理單元或者不在目前工作階段的其他元素。 若要匯入命令,請先使用 New-PSSession Cmdlet 建立 PSSession。然後,使用 Import-PSSession Cmdlet 匯入命令。根據預設,Import-PSSession 會匯入所有命令,但與目前工作階段中的命令同名的命令除外。若要匯入所有命令,請使用 AllowClobber 參數。 您可以像在工作階段中使用任何命令一樣使用匯入的命令。當您使用匯入的命令時,命令的匯入部分會以隱含方式在其匯入來源的工作階段中執行,而遠端操作則完全由 Windows PowerShell 處理。您甚至不需要知道這些遠端操作,但是必須讓與其他工作階段 (PSSession) 的連線保持在開啟狀態。如果關閉連線,匯入的命令就不能再使用。 因為匯入的命令可能要花比本機命令還要久的執行時間,Import-PSSession 會在每個匯入的命令中新增 AsJob 參數。此參數可讓您以 Windows PowerShell 背景工作的方式執行命令。如需詳細資訊,請參閱 about_Jobs。 當您使用 Import-PSSession 時,Windows PowerShell 會將匯入的命令加入至只存在於工作階段內的暫存模組,並傳回代表該模組的物件。若要建立您可以在未來工作階段使用的持續模組,請使用 Export-PSSession Cmdlet。 Import-PSSession Cmdlet 會使用 Windows PowerShell 的隱含遠端功能。當您將命令匯入目前的工作階段時,這些命令就會以隱含方式執行於原始工作階段,或是執行於原始電腦的類似工作階段。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Import-PSSession</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Session</maml:name> <maml:description> <maml:para>指定匯入 Cmdlet 的來源 PSSession。請輸入包含工作階段物件的變數或可取得工作階段物件的命令,例如 New-PSSession 或 Get-PSSession 命令。您只能指定一個工作階段。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSSession</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="3"> <maml:name>CommandName</maml:name> <maml:description> <maml:para>只匯入有指定的名稱或名稱模式的命令。允許使用萬用字元。請使用 "CommandName" 或其別名 "Name"。 根據預設,Import-PSSession 會從工作階段匯入所有命令,但與目前工作階段中的命令同名的命令則除外。這樣可防止匯入的命令隱藏或取代工作階段中的命令。若要匯入所有命令,即使是隱藏或取代其他命令的那些命令,請使用 AllowClobber 參數。 如果您使用 CommandName 參數,則除非您使用 FormatTypeName 參數,否則不會匯入命令的格式化檔案。同樣地,如果您使用 FormatTypeName 參數,則除非您使用 CommandName 參數,否則不會匯入命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="4"> <maml:name>FormatTypeName</maml:name> <maml:description> <maml:para>匯入指定之 Microsoft .NET Framework 型別的格式化指示。請輸入型別名稱。允許使用萬用字元。 這個參數的值必須是匯入命令之來源工作階段中的 Get-FormatData 命令所傳回的型別名稱。若要取得遠端工作階段中的所有格式化資料,請輸入 *。 如果此命令不包含 CommandName 或 FormatTypeName 參數,Import-PSSession 會匯入遠端工作階段中 Get-FormatData 命令所傳回之所有 .NET Framework 型別的格式化指示。 如果您使用 FormatTypeName 參數,則除非您使用 CommandName 參數,否則不會匯入命令。 同樣地,如果您使用 CommandName 參數,則除非您使用 FormatTypeName 參數,否則不會匯入命令的格式化檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AllowClobber</maml:name> <maml:description> <maml:para>匯入指定的命令,即使這些命令與目前工作階段中的命令同名亦然。 如果您匯入與目前工作階段中的命令同名的命令,則匯入的命令會隱藏或取代原始命令。如需詳細資訊,請參閱 about_Command_Precedence。 根據預設,Import-PSSession 不會匯入與目前工作階段中的命令同名的命令。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>ArgumentList</maml:name> <maml:description> <maml:para>匯入因使用指定的引數 (參數值) 所產生的命令變化。 例如,若要從 $s 的 PSSession 匯入憑證 (Cert:) 磁碟機中 Get-Item 命令的變化,請輸入 "import-pssession -session $s -command get-item -argumentlist cert:".</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CommandType</maml:name> <maml:description> <maml:para>只匯入指定類型的命令物件。預設值為 Cmdlet。請使用 "CommandType" 或其別名 "Type"。 有效的值包括: -- Alias:遠端工作階段中的 Windows PowerShell 別名。 -- All:遠端工作階段中的 Cmdlet 和函數。 -- Application:Path 環境變數 ($env:path) 所列出之路徑中所有非 Windows PowerShell 的檔案,包括 .txt、.exe 和 .dll 檔案。 -- Cmdlet:遠端工作階段中的 Cmdlet。預設為 "Cmdlet"。 -- ExternalScript:遠端工作階段中 Path 環境變數 ($env:path) 所列出之路徑中的 .ps1 檔案。 -- Filter 和 Function:遠端工作階段中的 Windows PowerShell 函數。 -- Script:遠端工作階段中的指令碼區塊。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Alias</command:parameterValue> <command:parameterValue required="false" variableLength="false">Function</command:parameterValue> <command:parameterValue required="false" variableLength="false">Filter</command:parameterValue> <command:parameterValue required="false" variableLength="false">Cmdlet</command:parameterValue> <command:parameterValue required="false" variableLength="false">ExternalScript</command:parameterValue> <command:parameterValue required="false" variableLength="false">Application</command:parameterValue> <command:parameterValue required="false" variableLength="false">Script</command:parameterValue> <command:parameterValue required="false" variableLength="false">All</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Module</maml:name> <maml:description> <maml:para>只匯入指定的 Windows PowerShell 嵌入式管理單元和模組中的命令。請輸入嵌入式管理單元和模組的名稱。不允許使用萬用字元。 如需詳細資訊,請參閱 about_PSSnapins 和 Import-Module。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Prefix</maml:name> <maml:description> <maml:para>將指定的首碼加入至已匯入之命令名稱中的名詞。 請使用此參數避免名稱衝突,當工作階段中不同命令具有相同名稱時,便可能發生此衝突。 例如,如果您指定首碼 "Remote",然後匯入 Get-Date Cmdlet,工作階段會將此 Cmdlet 識別為 Get-RemoteDate,以免與原始的 Get-Date Cmdlet 混淆。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AllowClobber</maml:name> <maml:description> <maml:para>匯入指定的命令,即使這些命令與目前工作階段中的命令同名亦然。 如果您匯入與目前工作階段中的命令同名的命令,則匯入的命令會隱藏或取代原始命令。如需詳細資訊,請參閱 about_Command_Precedence。 根據預設,Import-PSSession 不會匯入與目前工作階段中的命令同名的命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>ArgumentList</maml:name> <maml:description> <maml:para>匯入因使用指定的引數 (參數值) 所產生的命令變化。 例如,若要從 $s 的 PSSession 匯入憑證 (Cert:) 磁碟機中 Get-Item 命令的變化,請輸入 "import-pssession -session $s -command get-item -argumentlist cert:".</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>工作階段中的所有命令,但是與目前工作階段中之命令具有相同名稱的命令除外。</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="3"> <maml:name>CommandName</maml:name> <maml:description> <maml:para>只匯入有指定的名稱或名稱模式的命令。允許使用萬用字元。請使用 "CommandName" 或其別名 "Name"。 根據預設,Import-PSSession 會從工作階段匯入所有命令,但與目前工作階段中的命令同名的命令則除外。這樣可防止匯入的命令隱藏或取代工作階段中的命令。若要匯入所有命令,即使是隱藏或取代其他命令的那些命令,請使用 AllowClobber 參數。 如果您使用 CommandName 參數,則除非您使用 FormatTypeName 參數,否則不會匯入命令的格式化檔案。同樣地,如果您使用 FormatTypeName 參數,則除非您使用 CommandName 參數,否則不會匯入命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>工作階段中的所有命令,但是與目前工作階段中之命令具有相同名稱的命令除外。</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CommandType</maml:name> <maml:description> <maml:para>只匯入指定類型的命令物件。預設值為 Cmdlet。請使用 "CommandType" 或其別名 "Type"。 有效的值包括: -- Alias:遠端工作階段中的 Windows PowerShell 別名。 -- All:遠端工作階段中的 Cmdlet 和函數。 -- Application:Path 環境變數 ($env:path) 所列出之路徑中所有非 Windows PowerShell 的檔案,包括 .txt、.exe 和 .dll 檔案。 -- Cmdlet:遠端工作階段中的 Cmdlet。預設為 "Cmdlet"。 -- ExternalScript:遠端工作階段中 Path 環境變數 ($env:path) 所列出之路徑中的 .ps1 檔案。 -- Filter 和 Function:遠端工作階段中的 Windows PowerShell 函數。 -- Script:遠端工作階段中的指令碼區塊。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">CommandTypes</command:parameterValue> <dev:type> <maml:name>CommandTypes</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>工作階段中的所有命令,但是與目前工作階段中之命令具有相同名稱的命令除外。</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="4"> <maml:name>FormatTypeName</maml:name> <maml:description> <maml:para>匯入指定之 Microsoft .NET Framework 型別的格式化指示。請輸入型別名稱。允許使用萬用字元。 這個參數的值必須是匯入命令之來源工作階段中的 Get-FormatData 命令所傳回的型別名稱。若要取得遠端工作階段中的所有格式化資料,請輸入 *。 如果此命令不包含 CommandName 或 FormatTypeName 參數,Import-PSSession 會匯入遠端工作階段中 Get-FormatData 命令所傳回之所有 .NET Framework 型別的格式化指示。 如果您使用 FormatTypeName 參數,則除非您使用 CommandName 參數,否則不會匯入命令。 同樣地,如果您使用 CommandName 參數,則除非您使用 FormatTypeName 參數,否則不會匯入命令的格式化檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>System.Management.Automation 命名空間中的型別</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Module</maml:name> <maml:description> <maml:para>只匯入指定的 Windows PowerShell 嵌入式管理單元和模組中的命令。請輸入嵌入式管理單元和模組的名稱。不允許使用萬用字元。 如需詳細資訊,請參閱 about_PSSnapins 和 Import-Module。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>工作階段中的所有命令,但是與目前工作階段中之命令具有相同名稱的命令除外。</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Prefix</maml:name> <maml:description> <maml:para>將指定的首碼加入至已匯入之命令名稱中的名詞。 請使用此參數避免名稱衝突,當工作階段中不同命令具有相同名稱時,便可能發生此衝突。 例如,如果您指定首碼 "Remote",然後匯入 Get-Date Cmdlet,工作階段會將此 Cmdlet 識別為 Get-RemoteDate,以免與原始的 Get-Date Cmdlet 混淆。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Session</maml:name> <maml:description> <maml:para>指定匯入 Cmdlet 的來源 PSSession。請輸入包含工作階段物件的變數或可取得工作階段物件的命令,例如 New-PSSession 或 Get-PSSession 命令。您只能指定一個工作階段。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSSession</command:parameterValue> <dev:type> <maml:name>PSSession</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將物件輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSModuleInfo</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Import-PSSession 會傳回 New-Module 和 Get-Module 傳回的相同模組物件。但是傳回的模組是暫存的,而且只存在於目前的工作階段中。若要在磁碟上建立永久的模組,請使用 Export-PSSession Cmdlet。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> Import-PSSession 依存於 Windows PowerShell 遠端基礎結構。若要使用此 Cmdlet,電腦必須有設定 WS-Management 遠端功能。如需詳細資訊,請參閱 about_Remote 和 about_Remote_Requirements。 您不能使用 Import-PSSession 匯入變數或 Windows PowerShell 提供者。 當您匯入的命令與目前工作階段的命令同名時,匯入的命令可以隱藏工作階段中的別名、函數和 Cmdlet,而且可以取代工作階段中的函數和變數。如需詳細資訊,請參閱 about_Command_Precedence。 Import-PSSession 會將所有命令轉換成函數,然後再加以匯入。因此,匯入之命令的行為會與它們保留其原始命令類型時的行為有些不同。例如,如果您從 PSSession 匯入 Cmdlet,然後從模組或嵌入式管理單元匯入同名的 Cmdlet,預設一定會執行從 PSSession 匯入的 Cmdlet,因為函數優先於 Cmdlet。相反地,如果您將別名匯入具有同名之別名的工作階段中,一定會使用原始別名,因為別名優先於函數。如需詳細資訊,請參閱 about_Command_Precedence。 Import-PSSession 會使用 Write-Progress Cmdlet 顯示命令的進度。您可能會在命令執行時看到進度列。 為了尋找要匯入的命令,Import-PSSession 會使用 Invoke-Command Cmdlet 在 PSSession 中執行 Get-Command 命令。為了取得命令的格式化資料,它會使用 Get-FormatData Cmdlet。當您執行 Import-PSSession 命令時,您可能會看到來自 Invoke-Command、Get-Command 和 Get-FormatData 的錯誤訊息。此外,Import-PSSession 無法從未包含 Get-Command、Get-FormatData、Select-Object 和 Get-Help Cmdlet 的 PSSession 中匯入命令。 匯入的命令與其他遠端命令都有相同限制,包括無法啟動有使用者介面的程式,例如 [記事本]。 因為 Windows PowerShell 設定檔無法在 PSSessions 中執行,設定檔新增到工作階段中的命令將不會提供給 Import-PSSession。若要從設定檔匯入命令,請在匯入命令之前使用 Invoke-Command 命令,以手動方式在 PSSession 中執行設定檔。 Import-PSSession 所建立的暫時性模組可能包含格式化檔案,即使此命令未匯入格式化資料亦然。如果此命令未匯入格式化資料,所有建立的格式化檔案都不會包含格式化資料。 若要使用 Import-PSSession,目前工作階段中的執行原則不得為 Restricted 或 AllSigned,因為 Import-PSSession 所建立的模組包含這些原則禁止使用的未經簽署指令碼檔案。若要使用 Import-PSSession 而不變更本機電腦的執行原則,請使用 Set-ExecutionPolicy 的 Scope 參數,針對單一處理序設定限制較少的執行原則。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $s = new-pssession -computername Server01 C:\PS> import-pssession -session $s </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從 Server01 電腦上的 PSSession 將所有命令匯入目前的工作階段,但與目前工作階段中的命令同名的命令則除外。 因為這個命令不使用 CommandName 參數,所以它也會匯入匯入的命令所需的所有格式化資料。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $s = new-pssession https://ps.testlabs.com/powershell C:\PS> import-pssession -session $s -commandname *-test -formatTypeName * C:\PS> new-test -name test1 C:\PS> get-test test1 | run-test </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會從 PSSession 將名稱結尾為 "-test" 的命令匯入本機工作階段,然後示範如何使用匯入的 Cmdlet。 第一個命令會使用 New-PSSession Cmdlet 建立 PSSession,並將這個 PSSession 儲存在 $s 變數中。 第二個命令會使用 Import-PSSession Cmdlet 從 $s 中的 PSSession 將命令匯入本機工作階段。它會使用 CommandName 參數指定具有 Test 名詞的命令,並使用 FormatTypeName 參數匯入 Test 命令的格式化資料。 第三個和第四個命令會使用目前工作階段中匯入的命令。因為匯入的命令實際上是新增到目前的工作階段,您可以使用本機語法加以執行,並不需要使用 Invoke-Command Cmdlet 執行匯入的命令。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $s1 = new-pssession -computername s1 C:\PS> $s2 = new-pssession -computername s2 C:\PS> import-pssession -session s1 -type cmdlet -name New-Test, Get-Test -FormatTypeName * C:\PS> import-pssession -session s2 -type cmdlet -name Set-Test -FormatTypeName * C:\PS> new-test Test1 | set-test -runtype full </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範您可以像使用本機 Cmdlet 一樣使用匯入的 Cmdlet。 這些命令會從 Server01 電腦上的 PSSession 匯入 New-Test 和 Get-Test Cmdlet,以及從 Server02 電腦上的 PSSession 匯入 Set-Test Cmdlet。 雖然這些 Cmdlet 是從不同 PSSession 匯入而得,但您仍可經由管道將物件從一個 Cmdlet 匯入至另一個 Cmdlet,而不會有錯誤產生。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $s = new-pssession -computername Server01 C:\PS> import-pssession -session $s -commandname *-test* -formattypename * C:\PS> $batch = new-test -name Batch -asjob C:\PS> receive-job $batch </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何以背景工作的方式執行匯入的命令。 因為匯入的命令可能要花比本機命令還要久的執行時間,Import-PSSession 會在每個匯入的命令中新增 AsJob 參數。AsJob 參數可讓您以背景工作的方式執行命令。 第一個命令會在 Server01 電腦上建立 PSSession,然後將 PSSession 物件儲存到 $s 變數。 第二個命令會使用 Import-PSSession 從 $s 中的 PSSession 將 Test Cmdlet 匯入目前工作階段。 第三個命令會使用匯入之 New-Test Cmdlet 的 AsJob 參數,以背景工作的方式執行 New-Test 命令,並將 New-Test 所傳回的工作物件儲存在 $batch 變數中。 第四個命令會使用 Receive-Job Cmdlet 取得 $batch 變數中的工作結果。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $s = new-pssession -comp Server01 C:\PS> invoke-command -session $s {import-module TestManagement} C:\PS> import-pssession -session $s -module TestManagement </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何從遠端電腦上的 Windows PowerShell 模組將 Cmdlet 和函數匯入目前的工作階段。 第一個命令會在 Server01 電腦上建立 PSSession,然後將其儲存到 $s 變數。 第二個命令會使用 Invoke-Command Cmdlet 在 $s 的 PSSession 中執行 Import-Module 命令。 一般來說,Windows PowerShell 設定檔內的 Import-Module 命令會將模組加入至所有工作階段,但設定檔無法在 PSSessions 中執行。 第三個命令會使用 Import-PSSession 的 Module 參數將模組中的 Cmdlet 和函數匯入目前的工作階段。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> import-pssession $s -CommandName Get-Date, SearchHelp -formatTypeName * -AllowClobber Name : tmp_79468106-4e1d-4d90-af97-1154f9317239_tcw1zunz.ttf Path : C:\Users\User01\AppData\Local\Temp\tmp_79468106-4e1d-4d90-af97-1154f9317239_tcw1zunz.ttf\tmp_79468106-4e1d-4d90-af97-1154f9317239_ tcw1zunz.ttf.psm1 Description : Implicit remoting for http://server01.corp.fabrikam.com/wsman Guid : 79468106-4e1d-4d90-af97-1154f9317239 Version : 1.0 ModuleBase : C:\Users\User01\AppData\Local\Temp\tmp_79468106-4e1d-4d90-af97-1154f9317239_tcw1zunz.ttf ModuleType : Script PrivateData : {ImplicitRemoting} AccessMode : ReadWrite ExportedAliases : {} ExportedCmdlets : {} ExportedFunctions : {[Get-Date, Get-Date], [SearchHelp, SearchHelp]} ExportedVariables : {} NestedModules : {} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範 Import-PSSession 在磁碟上的暫存檔中建立模組,也示範所有命令都會轉換成函數,然後再將其匯入目前工作階段。 此命令會使用 Import-PSSession Cmdlet 將 Get-Date Cmdlet 和 SearchHelp 函數匯入目前工作階段中。 Import-PSSession Cmdlet 會傳回代表暫時性模組的 PSModuleInfo 物件。Path 屬性值顯示 Import-PSSession 已經在暫存位置建立指令碼模組 (.psm1) 檔案。ExportedFunctions 屬性顯示 Get-Date Cmdlet 和 SearchHelp 函數兩者都當做函數匯入。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> import-pssession $s -CommandName Get-Date -formatTypeName * -AllowClobber C:\PS> get-command get-date CommandType Name Definition ----------- ---- ---------- Function Get-Date ... Cmdlet Get-Date Get-Date [[-Date] <DateTime>] [-Year <Int32>] [-Month <Int32>] C:\PS> Get-Date 09074 C:\PS> (get-command -type cmdlet -name get-date).pssnapin.name Microsoft.PowerShell.Utility C:\PS> Microsoft.PowerShell.Utility\get-date Sunday, March 15, 2009 2:08:26 PM </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會示範如何執行匯入之命令所隱藏的命令。 第一個命令會從 $s 變數中的 PSSession 匯入 Get-Date Cmdlet。因為目前工作階段包含 Get-Date Cmdlet,所以此命令中需要 AllowClobber 參數。 第二個命令會使用 Get-Command Cmdlet 取得目前工作階段中的 Get-Date 命令。輸出顯示此工作階段包含原始 Get-Date Cmdlet 和 Get-Date 函數。Get-Date 函數會在 $s 的 PSSession 中執行匯入的 Get-Date Cmdlet。 第三個命令會執行 Get-Date 命令。因為函數優先於 Cmdlet,所以 Windows PowerShell 會執行匯入的 Get-Date 函數,此函數會傳回凱撒日 (Julian Date)。 第四和第五個命令會示範如何使用合格的名稱來執行匯入的命令所隱藏的命令。 第四個命令會取得將原始 Get-Date Cmdlet 加入至目前工作階段的 Windows PowerShell 嵌入式管理單元名稱。 第五個命令會使用 Get-Date Cmdlet 的嵌入式管理單元限定名稱來執行 Get-Date 命令。 如需命令優先順序和隱藏命令的詳細資訊,請參閱 about_Command_Precedence。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 8 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> import-pssession -session $s -commandName *Item* -AllowClobber </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從 $s 的 PSSession 匯入名稱包含 "Item" 的命令。因為此命令包含 CommandName 參數,而不包含 FormatTypeData 參數,所以只會匯入此命令。 當您在遠端電腦上使用 Import-PSSession 執行命令,而且您在目前工作階段中已經有此命令的格式化資料時,請使用這個命令。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 9 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $m = import-pssession -session $s -CommandName *bits* -formattypename *bits* C:\PS> get-command -module $m CommandType Name ----------- ---- Function Add-BitsFile Function Complete-BitsTransfer Function Get-BitsTransfer Function Remove-BitsTransfer Function Resume-BitsTransfer Function Set-BitsTransfer Function Start-BitsTransfer Function Suspend-BitsTransfer </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令示範如何使用 Get-Command 的 Module 參數來查明 Import-PSSession 命令將哪一個命令匯入工作階段。 第一個命令會使用 Import-PSSession Cmdlet,從 $s 變數中的 PSSession 匯入名稱包含 "bits" 的命令。Import-PSSession 命令會傳回暫時性模組,並將此模組儲存在 $m 變數中。 第二個命令會使用 Get-Command Cmdlet 取得 $m 變數中的模組所匯出的命令。 Module 參數會採用字串值,這個值是針對模組名稱所設計。但是,當您提交模組物件時,Windows PowerShell 會使用模組物件上的 ToString 方法,該物件會傳回模組名稱。 Get-Command 命令相當於 "get-command $m.name"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135221</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Command_Precedence</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-PSSession</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-PSSession</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Jobs</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_PSSessions</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Invoke-Expression </command:name> <maml:description> <maml:para>在本機電腦上執行命令或運算式。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Invoke</command:verb> <command:noun>Expression</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Invoke-Expression Cmdlet 會以命令的形式評估或執行指定的字串,並傳回命令或運算式的結果。缺少 Invoke-Expression,在命令列送出的字串會返回 (回應) 不變。 </maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Invoke-Expression</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Command</maml:name> <maml:description> <maml:para>指定要執行的命令或運算式。請輸入命令或運算式,或輸入包含命令或運算式的變數。Command 參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Command</maml:name> <maml:description> <maml:para>指定要執行的命令或運算式。請輸入命令或運算式,或輸入包含命令或運算式的變數。Command 參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String 或 PSObject </maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將代表命令的物件輸出至 Invoke-Expression。請使用 $input 自動變數表示命令中的輸入物件。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>PSObject </maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 傳回呼叫的命令 (Command 參數的值) 所產生的輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> -- 運算式是一種可被評估且產生結果的陳述式,例如 Windows PowerShell 命令。 -- 在指令碼中使用 Invoke-Expression Cmdlet 時,請採取合理的防範措施。使用 Invoke-Expression 執行使用者輸入的命令時,請在執行前確認可以放心執行命令。一般而言,最好是以預先定義的輸入選項設定指令碼,而不是允許任意輸入。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $command = "Get-Process" C:\PS> $command Get-Process C:\PS> invoke-expression $command Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 296 4 1572 1956 20 0.53 1348 AdtAgent 270 6 1328 800 34 0.06 2396 alg 67 2 620 484 20 0.22 716 ati2evxx 1060 15 12904 11840 74 11.48 892 CcmExec 1400 33 25280 37544 223 38.44 2564 communicator ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範 Invoke-Expression 的用法,評估運算式。缺少 Invoke-Expression,運算式會被印出但不被評估。 第一個命令會將 "Get-Process" (字串) 的值指派給 $command 變數。 第二個命令會顯示在命令列輸入變數名稱的效果。Windows PowerShell 會回應字串。 第三個命令會使用 Invoke-Expression 評估字串。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> invoke-expression -command "C:\ps-test\testscript.ps1" C:\PS> "C:\ps-test\testscript.ps1" | invoke-expression </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會使用 Invoke-Expression 在本機電腦上執行 TestScript.ps1 指令碼。這兩個命令功能相同。第一個命令會使用 Command 參數指定要執行的命令。第二個命令會使用管線運算子 (|) 將命令字串傳送給 Invoke-Expression。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $cmd = 'get-process | where {$_.cpu -gt 1000}' C:\PS> iex $command </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會執行 $cmd 變數中儲存的命令字串。 該命令字串因為包含代表目前物件的 $_ 變數而用單引號括住。如果用雙引號括住,$_ 變數在儲存到 $command 字串之前會被其值所取代。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $cmdlet_name = "get-eventlog" C:\PS> $example_number = 1 C:\PS> $example_code = (get-help $cmdlet_name).examples.example[($example_number-1)].code C:\PS> invoke-expression $example_code </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會擷取並執行 Get-EventLog Cmdlet 說明主題中的第一個範例。 若要執行不同 Cmdlet 的範例,請將 $cmdlet_name 變數的值變更為此 Cmdlet 的名稱。此外,請將 $example_number 變數變更成您想要執行的範例編號。如果範例編號無效,這個命令將會失敗。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113343</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Invoke-Command</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Measure-Command </command:name> <maml:description> <maml:para>測量執行指令碼區塊和 cmdlet 所需要的時間。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Measure</command:verb> <command:noun>Command</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Measure-Command Cmdlet 會在內部執行指令碼區塊或 Cmdlet、為作業的執行計時,然後傳回執行時間。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Measure-Command</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Expression</maml:name> <maml:description> <maml:para>指定所要計時的運算式。將運算式置於大括號 ({}) 內。參數名稱 ("Expression") 為選擇性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定代表要測量之運算式的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Expression</maml:name> <maml:description> <maml:para>指定所要計時的運算式。將運算式置於大括號 ({}) 內。參數名稱 ("Expression") 為選擇性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> <dev:type> <maml:name>scriptblock</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定代表要測量之運算式的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將物件輸出至 Measure-Command。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.TimeSpan</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Measure-Command 會傳回代表結果的時間範圍物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 如需詳細資訊,請輸入 "Get-Help Measure-Command -detailed"。如需技術資訊,請輸入 "Get-Help Measure-Command -full"。 若要為參數指定多重數值,請使用逗號來分隔數值。例如:"<參數名稱> <值1>, <值2>"。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> Measure-Command { get-eventlog "windows powershell" } </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>此命令會測量執行 "get-eventlog" 命令所花的時間,該命令會取得 Windows PowerShell 事件記錄檔中的事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> measure-command {get-childitem c:\windows -include *.txt -recurse} Days : 0 Hours : 0 Minutes : 0 Seconds : 8 Milliseconds : 618 Ticks : 86182763 TotalDays : 9.9748568287037E-05 TotalHours : 0.00239396563888889 TotalMinutes : 0.143637938333333 TotalSeconds : 8.6182763 TotalMilliseconds : 8618.2763 C:\PS>measure-command {get-childitem c:\windows -filter "*.txt" -recurse} Days : 0 Hours : 0 Minutes : 0 Seconds : 1 Milliseconds : 140 Ticks : 11409189 TotalDays : 1.32050798611111E-05 TotalHours : 0.000316921916666667 TotalMinutes : 0.019015315 TotalSeconds : 1.1409189 TotalMilliseconds : 1140.9189 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令顯示 Windows PowerShell 命令中使用的提供者特定篩選器的值。第一個命令會測量處理遞迴 Get-ChildItem 命令 (該命令使用 Include 參數) 所需要的時間。第二個命令會測量處理遞迴 Get-ChildItem 命令 (該命令使用提供者特定的 Filter 參數) 所需要的時間。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113348</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Trace-Command</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Invoke-Command</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Measure-Object </command:name> <maml:description> <maml:para>計算物件的數值屬性,以及字串物件 (如文字檔) 中的字元數、字數、和行數。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Measure</command:verb> <command:noun>Object</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Measure-Object Cmdlet 會計算物件之特定類型的屬性值,Measure-Object 會根據此命令中的參數來執行三種類型的測量。 Measure-Object Cmdlet 會對物件的屬性值執行計算。它不但能計算物件數,也能計算數值的最小值、最大值、總和值及平均值。對文字物件,它還能計算行數、字數和字元數。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Measure-Object</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Average</maml:name> <maml:description> <maml:para>顯示指定之屬性的平均值。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Maximum</maml:name> <maml:description> <maml:para>顯示指定之屬性的最大值。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Minimum</maml:name> <maml:description> <maml:para>顯示指定之屬性的最小值。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Sum</maml:name> <maml:description> <maml:para>顯示指定之屬性的總和值。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定一個或多個要測量的數值屬性。預設為物件的 Count (Length) 屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要測量的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Measure-Object</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Character</maml:name> <maml:description> <maml:para>計算輸入物件的字元數。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IgnoreWhiteSpace</maml:name> <maml:description> <maml:para>計算字數和字元數時忽略空格。預設情況下不會忽略空格。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Line</maml:name> <maml:description> <maml:para>計算輸入物件的行數。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Word</maml:name> <maml:description> <maml:para>計算輸入物件的字數。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定一個或多個要測量的數值屬性。預設為物件的 Count (Length) 屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要測量的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Average</maml:name> <maml:description> <maml:para>顯示指定之屬性的平均值。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Character</maml:name> <maml:description> <maml:para>計算輸入物件的字元數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>IgnoreWhiteSpace</maml:name> <maml:description> <maml:para>計算字數和字元數時忽略空格。預設情況下不會忽略空格。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要測量的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Line</maml:name> <maml:description> <maml:para>計算輸入物件的行數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Maximum</maml:name> <maml:description> <maml:para>顯示指定之屬性的最大值。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Minimum</maml:name> <maml:description> <maml:para>顯示指定之屬性的最小值。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定一個或多個要測量的數值屬性。預設為物件的 Count (Length) 屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Count</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Sum</maml:name> <maml:description> <maml:para>顯示指定之屬性的總和值。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Word</maml:name> <maml:description> <maml:para>計算輸入物件的字數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將物件輸出至 Measure-Object。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>GenericMeasureInfo 或 TextMeasureInfoObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | measure-object </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會計算目前目錄中的檔案數和資料夾數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | measure-object -property length -minimum -maximum -average </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示目前目錄中所有檔案大小的最小值、最大值、總和值及平均值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-content C:\test.txt | measure-object -character -line -word </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示 Text.txt 檔案中的字元、單字與行的數目。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | measure-object -property workingset -minimum -maximum -average </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示電腦上處理序的工作組大小的最小值、最大值及平均值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> import-csv d:\test\serviceyrs.csv | measure-object -property years -minimum -maximum -average </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會計算出公司員工的平均服務年資。 ServiceYrs.csv 檔案一個包含每個員工服務年資的 CSV 檔案。在表格中的第一列是 "EmpNo, Years" 標頭列。 當您使用 Import-Csv 匯入這個檔案時,結果會是 note 屬性為 EmpNo 和 Years 的 PSCustomObject。您可以使用 Measure-Object 計算這些屬性的值,就像物件的任何其他屬性一樣。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | measure-object -property psiscontainer -max -sum -min -average Count : 126 Average : 0.0634920634920635 Sum : 8 Maximum : 1 Minimum : 0 Property : PSIsContainer </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>此範例示範 Measure-Object 可以測量布林值。在此案例中,它會使用 PSIsContainer Boolean 屬性來測量目前目錄中資料夾的出現次數 (相對於檔案)。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113349</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Compare-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ForEach-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Group-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Select-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Sort-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Tee-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Where-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> New-Alias </command:name> <maml:description> <maml:para>建立新別名。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>New</command:verb> <command:noun>Alias</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>New-Alias Cmdlet 會在目前的 Windows PowerShell 工作階段中建立新的別名。使用 New-Alias 建立的別名不會在結束工作階段或關閉 Windows PowerShell 之後儲存。您可以使用 Export-Alias Cmdlet,將別名資訊儲存到檔案。稍後則可以使用 Import-Alias 來擷取這項儲存的別名資訊。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>New-Alias</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定新別名。別名可使用任意英數字元,但第一個字元不可以是數字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Value</maml:name> <maml:description> <maml:para>指定要建立別名的 cmdlet 或命令元素的名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Description</maml:name> <maml:description> <maml:para>指定別名的描述。可輸入任意字串。如果描述中包含空格,請將其置於引號內。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>如果設定此參數,其作用就像在別名名稱已存在的情況下執行 set-alias 一樣。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Option</maml:name> <maml:description> <maml:para>設定別名的一或多個選擇性屬性。有效的值包括: -- None:不設定選項。(預設值)。 -- ReadOnly:無法變更別名,除非使用 Force 參數。 -- Constant:無法變更別名,即便使用 Force 參數也一樣。 -- Private:別名僅可在 Scope 參數所指定的範圍內使用。在其餘所有範圍內,別名均為不可見。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">ReadOnly</command:parameterValue> <command:parameterValue required="false" variableLength="false">Constant</command:parameterValue> <command:parameterValue required="false" variableLength="false">Private</command:parameterValue> <command:parameterValue required="false" variableLength="false">AllScope</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表新別名的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定新別名的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Description</maml:name> <maml:description> <maml:para>指定別名的描述。可輸入任意字串。如果描述中包含空格,請將其置於引號內。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>如果設定此參數,其作用就像在別名名稱已存在的情況下執行 set-alias 一樣。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定新別名。別名可使用任意英數字元,但第一個字元不可以是數字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Option</maml:name> <maml:description> <maml:para>設定別名的一或多個選擇性屬性。有效的值包括: -- None:不設定選項。(預設值)。 -- ReadOnly:無法變更別名,除非使用 Force 參數。 -- Constant:無法變更別名,即便使用 Force 參數也一樣。 -- Private:別名僅可在 Scope 參數所指定的範圍內使用。在其餘所有範圍內,別名均為不可見。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">ScopedItemOptions</command:parameterValue> <dev:type> <maml:name>ScopedItemOptions</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表新別名的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定新別名的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Value</maml:name> <maml:description> <maml:para>指定要建立別名的 cmdlet 或命令元素的名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.AliasInfo</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 如果使用 Passthru 參數,New-Alias 會產生代表新別名的 System.Management.Automation.AliasInfo 物件,否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 若要建立新的別名,請使用 Set-Alias 或 New-Alias。若要變更別名,請使用 Set-Alias。若要刪除別名,請使用 Remove-Item。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> new-alias list get-childitem </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立名為 "list" 的別名來代表 Get-ChildItem Cmdlet。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> new-alias -name w -value get-wmiobject -description "quick wmi alias" -option ReadOnly C:\PS> get-alias -name w | format-list * </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立名為 "w" 的別名來代表 Get-WMIObject Cmdlet。它建立別名的描述 "quick wmi alias",並將其設定為唯讀。最後一行命令使用 Get-Alias 來取得新別名,並經由管道將它輸出至 Format-List 以顯示所有的相關資訊。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113352</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> New-Event </command:name> <maml:description> <maml:para>建立新的事件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>New</command:verb> <command:noun>Event</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>New-Event Cmdlet 會建立新的自訂事件。 您可以使用自訂事件,通知使用者有關您程式中的狀態變更,或是您程式能偵測到的任何變更,包括硬體或系統狀態、應用程式狀態、磁碟狀態、網路狀態或背景工作的完成。 當引發自訂事件時,自訂事件會自動新增到工作階段中的事件佇列,因此不需加以訂閱。不過,如果要將事件轉送給本機工作階段,或指定回應事件的動作,請使用 Register-EngineEvent Cmdlet 訂閱自訂事件。 訂閱自訂事件時,事件訂閱者會新增到工作階段。如果使用 Unregister-Event Cmdlet 取消訂閱,就會從工作階段刪除事件訂閱者和自訂事件。如果不訂閱自訂事件,而要刪除事件,則必須變更程式狀態或關閉 Windows PowerShell 工作階段。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>New-Event</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>指定新事件的名稱。此參數為必要項,而且在工作階段中必須是唯一的。 此參數的值會出現在事件的 SourceIdentifier 屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Sender</maml:name> <maml:description> <maml:para>指定引發事件的物件。預設為 Windows PowerShell 引擎。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="3"> <maml:name>EventArguments</maml:name> <maml:description> <maml:para>指定包含事件選項的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="4"> <maml:name>MessageData</maml:name> <maml:description> <maml:para>指定與事件關聯的其他資料。此參數的值會出現在事件物件的 MessageData 屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="3"> <maml:name>EventArguments</maml:name> <maml:description> <maml:para>指定包含事件選項的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> <dev:type> <maml:name>PSObject[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="4"> <maml:name>MessageData</maml:name> <maml:description> <maml:para>指定與事件關聯的其他資料。此參數的值會出現在事件物件的 MessageData 屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Sender</maml:name> <maml:description> <maml:para>指定引發事件的物件。預設為 Windows PowerShell 引擎。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>指定新事件的名稱。此參數為必要項,而且在工作階段中必須是唯一的。 此參數的值會出現在事件的 SourceIdentifier 屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSEventArgs</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 新的自訂事件、事件訂閱和事件佇列只存在於目前的工作階段中。如果關閉目前的工作階段,則會捨棄事件佇列並取消事件訂閱。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> new-event -sourceidentifier Timer -sender windows.timer -messagedata "Test" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在 Windows PowerShell 事件佇列中建立新的事件,然後使用 Windows.Timer 物件傳送該事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> function Enable-ProcessCreationEvent { $query = New-Object System.Management.WqlEventQuery "__InstanceCreationEvent", (New-Object TimeSpan 0,0,1), "TargetInstance isa 'Win32_Process'" $processWatcher = New-Object System.Management.ManagementEventWatcher $query $identifier = "WMI.ProcessCreated" Register-ObjectEvent $processWatcher "EventArrived" -SupportEvent $identifier -Action { [void] (New-Event -sourceID "PowerShell.ProcessCreated" -Sender $args[0] -EventArguments $args[1].SourceEventArgs.NewEvent.TargetInstance) } } </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例函數會使用 New-Event Cmdlet 引發一個事件來回應另一個事件。這個函數中的命令會使用 Register-ObjectEvent Cmdlet 訂閱當建立新處理序時引發的 Windows Management Instrumentation (WMI) 事件,並使用此 Cmdlet 的 Action 參數呼叫 New-Event Cmdlet,讓後者建立新的事件。 因為 New-Event 引發的事件會自動新增到 Windows PowerShell 事件佇列,因此不需加以註冊。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135234</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-ObjectEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-EngineEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-WmiEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Unregister-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Wait-Event</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> New-Object </command:name> <maml:description> <maml:para>建立 Microsoft .NET Framework 或 COM 物件的執行個體。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>New</command:verb> <command:noun>Object</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>New-Object Cmdlet 會建立 .NET Framework 或 COM 物件的執行個體。 您可以指定 .NET Framework 類別的型別或 COM 物件的 ProgID。根據預設,若輸入 .NET Framework 類別的完整名稱,此 Cmdlet 會傳回該類別執行個體的參考。若要建立 COM 物件的執行個體,請使用 ComObject 參數,並指定物件的 ProgID 當作其值。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>New-Object</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ComObject</maml:name> <maml:description> <maml:para>指定 COM 物件的程式設計識別碼 (ProgID)。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Strict</maml:name> <maml:description> <maml:para>指定一旦試圖建立的 COM 物件使用 Interop 組件時,應引發的錯誤。如此即可分辨實際的 COM 物件以及具有可呼叫 COM 包裝函式的 .NET Framework 物件。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Property</maml:name> <maml:description> <maml:para>設定屬性值,並呼叫新物件的方法。 請輸入一個符合下列條件的雜湊表:索引鍵是屬性或方法的名稱,而值是屬性值或方法引數。New-Object 會建立物件並設定每一個屬性值,然後依照方法出現在雜湊表的順序來呼叫每一個方法。 如果新的物件衍生自 PSObject 類別,而且您在此物件上指定不存在的屬性,New-Object 會將指定的屬性當做 NoteProperty 加入至此物件。如果此物件不是 PSObject,此命令會產生非終止錯誤。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">hashtable</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>New-Object</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>TypeName</maml:name> <maml:description> <maml:para>指定 .NET Framework 類別的完整名稱。不可同時指定 TypeName 參數和 ComObject 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="2"> <maml:name>ArgumentList</maml:name> <maml:description> <maml:para>指定要傳遞給 .NET Framework 類別之建構函式的引數清單。使用逗號 (,) 分隔清單中的元素。ArgumentList 的別名為 Args。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Property</maml:name> <maml:description> <maml:para>設定屬性值,並呼叫新物件的方法。 請輸入一個符合下列條件的雜湊表:索引鍵是屬性或方法的名稱,而值是屬性值或方法引數。New-Object 會建立物件並設定每一個屬性值,然後依照方法出現在雜湊表的順序來呼叫每一個方法。 如果新的物件衍生自 PSObject 類別,而且您在此物件上指定不存在的屬性,New-Object 會將指定的屬性當做 NoteProperty 加入至此物件。如果此物件不是 PSObject,此命令會產生非終止錯誤。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">hashtable</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="2"> <maml:name>ArgumentList</maml:name> <maml:description> <maml:para>指定要傳遞給 .NET Framework 類別之建構函式的引數清單。使用逗號 (,) 分隔清單中的元素。ArgumentList 的別名為 Args。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ComObject</maml:name> <maml:description> <maml:para>指定 COM 物件的程式設計識別碼 (ProgID)。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Property</maml:name> <maml:description> <maml:para>設定屬性值,並呼叫新物件的方法。 請輸入一個符合下列條件的雜湊表:索引鍵是屬性或方法的名稱,而值是屬性值或方法引數。New-Object 會建立物件並設定每一個屬性值,然後依照方法出現在雜湊表的順序來呼叫每一個方法。 如果新的物件衍生自 PSObject 類別,而且您在此物件上指定不存在的屬性,New-Object 會將指定的屬性當做 NoteProperty 加入至此物件。如果此物件不是 PSObject,此命令會產生非終止錯誤。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">hashtable</command:parameterValue> <dev:type> <maml:name>hashtable</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Strict</maml:name> <maml:description> <maml:para>指定一旦試圖建立的 COM 物件使用 Interop 組件時,應引發的錯誤。如此即可分辨實際的 COM 物件以及具有可呼叫 COM 包裝函式的 .NET Framework 物件。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>TypeName</maml:name> <maml:description> <maml:para>指定 .NET Framework 類別的完整名稱。不可同時指定 TypeName 參數和 ComObject 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> New-Object 會傳回建立的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> New-Object 會提供 VBScript CreateObject 函數的最常用功能。VBScript 中的陳述式如 Set objShell = CreateObject("Shell.Application"),可以在 Windows PowerShell 中轉譯為 $objShell = new-object -comobject "Shell.Application"。 New-Object 讓您能從命令列及指令碼中輕鬆使用 .NET Framework 物件,擴展在 Windows Script Host 環境下可使用的功能。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> new-object -typename System.Version -argumentlist "1.2.3.4" Major Minor Build Revision ----- ----- ----- -------- 1 2 3 4 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令使用字串 "1.2.3.4" 當做建構函式,以建立 System.Version 物件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $ie = new-object -comobject InternetExplorer.Application -property @{navigate2="www.microsoft.com"; visible = $true} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令建立代表 Internet Explorer 應用程式的 COM 物件執行個體。它會使用 Property 參數,以便呼叫 Navigate2 方法,並將物件的 Visible 屬性設為 $true,讓應用程式顯示出來。 此命令相當於以下命令: $ie = new-object -comobject InternetExplorer.Application $ie.navigate2("www.microsoft.com") $ie.visible = $true</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a=new-object -comobject Word.Application -strict -property @{visible=$true} New-Object : The object written to the pipeline is an instance of the type "Microsoft.Office.Interop.Word.ApplicationClass" from the component's prima ry interop assembly. If this type exposes different members than the IDispa tch members, scripts written to work with this object might not work if the primary interop assembly is not installed. At line:1 char:14 + $a=New-Object <<<< -COM Word.Application -Strict; $a.visible=$true </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令示範,指定 Strict 參數將會導致 New-Object Cmdlet 在建立的 COM 物件使用 Interop 組件時,產生非終止錯誤。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $objshell = new-object -comobject "Shell.Application" C:\PS> $objshell | get-member C:\PS> $objshell.ToggleDesktop() </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 ComObject 參數建立 ProgID 為 "Shell.Application" 的 COM 物件,然後將產生的物件儲存到 $objShell 變數。 第二個命令會經由管道將 $objShell 變數輸出至 Get-Member Cmdlet,讓後者顯示 COM 物件的屬性和方法。 第三個命令會呼叫該物件的 ToggleDesktop 方法,將您的桌面上開啟的視窗最小化。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113355</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Compare-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Select-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Sort-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ForEach-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Group-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Measure-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Tee-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Where-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> New-TimeSpan </command:name> <maml:description> <maml:para>建立 TimeSpan 物件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>New</command:verb> <command:noun>TimeSpan</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>New-TimeSpan Cmdlet 會建立一個代表時間的 TimeSpan 物件。您可以使用 TimeSpan 物件來加減 DateTime 物件中的時間。 當沒有參數時,"New-Timespan" 命令會傳回一個代表時間間隔為零的 timespan 物件。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>New-TimeSpan</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Start</maml:name> <maml:description> <maml:para>指出時間範圍的起始點。請輸入一個代表日期和時間的字串 (例如 "3/15/09"),或輸入 DateTime 物件 (例如 Get-Date 命令中的物件)。 預設為目前的日期和時間。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>End</maml:name> <maml:description> <maml:para>指出時間範圍的結束點。預設為目前的日期和時間。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>New-TimeSpan</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Days</maml:name> <maml:description> <maml:para>指出時間範圍涵蓋的天數。預設值為 0。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Hours</maml:name> <maml:description> <maml:para>指出時間範圍涵蓋的小時數。預設為零。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Minutes</maml:name> <maml:description> <maml:para>指出時間範圍涵蓋的分鐘數。預設值為 0。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Seconds</maml:name> <maml:description> <maml:para>指出時間範圍涵蓋的秒數。預設值為 0。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Days</maml:name> <maml:description> <maml:para>指出時間範圍涵蓋的天數。預設值為 0。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>0</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>End</maml:name> <maml:description> <maml:para>指出時間範圍的結束點。預設為目前的日期和時間。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue> <dev:type> <maml:name>DateTime</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>目前日期和時間</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Hours</maml:name> <maml:description> <maml:para>指出時間範圍涵蓋的小時數。預設為零。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>0</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Minutes</maml:name> <maml:description> <maml:para>指出時間範圍涵蓋的分鐘數。預設值為 0。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>0</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Seconds</maml:name> <maml:description> <maml:para>指出時間範圍涵蓋的秒數。預設值為 0。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>0</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Start</maml:name> <maml:description> <maml:para>指出時間範圍的起始點。請輸入一個代表日期和時間的字串 (例如 "3/15/09"),或輸入 DateTime 物件 (例如 Get-Date 命令中的物件)。 預設為目前的日期和時間。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue> <dev:type> <maml:name>DateTime</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>目前日期和時間</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.DateTime</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將代表開始時間的 DateTime 物件輸出至 New-TimeSpan。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Timespan</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> New-TimeSpan 會傳回代表時間範圍的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $timespan = new-timespan -hour 1 -minute 25 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立持續期間 1 小時又 25 分鐘的 TimeSpan 物件,並將它儲存在名為 $timespan 的變數中。它會顯示 TimeSpan 物件的表示法。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> new-timespan -end (get-date -year 2010 -month 1 -day 1) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會建立新的 TimeSpan 物件,此物件代表執行命令當時與 2010 年 1 月 1 日之間的間隔。 此命令不需要 Start 參數,因為 Start 參數的預設值是目前的日期和時間。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $90days = new-timespan -days 90 C:\PS> (get-date) + $90days </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會傳回目前日期過了 90 天之後的日期。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113360</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-Date</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Date</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> New-Variable </command:name> <maml:description> <maml:para>建立新變數。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>New</command:verb> <command:noun>Variable</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>New-Variable Cmdlet 會在 Windows PowerShell 中建立新的變數。您可以在建立時指派值給變數,也可以在建立之後才指派或變更值。 您可以使用 New-Variable 的參數設定變數的屬性 (例如建立唯讀或常數變數的屬性)、設定變數範圍,以及決定變數是公用還是私用。 一般來說,您會透過輸入變數名稱及其值,例如 "$var = 3",建立新的變數,不過可以利用 New-Variable Cmdlet 使用其參數。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>New-Variable</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定新變數的名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="2"> <maml:name>Value</maml:name> <maml:description> <maml:para>指定變數的初始值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Description</maml:name> <maml:description> <maml:para>指定變數的描述。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許建立與現有唯讀變數同名的新變數。 根據預設,除非變數的選項值為 ReadOnly 或 Constant,否則可以覆寫變數。如需詳細資訊,請參閱 Option 參數。 </maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Option</maml:name> <maml:description> <maml:para>設定新變數的 Options 屬性值。 有效的值包括: -- None:不設定選項。(預設值為 "None")。 -- ReadOnly:無法變更變數的值,除非使用 Force 參數。您可以使用 Remove-Variable 刪除變數。 -- Constant:無法刪除變數,且無法變更其屬性。只有建立別名時才能使用 "Constant"。您無法將現有變數的選項變更為 "Constant"。 -- Private:變數只在 Scope 參數所指定的範圍內有效。此範圍由子範圍繼承 (此值與 Visibility 參數的 "Private" 值無關)。 -- AllScope:將變數複製到所有新建立的範圍。 若要查看變數的 Options 屬性,請輸入 "get-variable| format-table -property name, options -autosize"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">ReadOnly</command:parameterValue> <command:parameterValue required="false" variableLength="false">Constant</command:parameterValue> <command:parameterValue required="false" variableLength="false">Private</command:parameterValue> <command:parameterValue required="false" variableLength="false">AllScope</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表新變數的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>決定新變數的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Visibility</maml:name> <maml:description> <maml:para>決定變數是否可在其建立所在的工作階段以外顯示。此參數是專為用在提供給其他使用者的指令碼和命令所設計。 有效的值包括: -- Public:看得到變數 (預設值為 "Public")。 -- Private:看不到變數。 變數為私用時,不會出現在變數的清單 (例如由 Get-Variable 傳回的清單),也不會在 Variable:磁碟機中顯示。對私用變數的值進行讀取或變更的命令會傳回錯誤。但是,如果使用私用變數的命令是在該變數定義所在的工作階段中撰寫的,使用者就可以執行這種命令。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Public</command:parameterValue> <command:parameterValue required="false" variableLength="false">Private</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Description</maml:name> <maml:description> <maml:para>指定變數的描述。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許建立與現有唯讀變數同名的新變數。 根據預設,除非變數的選項值為 ReadOnly 或 Constant,否則可以覆寫變數。如需詳細資訊,請參閱 Option 參數。 </maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定新變數的名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Option</maml:name> <maml:description> <maml:para>設定新變數的 Options 屬性值。 有效的值包括: -- None:不設定選項。(預設值為 "None")。 -- ReadOnly:無法變更變數的值,除非使用 Force 參數。您可以使用 Remove-Variable 刪除變數。 -- Constant:無法刪除變數,且無法變更其屬性。只有建立別名時才能使用 "Constant"。您無法將現有變數的選項變更為 "Constant"。 -- Private:變數只在 Scope 參數所指定的範圍內有效。此範圍由子範圍繼承 (此值與 Visibility 參數的 "Private" 值無關)。 -- AllScope:將變數複製到所有新建立的範圍。 若要查看變數的 Options 屬性,請輸入 "get-variable| format-table -property name, options -autosize"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">ScopedItemOptions</command:parameterValue> <dev:type> <maml:name>ScopedItemOptions</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表新變數的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>決定新變數的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="2"> <maml:name>Value</maml:name> <maml:description> <maml:para>指定變數的初始值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Visibility</maml:name> <maml:description> <maml:para>決定變數是否可在其建立所在的工作階段以外顯示。此參數是專為用在提供給其他使用者的指令碼和命令所設計。 有效的值包括: -- Public:看得到變數 (預設值為 "Public")。 -- Private:看不到變數。 變數為私用時,不會出現在變數的清單 (例如由 Get-Variable 傳回的清單),也不會在 Variable:磁碟機中顯示。對私用變數的值進行讀取或變更的命令會傳回錯誤。但是,如果使用私用變數的命令是在該變數定義所在的工作階段中撰寫的,使用者就可以執行這種命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">SessionStateEntryVisibility</command:parameterValue> <dev:type> <maml:name>SessionStateEntryVisibility</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Public</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Object</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可以經由管道將值輸出至 New-Variable。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.PSVariable</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 PassThru 參數時,New-Variable 會產生代表新變數的 System.Management.Automation.PSVariable 物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> new-variable days </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立名為 "days" 的新變數。緊接命令之後沒有任何值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> new-variable zipcode -value 98033 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立名為 "zipcode" 的變數,並指定其值為 "98033"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> new-variable -name max -value 256 -option readonly new-variable -name max -value 1024 new-variable -name max -value 1024 -force C:\PS> new-variable -name max -value 256 -option readonly C:\PS> new-variable -name max -value 1024 New-Variable : A variable with name 'max' already exists. At line:1 char:13 + new-variable <<<< -name max -value 1024 C:\PS> new-variable -name max -value 1024 -force </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用 New-Variable 的 ReadOnly 選項防止覆寫變數。 第一個命令會建立名為 Max 的新變數,並將它的值設定為 "256"。它會使用具有 ReadOnly 值的 Option 參數。 第二個命令會嘗試建立第二個同名變數。此命令會傳回錯誤,因為該變數上已設定唯讀選項。 第三個命令會使用 Force 參數覆寫該變數上的唯讀保護。在此例中,建立新的同名變數的命令會成功。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> new-variable -name counter -visibility private #Effect of private variable in a module. C:\PS> get-variable c* Name Value ---- ----- Culture en-US ConsoleFileName ConfirmPreference High CommandLineParameters {} C:\PS> $counter "Cannot access the variable '$counter' because it is a private variable" C:\PS> Get-Counter Name Value ---- ----- Counter1 3.1415 ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令示範私用變數在模組中的行為。這個模組包含 Get-Counter Cmdlet,其中有一個名為 "Counter" 的私用變數。這個命令會使用值為 "Private" 的 Visibility 參數來建立變數。 範例輸出會顯示私用變數的行為。已載入該模組的使用者無法檢視或變更 Counter 變數的值,但該模組中的命令卻可以讀取或變更 Counter 變數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113361</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Clear-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Out-Default </command:name> <maml:description> <maml:para>將輸出傳送給預設格式器及預設輸出 Cmdlet。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Out</command:verb> <command:noun>Default</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Out-Default Cmdlet 會將輸出傳送給預設格式器及預設輸出 Cmdlet。此 Cmdlet 不會影響 Windows PowerShell 命令的格式化或輸出。這是預留給您撰寫自己的 Out-Default 函數或 Cmdlet 之用。 </maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Out-Default</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para></maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name></maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name></maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113362</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Out-File </command:name> <maml:description> <maml:para>將輸出傳送到檔案。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Out</command:verb> <command:noun>File</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Out-File Cmdlet 會將輸出傳送到檔案。當您需要使用參數時,可以使用這個 cmdlet 來代替重新導向運算子 (>)。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Out-File</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>FilePath</maml:name> <maml:description> <maml:para>指定輸出檔的路徑。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定檔案所使用的字元編碼類型。有效值包括 "Unicode"、"UTF7"、"UTF8"、"UTF32"、"ASCII"、"BigEndianUnicode"、"Default" 和 "OEM"。預設值為 "Unicode"。 "Default" 使用系統目前的 ANSI 字碼頁編碼。 "OEM" 使用作業系統目前的原始設備製造商字碼頁識別元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Append</maml:name> <maml:description> <maml:para>將輸出附加至現有檔案結尾,而非取代檔案內容。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 覆寫現有的唯讀檔案。即便使用 Force 參數,此 Cmdlet 也無法覆寫安全性限制。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要寫入檔案的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>不覆寫 (取代) 現有檔案的內容。根據預設,如果檔案已在指定的路徑中,Out-File 會毫無預警地覆寫該檔案。若同時使用 Append 和 NoClobber,輸出會附加到現有的檔案。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Width</maml:name> <maml:description> <maml:para>指定輸出的每一行字元數。任何多餘的字元都會被截斷,而非自動換行。如果省略此參數,則由主機的特性決定寬度。Windows PowerShell 主控台的預設值為 80 個字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Append</maml:name> <maml:description> <maml:para>將輸出附加至現有檔案結尾,而非取代檔案內容。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定檔案所使用的字元編碼類型。有效值包括 "Unicode"、"UTF7"、"UTF8"、"UTF32"、"ASCII"、"BigEndianUnicode"、"Default" 和 "OEM"。預設值為 "Unicode"。 "Default" 使用系統目前的 ANSI 字碼頁編碼。 "OEM" 使用作業系統目前的原始設備製造商字碼頁識別元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>FilePath</maml:name> <maml:description> <maml:para>指定輸出檔的路徑。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 覆寫現有的唯讀檔案。即便使用 Force 參數,此 Cmdlet 也無法覆寫安全性限制。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要寫入檔案的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoClobber</maml:name> <maml:description> <maml:para>不覆寫 (取代) 現有檔案的內容。根據預設,如果檔案已在指定的路徑中,Out-File 會毫無預警地覆寫該檔案。若同時使用 Append 和 NoClobber,輸出會附加到現有的檔案。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Width</maml:name> <maml:description> <maml:para>指定輸出的每一行字元數。任何多餘的字元都會被截斷,而非自動換行。如果省略此參數,則由主機的特性決定寬度。Windows PowerShell 主控台的預設值為 80 個字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Out-File。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Out-File 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> Out cmdlet 不會將物件格式化,而是單僅轉譯物件再傳送到指定的顯示目的地。若將尚未格式化的物件傳送給 Out cmdlet,cmdlet 便會在轉譯前先將物件傳送給格式化 cmdlet。 Out cmdlet 沒有名稱參數或檔案路徑參數。若要傳送資料給包含 Out 動詞的 Cmdlet (Out Cmdlet),請使用管線運算子 (|) 將 Windows PowerShell 命令的輸出傳送給此 Cmdlet。您也可以將資料儲存至變數,再使用 InputObject 參數將資料傳遞給 cmdlet。如需說明,請參閱範例。 Out-File 會傳送資料,但是不會發出任何輸出物件。如果您經由管道將 Out-File 的輸出輸出至 Get-Member,Get-Member 就會報告尚未指定物件的狀況。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | out-file -filepath C:\Test1\process.txt </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將電腦中處理序的清單傳送給 Process.txt 檔案。如果檔案不存在,Out-File 會自行建立。因為 FilePath 參數的名稱為選擇性,您可以省略它,並提交相等的命令 "get-process | outfile C:\Test1\process.txt"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | out-file C:\Test1\process.txt -noclobber Out-File : File C:\Test1\process.txt already exists and NoClobber was specified. At line:1 char:23 + get-process | out-file <<<< process.txt -noclobber </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令也會將處理序的清單傳送給 Process.txt 檔案,但是使用了 NoClobber 參數,以避免現有的檔案遭到覆寫。此命令的輸出會顯示錯誤訊息,而此訊息即是在使用 NoClobber 時檔案已存在的情況下所出現的。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-process C:\PS> out-file -filepath C:\Test1\process.txt -inputobject $a -encoding ASCII -width 50 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令將電腦中處理序的清單傳送給 Process.txt 檔案。文字經過 ASCII 格式編碼,因此可由 Findstr 和 Grep 這類搜尋程式讀取。根據預設,Out-File 會使用 Unicode 格式。 第一個命令取得處理序的清單,再將它們儲存在 $a 變數中。第二個命令使用 Out-File Cmdlet,將清單傳送給 Process.txt 檔案。 此命令使用 InputObject 參數指定輸入位於 $a 變數中。它使用 Encoding 參數,將輸出轉換為 ASCII 格式。它使用 Width 參數,將檔案的每一行限制為 50 個字元。因為輸出的各行都會在到達 50 個字元時被截斷,所以會略掉處理序表格的最右欄。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-location hklm:\software c:\PS>get-acl mycompany\mykey | out-file -filepath c:\ps\acl.txt c:\PS>get-acl mycompany\mykey | out-file -filepath filesystem::acl.txt </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令顯示如何在 FileSystem 磁碟機以外的位置使用 Out-File Cmdlet。 第一個命令將目前位置設定為 HKLM:\Software 登錄機碼。 第二和第三個命令的作用相同。它們都是使用 Get-Acl Cmdlet 來取得 MyKey 登錄子機碼 (HKLM\Software\MyCompany\MyKey) 的安全性描述元。管線運算子會將結果傳遞給 Out-File Cmdlet,後者再將它傳送至 Acl.txt 檔案。 因為 Windows PowerShell 登錄提供者不支援 Out-File,所以您必須在 FilePath 參數值中指定檔案系統磁碟機名稱 (例如 "c:") 或是提供者名稱 (後面接著兩個冒號),例如 "FileSystem::"。第二和第三個命令示範了這些方法。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113363</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-String</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Null</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Printer</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Default</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Tee-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Out-GridView </command:name> <maml:description> <maml:para>將輸出傳送到單獨視窗中的互動式表格。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Out</command:verb> <command:noun>GridView</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Out-GridView Cmdlet 會將命令的輸出傳送到方格檢視視窗,並在當中的互動式表格中顯示輸出。此功能需要 Microsoft .NET Framework 3.5 Service Pack 1。 您可以使用下列的表格功能檢視資料: -- 隱藏、顯示及重新排序欄:若要隱藏、顯示或重新排序欄,請以滑鼠右鍵按一下欄標頭,然後按一下 [選取欄位]。 -- 排序:若要排序資料,請按一下欄標頭。再按一下即可從遞增順序切換到遞減順序。 -- 快速篩選:使用視窗頂端的 [篩選] 方塊來搜尋表格中的文字。您可以搜尋特定欄中的文字、搜尋常值和搜尋多個字。 -- 準則篩選:使用 [新增準則] 下拉式功能表建立規則,以篩選資料。這對非常大量的資料集 (如事件記錄檔) 非常有用。 -- 複製與貼上:若要從 Out-GridView 複製資料列,請按 CTRL+C (複製)。您可以將資料貼入任何文字或試算表程式。 如需使用這些功能的指示,請輸入 "get-help out-gridview -full",並查看注意事項一節中的<如何使用方格檢視視窗功能>。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Out-GridView</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>接受 Out-GridView 的輸入。 當您使用 InputObject 參數將物件的集合 (不只一個) 傳送給 Out-GridView 時,Out-GridView 會將此集合視為一個集合物件,並顯示一個代表此集合的資料列。若要顯示集合中的每一個物件,請使用管線運算子 (|) 將物件傳送給 Out-GridView。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Title</maml:name> <maml:description> <maml:para>指定出現在 Out-GridView 視窗標題列中的文字。 根據預設,標題列會顯示可呼叫 Out-GridView 的命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>接受 Out-GridView 的輸入。 當您使用 InputObject 參數將物件的集合 (不只一個) 傳送給 Out-GridView 時,Out-GridView 會將此集合視為一個集合物件,並顯示一個代表此集合的資料列。若要顯示集合中的每一個物件,請使用管線運算子 (|) 將物件傳送給 Out-GridView。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Title</maml:name> <maml:description> <maml:para>指定出現在 Out-GridView 視窗標題列中的文字。 根據預設,標題列會顯示可呼叫 Out-GridView 的命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>目前的命令</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可傳送任何物件給 Out-GridView。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Out-GridView 不會傳回任何物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> OUT-GRIDVIEW 的注意事項 ---------------------- 您可以從 Microsoft 下載中心下載 Microsoft .NET Framework 3.5 Service Pack 1。 因為此 Cmdlet 需要使用者介面,它無法在 Windows Server 的 Server Core 安裝上運作。 您不能使用遠端命令來開啟遠端電腦上的方格檢視視窗。 您所傳送的命令輸出無法透過像是 Format-Table 或 Format-Wide 這類的 Cmdlet 預先格式化。若要選取屬性,請使用 Select-Object Cmdlet。 遠端命令中還原序列化的輸出可能無法在方格檢視視窗中正確格式化。 OUT-GRIDVIEW 的鍵盤快速鍵 ----------------------------------- 使用下列鍵盤快速鍵即可快速執行許多工作。 按鍵: 執行動作: ------------- ---------------------------------------------------------------- TAB 將游標從 [篩選] 方塊移至 [新增準則] 功能表,再移至表格,然後往回移。 向上鍵 上移一列。將移至欄標頭。 向下鍵 下移一列。 向左鍵 在欄標頭列中左移一欄。 向右鍵 在欄標頭列中右移一欄。 內容功能表鍵 在欄標頭列中顯示 [選取欄位] 選項。 ENTER 或空格鍵 在欄標頭列中排序欄資料 (在遞增順序和遞減順序之間切換)。 如何使用方格檢視視窗功能 ---------------------------------------- 下列主題說明如何使用 Out-GridView 所顯示之視窗的功能。 如何隱藏、顯示及重新排序欄 -------------------------------------- 若要隱藏或顯示欄: 1. 以滑鼠右鍵按一下任何欄標頭,然後按一下 [選取欄位]。 2. 在 [選取欄位] 對話方塊中,使用方向鍵在 [選取的欄位] 與 [可用欄位] 方塊中間移動欄位。只有 [選取的欄位] 方塊中的欄才會出現在方格檢視視窗中。 若要重新排序欄: -- 將此欄拖放到想要的位置。 -或- 1. 以滑鼠右鍵按一下任何欄標頭,然後按一下 [選取欄位]。 2. 在 [選取欄位] 對話方塊中,使用 [上移] 和 [下移] 按鈕來重新排序欄位。位於清單最上方的欄位會出現在方格檢視視窗內清單底部的欄位左邊。 如何排序表格資料 ---------------------- -- 若要排序資料,請按一下欄標頭。 -- 若要變更排序順序,請再按一下欄標頭。每次按一下相同標頭時,排序順序就會在遞增與遞減順序之間切換。目前的排序順序是由欄標頭中的三角形所指示。 如何選取表格資料 ------------------------ -- 若要選取一列,請按一下該列,或使用向上鍵或向下鍵瀏覽到該列。 -- 若要選取所有列 (標頭列除外),請按 CTRL+A。 -- 若要選取連續的列,請按住 SHIFT 鍵,再按一下列或使用方向鍵。 -- 若要選取非連續的列,請按 CTRL 鍵,再按一下將列加入選取範圍。 您無法選取欄,也無法選取整個欄標頭列。 如何複製列 ---------------------- -- 若要從表格中複製一列或多列,請選取列再按 CTRL+C。 您可以將資料貼入任何文字或試算表程式。您無法複製欄或部分的列,也無法複製整個欄標頭列。 如何在表格中搜尋 (快速篩選) --------------------------------- 使用 [篩選] 方塊來搜尋表格中的資料。當您在此方塊中輸入時,只有包含輸入之文字的項目才會出現在表格中。 -- 搜尋文字:若要搜尋表格中的文字,請在 [篩選] 方塊中輸入要尋找的文字。 -- 搜尋多個字詞:若要搜尋表格中的多個字詞,請輸入多個字詞並用空格分隔每個字詞。Out-GridView 會顯示包含所有字詞的列 (邏輯 AND)。 -- 搜尋常值句子:若要搜尋包含空格或特殊字元的句子,請將句子置於引號內。Out-GridView 會顯示包含完全相符項目的列。 -- 搜尋欄:若要搜尋一欄或多欄中的文字,請使用下列格式: <column>:<text> [<column>:<text>] ... 例如,若要尋找 DisplayName 欄中的 "Net",請在 [篩選] 方塊中輸入: displayname:net 若要尋找 DisplayName 和 Name 欄中有 "Net" 的列,請在 [篩選] 方塊中輸入: displayname:net name:net -- 關閉搜尋:若要再次顯示整個表格,請按一下 [篩選] 方塊右上角的紅色 X 按鈕,或是刪除 [篩選] 方塊中的文字。 使用準則來篩選表格 -------------------------------- 您可以使用規則或「準則」來決定哪些項目可以顯示在表格中。只有當項目符合您所建立的所有準則時,才會顯示項目。可用的準則是由方格檢視視窗中顯示之物件的屬性以及這些屬性的 .NET Framework 型別所決定。 每一個準則的格式如下: <欄> <運算子> <值> 不同屬性的準則由 AND 連接。相同屬性的準則是以 OR 連接。您無法變更邏輯連接子。 此準則只會影響顯示。並不會從表格中刪除項目。 如何新增準則 --------------------------- 1. 若要顯示 [新增準則] 功能表按鈕,請在視窗的右上角按一下 [展開] 箭頭。 2. 按一下 [新增準則] 功能表按鈕。 3. 按一下以選取欄位 (屬性)。您可以選取一個或多個屬性。 4. 當您屬性選取完畢之後,請按一下 [新增] 按鈕。 5. 若要取消新增的部分,請按一下 [取消]。 6. 若要新增多個準則,請再按一下 [新增準則]。 如何編輯準則 -------------------- -- 若要變更運算子,請按一下藍色運算子值,然後從下拉式清單中 選取其他運算子。 -- 若要輸入或變更值,請在值方塊中輸入值。如果您輸入無效的值,將會出現圓形的 X 圖示。要移除它就必須變更值。 -- 若要建立 OR 陳述式,請新增具有相同屬性的準則。 如何刪除準則 ------------------------- -- 若要刪除選取的準則,請按一下每一個準則旁邊的紅色 X。 -- 若要刪除所有準則,請按一下 [全部清除] 按鈕。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | out-gridview </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得本機電腦上所執行的處理序,然後將這些處理序傳送到方格檢視視窗。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $p = get-process C:\PS> $p | out-gridview </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令也會取得本機電腦上所執行的處理序,然後將這些處理序傳送到方格檢視視窗。 第一個命令會使用 Get-Process 命令取得本機電腦上的處理序,然後將處理序物件儲存到 $p 變數。 第二個命令會使用管線運算子將 $p 變數傳送給 Out-GridView。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | select-object -property name, workingset, peakworkingset | sort-object -property workingset -desc | out-gridview </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在方格檢視視窗中顯示格式化的表格。 它會使用 Get-Process Cmdlet 取得電腦上的處理序。 然後,它會使用管線運算子 (|) 將處理序物件傳送給 Select-Object Cmdlet。這個命令會使用 Select-Object 的 Property 參數選取要在表格中顯示的 Name、WorkingSet 和 PeakWorkingSet 屬性。 另一個管線運算子會將篩選過的物件傳送給 Sort-Object Cmdlet,讓後者依據 WorkingSet 屬性的值以遞減順序進行排序。 這個命令的最後一個部分是使用管線運算子 (|) 將格式化的表格傳送給 Out-GridView。 現在您可以使用方格檢視的功能,對資料進行搜尋、排序和篩選。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> ($a = get-childitem -path $pshome -recurse) | out-gridview </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將其輸出儲存到變數,然後將它傳送給 Out-GridView。 該命令會使用 Get-ChildItem Cmdlet 取得 Windows PowerShell 安裝目錄及其子目錄中的檔案。安裝目錄的路徑儲存在 $pshome automatic 變數中。 該命令會使用指派運算子 (=) 將輸出儲存到 $a 變數,而且使用管線運算子 (|) 將輸出傳送給 Out-GridView。 命令中的括號是確定運算的順序。因此,Get-ChildItem 命令的輸出在傳送給 Out-GridView 之前會先儲存到 $a 變數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process -computername Server01| ogv -title "Processes - Server01" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在方格檢視視窗中顯示 Server01 電腦上執行的處理序。 該命令會使用 "ogv" (Out-GridView Cmdlet 的內建別名),而且它會使用 Title 參數指定視窗標題。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> invoke-command -ComputerName S1, S2, S3 -scriptblock {get-culture} | out-gridview </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會示範將從遠端電腦收集之資料傳送到 Out-GridView Cmdlet 的正確格式。 該命令會使用 Invoke-Command Cmdlet,在三部遠端電腦上執行 Get-Culture 命令。它會使用管線運算子,將傳回的資料傳送到 Out-GridView Cmdlet。 請注意,包含遠端執行之命令的指令碼區塊不包括 Out-GridView 命令。如果包括,當該命令嘗試在每一部遠端電腦上開啟方格檢視視窗時,命令就會失敗。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113364</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Out-Host </command:name> <maml:description> <maml:para>將輸出傳送到命令列。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Out</command:verb> <command:noun>Host</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Out-Host Cmdlet 會將輸出傳送到 Windows PowerShell 主機以供顯示。主機會在命令列中顯示輸出。因為 Out-Host 是預設值,所以除非您要使用其參數來變更顯示,否則不需要另外指定。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Out-Host</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要寫入主控台的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Paging</maml:name> <maml:description> <maml:para>一次顯示一頁輸出,並等待使用者輸入後再顯示其餘頁面,就像傳統的 "more" 命令。預設情況下,會以一頁顯示所有的輸出。頁面大小取決於主機的特性。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要寫入主控台的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Paging</maml:name> <maml:description> <maml:para>一次顯示一頁輸出,並等待使用者輸入後再顯示其餘頁面,就像傳統的 "more" 命令。預設情況下,會以一頁顯示所有的輸出。頁面大小取決於主機的特性。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Out-Host。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Out-Host 不會產生任何輸出。不過,主機可能會顯示 Out-Host 傳送給它的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以利用內建的別名 "oh" 來參照 Out-Host。如需詳細資訊,請參閱 about_Aliases。 包含 Out 動詞的 Cmdlet (Out Cmdlet) 不會將物件格式化,而是單僅轉譯物件再傳送到指定的顯示目的地。若將尚未格式化的物件傳送給 Out cmdlet,cmdlet 便會在轉譯前先將物件傳送給格式化 cmdlet。 Out cmdlet 沒有名稱參數或檔案路徑參數。若要傳送資料給 Out Cmdlet,請使用管線運算子 (|) 將 Windows PowerShell 命令的輸出傳送給 Cmdlet。您也可以將資料儲存至變數,再使用 InputObject 參數將資料傳遞給 cmdlet。如需說明,請參閱範例。 Out-Host 會傳送資料,但是不會發出任何輸出物件。如果您經由管道將 Out-Host 的輸出輸出至 Get-Member,Get-Member 就會報告尚未指定物件的狀況。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | out-host -paging </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令以一次一頁的方式顯示系統中的處理序。它會使用 Get-Process 命令來取得系統中的處理序。管線運算子 (|) 會將結果傳送到 Out-Host,後者再將它們顯示於主控台。Paging 參數會一次顯示一頁的資料。 Windows PowerShell 的內建 Help 函數也使用相同的命令格式。該函數會使用下列命令格式從 Get-Help 取得資料,然後使用 Out-Host 的 Paging 參數以一次一頁的方式顯示資料:get-help $args[0] | out-host -paging)。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-history C:\PS>out-host -InputObject $a </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會在命令列顯示工作階段歷程記錄。第一個命令使會用 Get-History Cmdlet 來取得工作階段歷程記錄,然後將歷程記錄儲存在 $a 變數中。第二個命令會使用 Out-Host 來顯示 $a 變數的內容,並使用 InputObject 參數,將此變數指定給 Out-Host。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113365</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Printer</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Null</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-File</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-String</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Default</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Host</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Out-Null </command:name> <maml:description> <maml:para>刪除輸出而不傳送到主控台。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Out</command:verb> <command:noun>Null</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Out-Null Cmdlet 會將輸出傳送到 NULL,實際上等於刪除它。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Out-Null</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要傳送至 Null 進行刪除的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要傳送至 Null 進行刪除的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Out-Null。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Out-Null 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 包含 Out 動詞的 Cmdlet (Out Cmdlet) 沒有代表名稱或檔案路徑的參數。若要傳送資料給 Out Cmdlet,請使用管線運算子 (|) 將 Windows PowerShell 命令的輸出傳送給 Cmdlet。您也可以將資料儲存至變數,再使用 InputObject 參數將資料傳遞給 cmdlet。如需詳細資訊,請參閱範例。 Out-Null 不會傳回任何輸出物件。如果您經由管道將 Out-Null 的輸出輸出至 Get-Member,Get-Member 就會報告尚未指定物件的狀況。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | out-null </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得本機目錄中的項目,但是接著就予以捨棄,而不會透過管線進行傳遞,或將其顯示在命令列。這在捨棄不需要的輸出時很有用。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113366</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Printer</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-File</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-String</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Default</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Out-Printer </command:name> <maml:description> <maml:para>將輸出傳送到印表機。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Out</command:verb> <command:noun>Printer</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Out-Printer Cmdlet 會將輸出傳送到預設印表機或備用印表機 (如果有指定)。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Out-Printer</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定備用印表機。參數名稱 ("Name") 為選擇項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要傳送至印表機的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要傳送至印表機的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定備用印表機。參數名稱 ("Name") 為選擇項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Out-Printer。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Out-Printer 不會傳回任何物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以利用內建的別名 "lp" 來參照 Out-Printer。如需詳細資訊,請參閱 about_Aliases。 包含 Out 動詞的 Cmdlet (Out Cmdlet) 不會將物件格式化,而是單僅轉譯物件再傳送到指定的顯示目的地。若將尚未格式化的物件傳送給 Out cmdlet,cmdlet 便會在轉譯前先將物件傳送給格式化 cmdlet。 Out cmdlet 沒有名稱參數或檔案路徑參數。若要傳送資料給 Out Cmdlet,請使用管線運算子 (|) 將 Windows PowerShell 命令的輸出傳送給 Cmdlet。您也可以將資料儲存至變數,再使用 InputObject 參數將資料傳遞給 cmdlet。如需詳細資訊,請參閱範例。 Out-Printer 會傳送資料,但是不會發出任何輸出物件。如果您經由管道將 Out-Printer 的輸出輸出至 Get-Member,Get-Member 就會報告尚未指定物件的狀況。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-content $pshome\about_signing.help.txt | Out-Printer </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將 about_Signing 說明主題的內容列印到預設印表機。這個範例告訴您如何列印檔案 (即使 Out-Printer 沒有 Path 參數)。 這個命令會使用 Get-Content Cmdlet 取得說明主題的內容。路徑包含 $pshome,這是儲存 Windows PowerShell 安裝目錄的內建變數。管線運算子 (|) 會將結果傳遞給 Out-Printer,後者再將它傳送至預設印表機。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> "Hello, World" | out-printer -name "\\Server01\Prt-6B Color" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將 "Hello, World" 列印到 Server01 上的 "Prt-6B Color" 印表機。這個命令使用 Name 參數來指定備用印表機。因為參數名稱為選擇性,您可以省略。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $h = get-help -full get-wmiobject C:\PS> out-printer -inputobject $h </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會列印 Get-WmiObject 說明主題的完整版本。第一個命令會使用 Get-Help Cmdlet 來取得 Get-WmiObject 說明主題的完整版本,並將它儲存在 $h 變數中。第二個命令將內容傳送到預設印表機。它會使用 InputObject 參數,將 $h 變數的值傳遞給 Out-Printer。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113367</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Null</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-String</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-File</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Default</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Out-String </command:name> <maml:description> <maml:para>以一系列的字串將物件傳送到主機。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Out</command:verb> <command:noun>String</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Out-String Cmdlet 會將 Windows PowerShell 所管理的物件轉換成字串陣列。根據預設,Out-String 會累積字串,並將它們當作單一字串傳回,但是您也可以使用 Stream 參數,指示 Out-String 一次傳回一個字串。當操作物件不方便時,這個 cmdlet 可讓您如同在傳統殼層一般搜尋並操作字串輸出。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Out-String</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要寫入字串的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Stream</maml:name> <maml:description> <maml:para>將每個物件的字串分開傳送。預設情況下,會將每個物件的字串累積,再以單一字串的形式傳送。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Width</maml:name> <maml:description> <maml:para>指定輸出的每一行字元數。任何多餘的字元都會被截斷,而非自動換行。如果省略此參數,則由主機的特性決定寬度。PowerShell.exe 主機預設為 80 個字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要寫入字串的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Stream</maml:name> <maml:description> <maml:para>將每個物件的字串分開傳送。預設情況下,會將每個物件的字串累積,再以單一字串的形式傳送。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Width</maml:name> <maml:description> <maml:para>指定輸出的每一行字元數。任何多餘的字元都會被截斷,而非自動換行。如果省略此參數,則由主機的特性決定寬度。PowerShell.exe 主機預設為 80 個字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將物件輸出至 Out-String。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Out-String 會傳回它根據輸入物件所建立的字串。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 包含 Out 動詞的 Cmdlet (Out Cmdlet) 不會將物件格式化,而是單僅轉譯物件再傳送到指定的顯示目的地。若將尚未格式化的物件傳送給 Out cmdlet,cmdlet 便會在轉譯前先將物件傳送給格式化 cmdlet。 Out cmdlet 沒有名稱參數或檔案路徑參數。若要傳送資料給 Out Cmdlet,請使用管線運算子 (|) 將 Windows PowerShell 命令的輸出傳送給 Cmdlet。您也可以將資料儲存至變數,再使用 InputObject 參數將資料傳遞給 cmdlet。如需詳細資訊,請參閱範例。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-content C:\test1\testfile2.txt | out-string </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將 Testfile2.txt 檔案的內容當作單一字串傳送到主控台。它會使用 Get-Content Cmdlet 來取得檔案的內容。管線運算子 (|) 會將內容傳送給 Out-String,後者再將內容當作字串傳送到主控台。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $c = get-culture | select-object * C:\PS> out-string -inputobject $c -width 100 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會取得目前使用者的地區設定,並將資料轉換為字串。第一個命令會使用 Get-Culture Cmdlet 來取得地區設定。管線運算子 (|) 會將結果傳送到 Select-Object Cmdlet,後者再選取 Get-Culture 所擷取之文化特性物件的所有屬性 (*)。此命令接著將結果儲存在 $c 變數中。 第二個會命令使用 Out-String,將 CultureInfo 物件轉換為一連串的字串 (每個屬性各一個字串)。它會使用 InputObject 參數將 $c 變數傳遞給 Out-String。寬度參數設定為每行 100 個字元以避免被截斷。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-alias | out-string -stream | select-string "Get-Command" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示包含片語 "Get-Command" 的別名。它會使用 Get-Alias Cmdlet 來取得一組 AliasInfo 物件 (目前工作階段中的每個別名各取一個物件)。這個範例會示範使用物件與使用字串之間的差異。 管線運算子 (|) 會將 Get-Alias 的輸出傳送到 Out-String,後者再將物件轉換為一連串的字串。它會使用 Stream 參數個別傳送每個字串,而不是將它們串連成單一字串。另一個管線運算子則將字串傳送到 Select-String,後者再選取內含 "Get-Command" 的字串。 如果您省略 Stream 參數,命令將會顯示所有的別名,因為 Select-String 會在 Out-String 傳回的單一字串中尋找 "Get-Command",而且格式器會以表格來顯示字串。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113368</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-File</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Null</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Printer</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Default</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Read-Host </command:name> <maml:description> <maml:para>從主控台讀取一行輸入。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Read</command:verb> <command:noun>Host</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Read-Host Cmdlet 會從主控台讀取一行輸入。您可以用它來提示使用者輸入。由於您可以將輸入另存成安全字串,因此可以使用此 Cmdlet 提示使用者輸入安全資料 (如密碼) 以及共用資料。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Read-Host</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Prompt</maml:name> <maml:description> <maml:para>指定提示的文字。請輸入字串。如果字串包含空格,請將其置於引號內。例如,輸入 "Type an integer: "。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AsSecureString</maml:name> <maml:description> <maml:para>顯示星號 (*) 以取代使用者在輸入時所輸入的字元。 使用此參數時,Read-Host Cmdlet 的輸出會是 SecureString 物件 (System.Security.SecureString)。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AsSecureString</maml:name> <maml:description> <maml:para>顯示星號 (*) 以取代使用者在輸入時所輸入的字元。 使用此參數時,Read-Host Cmdlet 的輸出會是 SecureString 物件 (System.Security.SecureString)。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Prompt</maml:name> <maml:description> <maml:para>指定提示的文字。請輸入字串。如果字串包含空格,請將其置於引號內。例如,輸入 "Type an integer: "。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.String 或 System.Security.SecureString</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 如果使用 AsSecureString 參數,Read-Host 會傳回 SecureString,否則會傳回字串。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $age = read-host "Please enter your age:" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示作為提示的 "Please enter your age:" 字串。輸入值後再按 ENTER 鍵時,該值會儲存到 $age 變數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $pwd_secure_string = read-host "Enter a Password:" -assecurestring </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示作為提示的 "Enter a Password:" 字串。在輸入值時,星號 (*) 會取代輸入出現在主控台上。按下 ENTER 鍵後,該值會另存成 SecureString 物件而儲存到 $pwd_secure_string 變數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113371</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertFrom-SecureString</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Register-EngineEvent </command:name> <maml:description> <maml:para>訂閱由 Windows PowerShell 引擎和 New-Event Cmdlet 所產生的事件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Register</command:verb> <command:noun>EngineEvent</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Register-EngineEvent Cmdlet 會訂閱由 Windows PowerShell 引擎和 New-Event Cmdlet 所產生的事件。請使用 SourceIdentifier 參數指定事件。 您可以使用此 Cmdlet 訂閱 New-Event Cmdlet 所產生的 "Exiting" 引擎事件。這些事件會自動新增到工作階段中的事件佇列,不需訂閱。但是訂閱能讓您轉送事件、指定要回應事件的動作,以及取消訂閱。 當引發訂閱的事件時,訂閱的事件會新增到工作階段中的事件佇列。若要取得事件佇列中的事件,請使用 Get-Event Cmdlet。 訂閱事件時,事件訂閱者會新增到工作階段。若要取得工作階段中的事件訂閱者,請使用 Get-EventSubscriber Cmdlet。若要取消訂閱,請使用 Unregister-Event Cmdlet,它會從工作階段刪除事件訂閱者。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Register-EngineEvent</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="101"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>指定所要訂閱之事件的來源識別元。來源識別元在目前工作階段中必須是唯一的。此參數為必要項。 此參數的值會出現在訂閱者物件以及所有與這個訂閱相關聯之事件物件的 SourceIdentifier 屬性值中。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="102"> <maml:name>Action</maml:name> <maml:description> <maml:para>指定要處理事件的命令。當引發事件時會執行 Action 中的命令,而非將事件傳送到事件佇列。請以大括號 ( { } ) 括住命令以建立指令碼區塊。 Action 參數的值可以包含 $Event、$EventSubscriber、$Sender、$SourceEventArgs 和 $SourceArgs 自動變數,這些自動變數為 Action 指令碼區塊提供事件的相關資訊。如需詳細資訊,請參閱 about_Automatic_Variables。 指定動作時,Register-EngineEvent 會傳回代表該動作的事件工件物件。您可以使用 Job Cmdlet 管理事件工作。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Forward</maml:name> <maml:description> <maml:para>將這個訂閱的事件傳送到本機電腦的工作階段。當您在遠端電腦上或透過遠端工作階段註冊事件時,請使用此參數。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>MessageData</maml:name> <maml:description> <maml:para>指定與事件關聯的其他資料。此參數的值會出現在事件物件的 MessageData 屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SupportEvent</maml:name> <maml:description> <maml:para>隱藏事件訂閱。當目前的訂閱屬於較複雜的事件註冊機制,而且不可單獨進行探索時,請使用此參數。 若要檢視或取消以 SupportEvent 參數建立的訂閱,請使用 Get-EventSubscriber 和 Unregister-Event Cmdlet 的 Force 參數。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="102"> <maml:name>Action</maml:name> <maml:description> <maml:para>指定要處理事件的命令。當引發事件時會執行 Action 中的命令,而非將事件傳送到事件佇列。請以大括號 ( { } ) 括住命令以建立指令碼區塊。 Action 參數的值可以包含 $Event、$EventSubscriber、$Sender、$SourceEventArgs 和 $SourceArgs 自動變數,這些自動變數為 Action 指令碼區塊提供事件的相關資訊。如需詳細資訊,請參閱 about_Automatic_Variables。 指定動作時,Register-EngineEvent 會傳回代表該動作的事件工件物件。您可以使用 Job Cmdlet 管理事件工作。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> <dev:type> <maml:name>scriptblock</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Forward</maml:name> <maml:description> <maml:para>將這個訂閱的事件傳送到本機電腦的工作階段。當您在遠端電腦上或透過遠端工作階段註冊事件時,請使用此參數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>MessageData</maml:name> <maml:description> <maml:para>指定與事件關聯的其他資料。此參數的值會出現在事件物件的 MessageData 屬性。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="101"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>指定所要訂閱之事件的來源識別元。來源識別元在目前工作階段中必須是唯一的。此參數為必要項。 此參數的值會出現在訂閱者物件以及所有與這個訂閱相關聯之事件物件的 SourceIdentifier 屬性值中。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SupportEvent</maml:name> <maml:description> <maml:para>隱藏事件訂閱。當目前的訂閱屬於較複雜的事件註冊機制,而且不可單獨進行探索時,請使用此參數。 若要檢視或取消以 SupportEvent 參數建立的訂閱,請使用 Get-EventSubscriber 和 Unregister-Event Cmdlet 的 Force 參數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至 Register-EngineEvent。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.PSEventJob</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 如果您使用 Action 參數,Register-EngineEvent 就會傳回 System.Management.Automation.PSEventJob 物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 事件、事件訂閱和事件佇列只存在於目前的工作階段中。如果關閉目前的工作階段,則會捨棄事件佇列並取消事件訂閱。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $s = new-pssession -computername Server01, Server02 C:\PS> invoke-command -session $s { Register-EngineEvent -sourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -forward } </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在兩台遠端電腦上註冊 Windows PowerShell 引擎事件。 第一個命令會在每一台遠端電腦上建立 PSSession。 第二個命令會使用 Invoke-Command Cmdlet 在遠端工作階段中執行 Register-EngineEvent 命令。 Register-EngineEvent 命令會使用 SourceIdentifier 參數指定事件,並使用 Forward 參數將事件從遠端工作階段轉送到本機工作階段。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $j = register-engineEvent -sourceIdentifier PowerShell.ProcessCreated -action { $processName | add-content processLog.txt } C:\PS> get-event C:\PS> $results = $j | receive-job C:\PS> unregister-event PowerShell.ProcessCreated </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令示範如何使用 Job Cmdlet 管理事件工作物件,而這個物件是在您使用 Action 參數時 Register-EngineEvent 所傳回的。 管理事件工作,如同任何其他 Windows PowerShell 工作一樣。如需詳細資訊,請參閱 about_jobs。在這個範例中,Receive-Job Cmdlet 是用來取得工作的結果。 若要從工作階段刪除工作,請使用 Remove-Job。若要取消事件訂閱,請使用 Unregister-Event Cmdlet。若要刪除事件佇列中的事件,請使用 Remove-Event。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135243</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-ObjectEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-WmiEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Unregister-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Wait-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Job</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Receive-Job</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Job</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Wait-Job</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Register-ObjectEvent </command:name> <maml:description> <maml:para>訂閱 Microsoft .NET Framework 物件所產生的事件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Register</command:verb> <command:noun>ObjectEvent</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Register-ObjectEvent Cmdlet 會在本機電腦或遠端電腦上訂閱 .NET Framework 物件所產生的事件。 當引發訂閱的事件時,訂閱的事件會新增到工作階段中的事件佇列。若要取得事件佇列中的事件,請使用 Get-Event Cmdlet。 您可以使用 Register-ObjectEvent 的參數指定事件的屬性值,以協助您識別佇列中的事件。也可以使用 Action 參數指定當引發訂閱的事件時所要採取的動作,並使用 Forward 參數將遠端事件傳送到本機工作階段中的事件佇列。 訂閱事件時,事件訂閱者會新增到工作階段。若要取得工作階段中的事件訂閱者,請使用 Get-EventSubscriber Cmdlet。若要取消訂閱,請使用 Unregister-Event Cmdlet,它會從工作階段刪除事件訂閱者。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Register-ObjectEvent</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定產生事件的 .NET Framework 物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>EventName</maml:name> <maml:description> <maml:para>指定所要訂閱的事件。請輸入事件名稱。此參數為必要項。 此參數的值不是您為事件訂閱所選取的名稱,而是 .NET Framework 物件所公開的事件名稱。例如,ManagementEventWatcher 類別有名稱為 "EventArrived" 和 "Stopped" 的事件。若要找出事件的事件名稱,請使用 Get-Member Cmdlet。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="101"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>指定您為訂閱所選取的名稱。您所選取的名稱在目前工作階段中必須是唯一的。預設值為 Windows PowerShell 指派的 GUID。 此參數的值會出現在用戶物件和所有與這個訂閱關聯之事件的 SourceIdentifier 屬性中。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="102"> <maml:name>Action</maml:name> <maml:description> <maml:para>指定要處理事件的命令。當引發事件時會執行 Action 中的命令,而非將事件傳送到事件佇列。請以大括號 ( { } ) 括住命令以建立指令碼區塊。 Action 參數的值可以包含 $Event、$EventSubscriber、$Sender、$SourceEventArgs 和 $SourceArgs 自動變數,這些自動變數為 Action 指令碼區塊提供事件的相關資訊。如需詳細資訊,請參閱 about_Automatic_Variables。 指定動作時,Register-ObjectEvent 會傳回代表該動作的事件工件物件。您可以使用 Job Cmdlet 管理事件工作。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Forward</maml:name> <maml:description> <maml:para>將這個訂閱的事件傳送到遠端工作階段。當您在遠端電腦上或透過遠端工作階段註冊事件時,請使用此參數。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>MessageData</maml:name> <maml:description> <maml:para>指定要與這個事件訂閱產生關聯的任何其他資料。此參數的值會出現在所有與這個訂閱關聯之事件的 MessageData 屬性中。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SupportEvent</maml:name> <maml:description> <maml:para>隱藏事件訂閱。當目前的訂閱屬於較複雜的事件註冊機制,而且不可單獨進行探索時,請使用此參數。 若要檢視或取消以 SupportEvent 參數建立的訂閱,請使用 Get-EventSubscriber 和 Unregister-Event Cmdlet 的 Force 參數。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="102"> <maml:name>Action</maml:name> <maml:description> <maml:para>指定要處理事件的命令。當引發事件時會執行 Action 中的命令,而非將事件傳送到事件佇列。請以大括號 ( { } ) 括住命令以建立指令碼區塊。 Action 參數的值可以包含 $Event、$EventSubscriber、$Sender、$SourceEventArgs 和 $SourceArgs 自動變數,這些自動變數為 Action 指令碼區塊提供事件的相關資訊。如需詳細資訊,請參閱 about_Automatic_Variables。 指定動作時,Register-ObjectEvent 會傳回代表該動作的事件工件物件。您可以使用 Job Cmdlet 管理事件工作。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> <dev:type> <maml:name>scriptblock</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無。</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>EventName</maml:name> <maml:description> <maml:para>指定所要訂閱的事件。請輸入事件名稱。此參數為必要項。 此參數的值不是您為事件訂閱所選取的名稱,而是 .NET Framework 物件所公開的事件名稱。例如,ManagementEventWatcher 類別有名稱為 "EventArrived" 和 "Stopped" 的事件。若要找出事件的事件名稱,請使用 Get-Member Cmdlet。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Forward</maml:name> <maml:description> <maml:para>將這個訂閱的事件傳送到遠端工作階段。當您在遠端電腦上或透過遠端工作階段註冊事件時,請使用此參數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定產生事件的 .NET Framework 物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>MessageData</maml:name> <maml:description> <maml:para>指定要與這個事件訂閱產生關聯的任何其他資料。此參數的值會出現在所有與這個訂閱關聯之事件的 MessageData 屬性中。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="101"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>指定您為訂閱所選取的名稱。您所選取的名稱在目前工作階段中必須是唯一的。預設值為 Windows PowerShell 指派的 GUID。 此參數的值會出現在用戶物件和所有與這個訂閱關聯之事件的 SourceIdentifier 屬性中。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>GUID</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SupportEvent</maml:name> <maml:description> <maml:para>隱藏事件訂閱。當目前的訂閱屬於較複雜的事件註冊機制,而且不可單獨進行探索時,請使用此參數。 若要檢視或取消以 SupportEvent 參數建立的訂閱,請使用 Get-EventSubscriber 和 Unregister-Event Cmdlet 的 Force 參數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將物件輸出至 Register-ObjectEvent。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 事件、事件訂閱和事件佇列只存在於目前的工作階段中。如果關閉目前的工作階段,則會捨棄事件佇列並取消事件訂閱。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $query = New-Object System.Management.WqlEventQuery "__InstanceCreationEvent", (New-Object TimeSpan 0,0,1), "TargetInstance isa 'Win32_Process'" C:\PS> $processWatcher = New-Object System.Management.ManagementEventWatcher $query C:\PS> register-objectEvent -inputObject $processWatcher -eventName "EventArrived" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會訂閱當新處理序啟動時產生的事件。 這個範例中的命令會使用 ManagementEventWatcher 物件取得 EventArrived 事件。查詢物件會指定事件是 Win32_Process 類別的執行個體建立事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $query = New-Object System.Management.WqlEventQuery "__InstanceCreationEvent", (New-Object TimeSpan 0,0,1), "TargetInstance isa 'Win32_Process'" C:\PS> $processWatcher = New-Object System.Management.ManagementEventWatcher $query C:\PS> $action = { New-Event "PowerShell.ProcessCreated" -Sender $sender -EventArguments $SourceEventArgs.NewEvent.TargetInstance } C:\PS> register-objectEvent -inputObject $processWatcher -eventName "EventArrived" -action $action Id Name State HasMoreData Location Command -- ---- ----- ----------- -------- ------- 2 422cfe5a-65e... Running True New-Event "PowerShe... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何指定要回應事件的動作。指定動作時,所引發的事件不會新增至事件佇列。不過,該動作會回應事件。 在這個範例中,引發執行個體建立事件,表示新的處理啟動而引發新的 ProcessCreated 事件。 該動作會使用僅針對事件動作填入的 $Sender 和 $SourceEventArgs 自動變數。 Register-ObjectEvent 命令會傳回代表動作的工作物件,它會以背景工作的方式執行。您可以使用 Job Cmdlet (例如 Get-Job 和 Receive-Job) 管理背景工作。 如需詳細資訊,請參閱 about_Jobs。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $s = new-pssession -computername Server01, Server02 C:\PS> invoke-command -session $s -filepath ProcessCreationEvent.ps1 C:\PS> invoke-command -session $s { get-event } # ProcessCreationEvent.ps1 function Enable-ProcessCreationEvent { $query = New-Object System.Management.WqlEventQuery "__InstanceCreationEvent", ` (New-Object TimeSpan 0,0,1), ` "TargetInstance isa 'Win32_Process'" $processWatcher = New-Object System.Management.ManagementEventWatcher $query $identifier = "WMI.ProcessCreated" Register-ObjectEvent -input $processWatcher -eventName "EventArrived" ` -sourceIdentifier $identifier -messageData "Test" -forward } } EnableProcessCreationEvent </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範在遠端電腦上訂閱物件事件。 第一個命令會在兩台遠端電腦上建立 PSSessions,然後將它們儲存到 $s 變數。 第二個命令會使用 Invoke-Command Cmdlet 的 FilePath 參數,在 $s 的每個 PSSession 內執行 ProcessCreationEvent.ps1 指令碼。 此指令碼內含的 Register-ObjectEvent 命令會透過 ManagementEventWatcher 物件及其 EventArrived 事件,訂閱 Win32_Process 物件上的執行個體建立事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $timer = New-Object Timers.Timer C:\PS> $timer.Interval = 500 C:\PS> $job = Register-ObjectEvent -inputObject $timer -eventName Elapsed -sourceIdentifier Timer.Random -Action {$random = Get-Random -Min 0 -Max 100} C:\PS> $job.gettype().fullname System.Management.Automation.PSEventJob C:\PS> $job | format-list -property * State : Running Module : __DynamicModule_6b5cbe82-d634-41d1-ae5e-ad7fe8d57fe0 StatusMessage : HasMoreData : True Location : Command : $random = Get-Random -Min 0 -Max 100 JobStateInfo : Running Finished : System.Threading.ManualResetEvent InstanceId : 88944290-133d-4b44-8752-f901bd8012e2 Id : 1 Name : Timer.Random ChildJobs : {} ... C:\PS> $timer.Enabled = $true C:\PS> & $job.module {$random} 60 C:\PS> & $job.module {$random} 47 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會示範如何將動態模組用於您在事件註冊中包含 Action 時所建立的 PSEventJob 物件中。 第一個命令會使用 New-Object Cmdlet 來建立計時器物件。第二個命令會將計時器的間隔設定為 500 (毫秒)。 第三個命令會使用 Register-ObjectEvent Cmdlet 來註冊計時器物件的 Elapsed 事件。該命令包含處理事件的動作。每當經過計時器間隔時,就會引發事件並且執行動作中的命令。在這個範例中,Get-Random Cmdlet 會產生介於 0 與 100 之間的亂數並將它儲存在 $random 變數中。 當您在 Register-ObjectEvent 命令中使用 Action 參數時,該命令就會傳回代表動作的 PSEventJob 物件,再將工作物件儲存在 $job 變數中。 Register-ObjectEvent Cmdlet 所傳回的 PSEventJob 物件也可以用於事件訂閱者的 Action 屬性中。如需詳細資訊,請參閱 Get-EventSubscriber。 第四個命令會顯示 $job 變數包含 PSEventJob 物件。第五個命令會使用 Format-List Cmdlet,以清單顯示 PSEventJob 物件的所有屬性。 PSEventJob 具有 Module 屬性,其中包含實作動作的動態指令碼模組。 第六個命令會啟用計時器。 其他命令則使用呼叫運算子 (&) 來叫用模組中的命令並且顯示 $random 變數的值。您可以使用呼叫運算子來叫用模組中的任何命令,包括尚未匯出的命令。在這個範例中,這些命令會顯示發生 Elapsed 事件時所產生的亂數。 如需模組的詳細資訊,請參閱 about_Modules。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135244</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-EngineEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-WmiEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Unregister-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Wait-Event</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Remove-Event </command:name> <maml:description> <maml:para>從事件佇列刪除事件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Remove</command:verb> <command:noun>Event</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Remove-Event Cmdlet 會從目前工作階段中的事件佇列刪除事件。 此 Cmdlet 只會刪除目前位於佇列中的事件。若要取消事件註冊或取消訂閱,請使用 Unregister-Event Cmdlet。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Remove-Event</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>EventIdentifier</maml:name> <maml:description> <maml:para>只刪除有指定的事件識別元的事件。每一個命令都需要有 EventIdentifier 或 SourceIdentifier 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Remove-Event</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>只刪除有指定的來源識別元的事件。不允許使用萬用字元。每一個命令都需要有 EventIdentifier 或 SourceIdentifier 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>EventIdentifier</maml:name> <maml:description> <maml:para>只刪除有指定的事件識別元的事件。每一個命令都需要有 EventIdentifier 或 SourceIdentifier 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>只刪除有指定的來源識別元的事件。不允許使用萬用字元。每一個命令都需要有 EventIdentifier 或 SourceIdentifier 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSEventArgs</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您也可經由管道將事件從 Get-Event 輸出至 Remove-Event。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 事件、事件訂閱和事件佇列只存在於目前的工作階段中。如果關閉目前的工作階段,則會捨棄事件佇列並取消事件訂閱。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> remove-event -sourceIdentifier "ProcessStarted" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從事件佇列刪除來源識別元為 "Process Started" 的事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> remove-event -eventIdentifier 30 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從事件佇列刪除事件識別碼為 30 的事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-event | remove-event </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從事件佇列刪除所有事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135247</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-ObjectEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-EngineEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-WmiEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Unregister-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Wait-Event</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Remove-PSBreakpoint </command:name> <maml:description> <maml:para>從目前主控台刪除中斷點。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Remove</command:verb> <command:noun>PSBreakpoint</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Remove-PSBreakpoint Cmdlet 會刪除中斷點。請輸入中斷點物件或中斷點識別碼。 移除中斷點後,中斷點物件不再可用或無效。如果已經將中斷點物件儲存在變數中,則參考仍存在,但中斷點無效。 Remove-PSBreakpoint 是其中幾個專為偵錯 Windows PowerShell 指令碼所設計的 Cmdlet。如需 Windows PowerShell 偵錯工具的詳細資訊,請參閱 about_Debuggers。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Remove-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Id</maml:name> <maml:description> <maml:para>刪除有指定的中斷點識別碼的中斷點。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Remove-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Breakpoint</maml:name> <maml:description> <maml:para>指定要刪除的中斷點。請輸入包含中斷點物件的變數或可取得中斷點物件的命令,例如 Get-PSBreakpoint 命令。您也可經由管道將中斷點物件輸出至 Remove-PSBreakpoint。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Breakpoint[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Breakpoint</maml:name> <maml:description> <maml:para>指定要刪除的中斷點。請輸入包含中斷點物件的變數或可取得中斷點物件的命令,例如 Get-PSBreakpoint 命令。您也可經由管道將中斷點物件輸出至 Remove-PSBreakpoint。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Breakpoint[]</command:parameterValue> <dev:type> <maml:name>Breakpoint[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Id</maml:name> <maml:description> <maml:para>刪除有指定的中斷點識別碼的中斷點。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> <dev:type> <maml:name>Int32[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.Breakpoint</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將中斷點物件輸出至 Remove-PSBreakpoint。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-breakpoint | remove-breakpoint </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會刪除目前主控台中的所有中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $b = set-psbreakpoint -script sample.ps1 -variable Name C:\PS> $b | remove-psbreakpoint </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會刪除中斷點。 第一個命令會使用 Set-PSBreakpoint Cmdlet 在 Sample.ps1 指令碼的 Name 變數上建立中斷點,然後將中斷點物件儲存到 $b 變數。 第二個命令會使用 Remove-PSBreakpoint Cmdlet 刪除新的中斷點,並使用管線運算子 (|) 將 $b 變數中的中斷點物件傳送給 Remove-PSBreakpoint Cmdlet。 因為這個命令,如果您執行指令碼,它會執行到完成而不停止。而且,Get-PSBreakpoint Cmdlet 也不會傳回這個中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> remove-psbreakpoint -id 2 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會刪除中斷點識別碼為 2 的中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> function del-psb { get-psbreakpoint | remove-psbreakpoint } </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個簡單函數會刪除目前主控台中的所有中斷點。它會使用 Get-PSBreakpoint Cmdlet 取得中斷點,然後使用管線運算子 (|) 將中斷點傳送給 Remove-PSBreakpoint Cmdlet,讓後者刪除中斷點。 因此,您可以輸入 "del-psb" 來代替較長的命令。 若要儲存這個函數,請將它新增到 Windows PowerShell 設定檔。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113375</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Debuggers</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Enable-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Disable-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSCallStack</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Remove-Variable </command:name> <maml:description> <maml:para>刪除變數及其值。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Remove</command:verb> <command:noun>Variable</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Remove-Variable Cmdlet 會從定義變數的範圍 (如目前的主控台) 刪除變數及其值。您無法使用這個 cmdlet 來刪除設定為常數或系統所擁有的變數。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Remove-Variable</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定要移除的變數的名稱。參數名稱 ("Name") 為選擇項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。此參數的值用於限定 Name 參數。輸入名稱元素或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 移除變數,即使它是唯讀的亦然。即便使用 Force 參數,此 Cmdlet 也無法移除常數。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>只刪除指定的項目。此參數的值用於限定 Name 參數。輸入名稱元素或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定此別名仍屬有效的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。此參數的值用於限定 Name 參數。輸入名稱元素或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 移除變數,即使它是唯讀的亦然。即便使用 Force 參數,此 Cmdlet 也無法移除常數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>只刪除指定的項目。此參數的值用於限定 Name 參數。輸入名稱元素或模式,例如 "s*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定要移除的變數的名稱。參數名稱 ("Name") 為選擇項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定此別名仍屬有效的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSVariable</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將變數物件輸出至 Remove-Variable。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 這個 Cmdlet 不會傳回任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 變更效果僅限目前的範圍,如工作階段。若要從所有工作階段刪除變數,請將 Remove-Variable 命令新增至 Windows PowerShell 設定檔。 您也可以利用內建的別名 "rv" 來參照 RemoveVariable。如需詳細資訊,請參閱 about_Aliases。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> remove-variable Smp </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會刪除 $Smp 變數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113380</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Clear-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Profiles</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Select-Object </command:name> <maml:description> <maml:para>選取單一物件或一組物件的指定屬性。它也可以從物件陣列選取未重複的物件,或從物件陣列的開頭或結尾選取指定個數的物件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Select</command:verb> <command:noun>Object</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Select-Object Cmdlet 只會取得一個物件或一組物件的指定屬性。它也可以從物件陣列選取未重複的物件,或從物件陣列的開頭或結尾選取指定個數的物件。 如果您使用 Select-Object 來選取指定的屬性,它就會從輸入物件複製那些屬性的值,並建立具有指定屬性與複製值的新物件。 請使用 Property 參數指定要選取的屬性,或是使用 First、Last、Unique、Skip 和 Index 參數從輸入物件的陣列選取特定物件。若要篩選出更明確的物件,請使用 Where-Object Cmdlet。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Select-Object</maml:name> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定要選取的屬性。允許使用萬用字元。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊></maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="named"> <maml:name>ExcludeProperty</maml:name> <maml:description> <maml:para>從選取範圍中移除指定的屬性。允許使用萬用字元。只有當命令也包含 Property 參數時,這個參數才有作用。 Property 參數的值可以是計算屬性,亦即指定名稱並針對屬性顯示計算值的雜湊表。有效的索引鍵包括: -- Name 或 Label <字串> -- Expression <字串> 或 <指令碼區塊> 如需詳細資訊,請參閱範例。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="true" pipelineInput="false" position="named"> <maml:name>ExpandProperty</maml:name> <maml:description> <maml:para>指定要選取的屬性,並表示應嘗試展開該屬性。允許在屬性名稱中使用萬用字元。 例如,若指定的屬性是陣列,在輸出中會包含該陣列的每個值。若屬性包含物件,在輸出中則會顯示該物件的屬性。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>First</maml:name> <maml:description> <maml:para>指定要從輸入物件陣列開頭選取的物件個數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要透過管線傳送給 Cmdlet 的物件。此參數可讓您經由管道將物件輸出至 Select-Object。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Last</maml:name> <maml:description> <maml:para>指定要從輸入物件陣列結尾選取的物件個數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Skip</maml:name> <maml:description> <maml:para>略過 (不選取) 指定的項目數。根據預設,Skip 參數會從陣列或物件清單的開頭開始計數,但如果命令使用 Last 參數,則會從清單或陣列的結尾開始計數。 不像 Index 參數是從 0 開始計數,Skip 參數是起始於 1。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Unique</maml:name> <maml:description> <maml:para>指定一旦輸入物件的子集具有相同的屬性和值,則僅選取單一子集成員。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Select-Object</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Index</maml:name> <maml:description> <maml:para>根據物件的索引值,從陣列選取物件。請以逗號分隔的清單輸入索引。 陣列中的索引以 0 為起始,其中 0 代表第一個值,(n-1) 代表最後一個值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要透過管線傳送給 Cmdlet 的物件。此參數可讓您經由管道將物件輸出至 Select-Object。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Unique</maml:name> <maml:description> <maml:para>指定一旦輸入物件的子集具有相同的屬性和值,則僅選取單一子集成員。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="named"> <maml:name>ExcludeProperty</maml:name> <maml:description> <maml:para>從選取範圍中移除指定的屬性。允許使用萬用字元。只有當命令也包含 Property 參數時,這個參數才有作用。 Property 參數的值可以是計算屬性,亦即指定名稱並針對屬性顯示計算值的雜湊表。有效的索引鍵包括: -- Name 或 Label <字串> -- Expression <字串> 或 <指令碼區塊> 如需詳細資訊,請參閱範例。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="true" pipelineInput="false" position="named"> <maml:name>ExpandProperty</maml:name> <maml:description> <maml:para>指定要選取的屬性,並表示應嘗試展開該屬性。允許在屬性名稱中使用萬用字元。 例如,若指定的屬性是陣列,在輸出中會包含該陣列的每個值。若屬性包含物件,在輸出中則會顯示該物件的屬性。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>First</maml:name> <maml:description> <maml:para>指定要從輸入物件陣列開頭選取的物件個數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Index</maml:name> <maml:description> <maml:para>根據物件的索引值,從陣列選取物件。請以逗號分隔的清單輸入索引。 陣列中的索引以 0 為起始,其中 0 代表第一個值,(n-1) 代表最後一個值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> <dev:type> <maml:name>Int32[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要透過管線傳送給 Cmdlet 的物件。此參數可讓您經由管道將物件輸出至 Select-Object。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Last</maml:name> <maml:description> <maml:para>指定要從輸入物件陣列結尾選取的物件個數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定要選取的屬性。允許使用萬用字元。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Name (或 Label) <字串> -- Expression <字串> 或 <指令碼區塊></maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Skip</maml:name> <maml:description> <maml:para>略過 (不選取) 指定的項目數。根據預設,Skip 參數會從陣列或物件清單的開頭開始計數,但如果命令使用 Last 參數,則會從清單或陣列的結尾開始計數。 不像 Index 參數是從 0 開始計數,Skip 參數是起始於 1。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Unique</maml:name> <maml:description> <maml:para>指定一旦輸入物件的子集具有相同的屬性和值,則僅選取單一子集成員。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將任何物件輸出至 Select-Object。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以利用內建的別名 "select" 來參照 Select-Object。如需詳細資訊,請參閱 about_Aliases。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | select-object ProcessName,Id,WS </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示處理序的清單。只會顯示處理序的名稱、識別碼及工作組 (WS) 屬性。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | select-object processname -expandproperty modules | format-list ProcessName : 00THotkey Size : 256 Company : TOSHIBA Corporation FileVersion : 1, 0, 0, 27 ProductVersion : 6, 2, 0, 0 Description : THotkey Product : TOSHIBA THotkey ModuleName : 00THotkey.exe FileName : C:\WINDOWS\system32\00THotkey.exe BaseAddress : 4194304 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示電腦上執行的處理序所使用之模組的相關資訊。它使用 ExpandProperty 參數來顯示模組屬性內含的詳細資料。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | sort-object -property WS | select-object -Last 5 Handles NPM(K) PM(K) WS(K) VS(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 2866 320 33432 45764 203 222.41 1292 svchost 577 17 23676 50516 265 50.58 4388 WINWORD 826 11 75448 76712 188 19.77 3780 Ps 1367 14 73152 88736 216 61.69 676 Ps 1612 44 66080 92780 380 900.59 6132 INFOPATH </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示使用最多記憶體的五個處理序。Sort-Object Cmdlet 用於依記憶體 (工作組) 使用量排序處理序,而 Select-Object Cmdlet 則用來僅選取結果物件陣列的最後五個成員。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | select-object -property ProcessName,@{Name="Start Day"; Expression = {$_.StartTime.DayOfWeek}} ProcessName StartDay ---- -------- alg Wednesday ati2evxx Wednesday ati2evxx Thursday ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示電腦上執行之處理序的名稱與開始日期。 Property 參數的值為 ProcessName 以及名為 "Start Day" 的計算屬性。"Start Day" 屬性是使用雜湊表搭配 Name 和 Expression 索引鍵加入的。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> "a","b","c","a","a","a" | select-object -unique a b c </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示字元陣列中的唯一字元。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-eventlog -log "Windows PowerShell" C:\PS> $a | select-object -index 0, ($a.count - 1) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會取得 Windows PowerShell 事件記錄檔中的第一筆 (最新) 和最後一筆 (最舊) 事件。 第一個命令會使用 Get-EventLog Cmdlet 取得 Windows PowerShell 記錄檔中的所有事件,然後將這些事件儲存到 $a 變數。 第二個命令會使用管線運算子 (|) 將 $a 中的事件傳送給 Select-Object Cmdlet。Select-Object 命令會使用 Index 參數,依照項目的索引編號選取項目。第一個事件的索引為 0。最後一個事件的索引則是 $a 中的項目數減去 1。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> new-pssession -computername (get-content servers.txt | select-object -skip 1) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在 Servers.txt 檔案所列出的每個電腦上建立新的 PSSession,但第一個除外。 這個命令會使用 Select-Object Cmdlet 選取電腦名稱清單中第一個以外的所有電腦,然後將產生的電腦清單設為 New-PSSession Cmdlet 的 ComputerName 參數值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113387</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Where-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Group-Object</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Sort-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Select-String </command:name> <maml:description> <maml:para>在字串和檔案中尋找文字。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Select</command:verb> <command:noun>String</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Select-String Cmdlet 會在輸出字串或檔案中搜尋文字和文字模式。您可以像 UNIX 的 Grep 和 Windows 的 Findstr 一樣使用它。 Select-String 是以文字行為主。根據預設,Select-String 會在每一行尋找第一個相符項目,而且針對每個相符項目會顯示檔名、行號和有相符項目的行中的所有文字。 不過,您可以指示此 Cmdlet 在每一行偵測多個相符項目、顯示相符項目前後的文字,或只顯示代表是否找到相符項目的布林值 (true 或 false)。 Select-String 會使用規則運算式比對,但也能執行單一比對,搜尋您所指定的輸入文字。 Select-String 能顯示所有的文字相符項目,或在每個輸入檔中的第一個相符項目後停止。它也能顯示所有不符合指定之模式的文字。 您也可以指定 Select-String 應該採用特定字元編碼,例如在搜尋 Unicode 文字的檔案時。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Select-String</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定要搜尋的檔案之路徑。允許使用萬用字元。預設位置為本機目錄。 請指定目錄中的檔案,例如 "log1.txt"、"*.doc" 或 "*.*"。如果只指定目錄,命令會失敗。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>指定要尋找的文字。請輸入字串或規則運算式。若要輸入字串,請使用 SimpleMatch 參數。 若要深入了解規則運算式,請參閱 about_Regular_Expressions。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AllMatches</maml:name> <maml:description> <maml:para>在每一行文字搜尋一個以上的相符項目。若沒有此參數,Select-String 只會在每一行文字尋找第一個相符項目。 Select-String 在每一行文字找到一個以上的相符項目時,只會為該行發出一個 MatchInfo 物件,但物件的 Matches 屬性則會包含所有的相符項目。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CaseSensitive</maml:name> <maml:description> <maml:para>執行有大小寫之分的比對。根據預設,比對項目時沒有大小寫之分。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Context</maml:name> <maml:description> <maml:para>擷取有相符項目的行前後的指定行數。這能讓您在內容中檢視相符項目。 如果輸入一個數字做為此參數的值,該數字會決定在相符項目前後所擷取的行數。如果輸入兩個數字做為此參數的值,第一個數字會決定在相符項目之前的行數,第二個數字會決定在相符項目之後的行數。 根據預設檢視,在顯示的第一欄中會用右角括弧 (ASCII 62) 表示有相符項目的行。沒有標記的行則是內容。 此參數不會變更 Select-String 所產生的物件數。Select-String 會為每個相符項目產生 MatchInfo (Microsoft.PowerShell.Commands.MatchInfo) 物件。內容在物件的 Context 屬性中會儲存為字串的陣列。 當您透過管道將 Select-String 命令的輸出傳送給另一個 Select-String 命令時,接收端的命令只會搜尋相符的行 (MatchInfo 物件的 Line 屬性值) 中的文字,而非內容行中的文字。因此,Context 參數對接收端的 Select-String 命令無效。 當內容包含相符項目時,每個相符項目的 MatchInfo 物件都會包含所有的內容行,但重疊的行只會在顯示中出現一次。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定 Select-String 在搜尋檔案時所應採用的字元編碼。預設為 UTF8。 有效的值包括:"UTF7"、"UTF8"、"UTF32"、"ASCII"、"Unicode"、"BigEndianUnicode"、"Default" 和 "OEM"。"Default" 為系統目前的 ANSI 字碼頁的編碼。"OEM" 為作業系統目前的原始設備製造商字碼頁識別元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>排除指定的項目。此參數的值用於限定 Path 參數。輸入路徑元素或模式,例如 "*.txt"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>只包含指定的項目。此參數的值用於限定 Path 參數。輸入路徑元素或模式,例如 "*.txt"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>List</maml:name> <maml:description> <maml:para>只傳回每個輸入檔中的第一個相符項目。根據預設,Select-String 會為每個找到的相符項目傳回 MatchInfo 物件。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NotMatch</maml:name> <maml:description> <maml:para>尋找不符合指定之模式的文字。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Quiet</maml:name> <maml:description> <maml:para>傳回布林值 (true 或 false),而非 MatchInfo 物件。如果找到模式,則該值為 "true",否則為 "false"。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SimpleMatch</maml:name> <maml:description> <maml:para>使用簡單比對,而不使用規則運算式比對。透過簡單比對,Select-String 會搜尋輸入以找出 Pattern 參數中的文字,但不會將 Pattern 參數的值解譯為規則運算式陳述式。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Select-String</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要搜尋的文字。請輸入包含文字的變數,或輸入可取得文字的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>指定要尋找的文字。請輸入字串或規則運算式。若要輸入字串,請使用 SimpleMatch 參數。 若要深入了解規則運算式,請參閱 about_Regular_Expressions。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AllMatches</maml:name> <maml:description> <maml:para>在每一行文字搜尋一個以上的相符項目。若沒有此參數,Select-String 只會在每一行文字尋找第一個相符項目。 Select-String 在每一行文字找到一個以上的相符項目時,只會為該行發出一個 MatchInfo 物件,但物件的 Matches 屬性則會包含所有的相符項目。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CaseSensitive</maml:name> <maml:description> <maml:para>執行有大小寫之分的比對。根據預設,比對項目時沒有大小寫之分。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Context</maml:name> <maml:description> <maml:para>擷取有相符項目的行前後的指定行數。這能讓您在內容中檢視相符項目。 如果輸入一個數字做為此參數的值,該數字會決定在相符項目前後所擷取的行數。如果輸入兩個數字做為此參數的值,第一個數字會決定在相符項目之前的行數,第二個數字會決定在相符項目之後的行數。 根據預設檢視,在顯示的第一欄中會用右角括弧 (ASCII 62) 表示有相符項目的行。沒有標記的行則是內容。 此參數不會變更 Select-String 所產生的物件數。Select-String 會為每個相符項目產生 MatchInfo (Microsoft.PowerShell.Commands.MatchInfo) 物件。內容在物件的 Context 屬性中會儲存為字串的陣列。 當您透過管道將 Select-String 命令的輸出傳送給另一個 Select-String 命令時,接收端的命令只會搜尋相符的行 (MatchInfo 物件的 Line 屬性值) 中的文字,而非內容行中的文字。因此,Context 參數對接收端的 Select-String 命令無效。 當內容包含相符項目時,每個相符項目的 MatchInfo 物件都會包含所有的內容行,但重疊的行只會在顯示中出現一次。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定 Select-String 在搜尋檔案時所應採用的字元編碼。預設為 UTF8。 有效的值包括:"UTF7"、"UTF8"、"UTF32"、"ASCII"、"Unicode"、"BigEndianUnicode"、"Default" 和 "OEM"。"Default" 為系統目前的 ANSI 字碼頁的編碼。"OEM" 為作業系統目前的原始設備製造商字碼頁識別元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>排除指定的項目。此參數的值用於限定 Path 參數。輸入路徑元素或模式,例如 "*.txt"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>只包含指定的項目。此參數的值用於限定 Path 參數。輸入路徑元素或模式,例如 "*.txt"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>List</maml:name> <maml:description> <maml:para>只傳回每個輸入檔中的第一個相符項目。根據預設,Select-String 會為每個找到的相符項目傳回 MatchInfo 物件。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NotMatch</maml:name> <maml:description> <maml:para>尋找不符合指定之模式的文字。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Quiet</maml:name> <maml:description> <maml:para>傳回布林值 (true 或 false),而非 MatchInfo 物件。如果找到模式,則該值為 "true",否則為 "false"。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SimpleMatch</maml:name> <maml:description> <maml:para>使用簡單比對,而不使用規則運算式比對。透過簡單比對,Select-String 會搜尋輸入以找出 Pattern 參數中的文字,但不會將 Pattern 參數的值解譯為規則運算式陳述式。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>AllMatches</maml:name> <maml:description> <maml:para>在每一行文字搜尋一個以上的相符項目。若沒有此參數,Select-String 只會在每一行文字尋找第一個相符項目。 Select-String 在每一行文字找到一個以上的相符項目時,只會為該行發出一個 MatchInfo 物件,但物件的 Matches 屬性則會包含所有的相符項目。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CaseSensitive</maml:name> <maml:description> <maml:para>執行有大小寫之分的比對。根據預設,比對項目時沒有大小寫之分。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Context</maml:name> <maml:description> <maml:para>擷取有相符項目的行前後的指定行數。這能讓您在內容中檢視相符項目。 如果輸入一個數字做為此參數的值,該數字會決定在相符項目前後所擷取的行數。如果輸入兩個數字做為此參數的值,第一個數字會決定在相符項目之前的行數,第二個數字會決定在相符項目之後的行數。 根據預設檢視,在顯示的第一欄中會用右角括弧 (ASCII 62) 表示有相符項目的行。沒有標記的行則是內容。 此參數不會變更 Select-String 所產生的物件數。Select-String 會為每個相符項目產生 MatchInfo (Microsoft.PowerShell.Commands.MatchInfo) 物件。內容在物件的 Context 屬性中會儲存為字串的陣列。 當您透過管道將 Select-String 命令的輸出傳送給另一個 Select-String 命令時,接收端的命令只會搜尋相符的行 (MatchInfo 物件的 Line 屬性值) 中的文字,而非內容行中的文字。因此,Context 參數對接收端的 Select-String 命令無效。 當內容包含相符項目時,每個相符項目的 MatchInfo 物件都會包含所有的內容行,但重疊的行只會在顯示中出現一次。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> <dev:type> <maml:name>Int32[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定 Select-String 在搜尋檔案時所應採用的字元編碼。預設為 UTF8。 有效的值包括:"UTF7"、"UTF8"、"UTF32"、"ASCII"、"Unicode"、"BigEndianUnicode"、"Default" 和 "OEM"。"Default" 為系統目前的 ANSI 字碼頁的編碼。"OEM" 為作業系統目前的原始設備製造商字碼頁識別元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>排除指定的項目。此參數的值用於限定 Path 參數。輸入路徑元素或模式,例如 "*.txt"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>只包含指定的項目。此參數的值用於限定 Path 參數。輸入路徑元素或模式,例如 "*.txt"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要搜尋的文字。請輸入包含文字的變數,或輸入可取得文字的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>List</maml:name> <maml:description> <maml:para>只傳回每個輸入檔中的第一個相符項目。根據預設,Select-String 會為每個找到的相符項目傳回 MatchInfo 物件。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NotMatch</maml:name> <maml:description> <maml:para>尋找不符合指定之模式的文字。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定要搜尋的檔案之路徑。允許使用萬用字元。預設位置為本機目錄。 請指定目錄中的檔案,例如 "log1.txt"、"*.doc" 或 "*.*"。如果只指定目錄,命令會失敗。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Pattern</maml:name> <maml:description> <maml:para>指定要尋找的文字。請輸入字串或規則運算式。若要輸入字串,請使用 SimpleMatch 參數。 若要深入了解規則運算式,請參閱 about_Regular_Expressions。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Quiet</maml:name> <maml:description> <maml:para>傳回布林值 (true 或 false),而非 MatchInfo 物件。如果找到模式,則該值為 "true",否則為 "false"。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SimpleMatch</maml:name> <maml:description> <maml:para>使用簡單比對,而不使用規則運算式比對。透過簡單比對,Select-String 會搜尋輸入以找出 Pattern 參數中的文字,但不會將 Pattern 參數的值解譯為規則運算式陳述式。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將具有 ToString 方法的任何物件輸出至 Select-String。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>Microsoft.PowerShell.Commands.MatchInfo 或 System.Boolean</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 根據預設,輸出為一組 MatchInfo 物件 (找到的每個相符項目各一個物件)。如果您使用 Quiet 參數,輸出則為指出是否找到模式的布林值。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> Select-String 如同 UNIX 的 Grep 命令和 Windows 的 FindStr 命令。 若要使用 Select-String,請輸入要尋找的文字做為 Pattern 參數的值。 若要指定要搜尋的文字,請進行下列步驟: -- 用引號括住的字串輸入文字,然後經由管道將它輸出至 Select-String。 -- 將文字字串儲存到變數,然後將該變數指定為 InputObject 參數的值。 -- 如果文字已儲存在檔案中,請使用 Path 參數指定檔案的路徑。 根據預設,Select-String 會將 Pattern 參數的值解譯為規則運算式 (如需詳細資訊,請參閱 about_Regular_Expressions)。不過,您可以使用 SimpleMatch 參數覆寫規則運算式比對。SimpleMatch 參數會在輸入中尋找 Pattern 參數值的例項。 Select-String 的預設輸出為 MatchInfo 物件,內含有關相符項目的詳細資訊。此物件中的資訊有助於搜尋檔案中的文字,因為 MatchInfo 物件具有 Filename 和 Line 之類的屬性。如果輸入的來源不是檔案時,這些參數的值會是 "InputStream"。 如果您不需要 MatchInfo 物件中的資訊,請使用 Quiet 參數,它傳回的是代表是否找到相符項目的布林值 (true 或 false),而非 MatchInfo 物件。 比對片語時,Select-String 會使用目前針對系統所設定的片語。若要尋找目前的文化特性,請使用 Get-Culture Cmdlet。 若要找出 MatchInfo 物件的屬性,請輸入下列命令: select-string -path test.txt -pattern "test" | get-member | format-list -property * </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> "Hello","HELLO" | select-string -pattern "HELLO" -casesensitive </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會對已經由管道輸出至 Select-String 命令的文字,執行有大小寫之分的比對。 因此,Select-String 只會尋找 "HELLO",因為 "Hello" 不符。 因為每個以引號括住的字串都被視為一行,所以如果沒有 CaseSensitive 參數,Select-String 會將上述兩個字串都辨識為相符項目。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> select-string -path *.xml -pattern "the the" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在目前目錄中搜尋副檔名為 .xml 的所有檔案,並顯示那些檔案中包含字串 "the the" 的行。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> select-string -path $pshome\en-US\*.txt -pattern "@" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會搜尋 Windows PowerShell 概念性說明檔 (about_*.txt) 以找出 @ 符號用法的相關資訊。 為了包含路徑,這個命令使用 $pshome 自動變數的值,此變數儲存了 Windows PowerShell 安裝目錄的路徑。這個範例命令會搜尋 en-US 子目錄,其內含 Windows PowerShell 的英文 (美國) 版說明檔。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> function search-help { $pshelp = "$pshome\es\about_*.txt", "$pshome\en-US\*dll-help.xml" select-string -path $pshelp -pattern $args[0] } </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個簡單函數會使用 Select-String Cmdlet 搜尋 Windows PowerShell 說明檔以找出特定字串。這個範例函數會搜尋 "en-US" 子目錄以找出英文 (美國) 版說明檔。 若要使用這個函數找出字串,例如 "psdrive",請輸入 "search-help psdrive"。 若要在任何 Windows PowerShell 主控台中使用這個函數,請變更路徑,讓它指向您系統上的 Windows PowerShell 說明檔,然後將這個函數貼入 Windows PowerShell 設定檔。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $events = get-eventlog -logname application -newest 100 C:\PS> $events | select-string -inputobject {$_.message} -pattern "failed" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會在事件檢視器應用程式記錄檔的 100 個最新的事件中搜尋 "failed" 字串。 第一個命令會使用 Get-EventLog Cmdlet 從應用程式事件記錄檔取得 100 個最新的事件,然後將這些事件儲存到 $events 變數。 第二個命令會使用管線運算子 (|) 將 $events 變數中的事件傳送給 Select-String,並使用 InputObject 參數來代表來自 $events 變數的輸入。InputObject 參數的值是每個物件通過管線時的 Message 屬性。$_ 符號代表目前的物件。 當每個事件到達管線時,Select-String 會搜尋其 Message 屬性的值以找出 "failed" 字串,然後顯示任何包含該相符項目的行。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem c:\windows\system32\* -include *.txt -recurse | select-string -pattern "Microsoft" -casesensitive </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會分析 C:\Windows\System32 的子目錄中副檔名為 .txt 的所有檔案,並找出 "Microsoft" 字串。CaseSensitive 參數表示 "Microsoft" 中的 "M" 必須是大寫的,而其餘字元必須是小寫的,才算是 Select-String 找到相符項目。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> select-string -path process.txt -pattern idle, svchost -notmatch </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在 Process.txt 檔案中尋找不包含 "idle" 或 "svchost" 字詞的文字行。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 8 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $f = select-string -path audit.log -pattern "logon failed" -context 2, 3 C:\PS> $f.count C:\PS> ($f)[0].context | format-list </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>第一個命令會搜尋 Audit.Log 檔案以找出 "logon failed" 片語,並使用 Context 參數擷取相符項目的前 2 行和後 3 行。 第二個命令會使用物件陣列的 Count 屬性來顯示找到的相符項目數,在本例中為 2。 第三個命令會顯示第一個 MatchInfo 物件的 Context 屬性中所儲存的行。此命令會使用陣列標記法表示第一個相符項目 (符合以零為起始的陣列中的 0),並使用 Format-List Cmdlet 將 Context 屬性的值顯示成清單。 輸出會包含兩個 MatchInfo 物件,偵測到的每個相符項目各一個。內容行會儲存在 MatchInfo 物件的 Context 屬性中。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 9 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = get-childitem $pshome\en-us\about*.help.txt | select-string -pattern transcript C:\PS> $b = get-childitem $pshome\en-us\about*.help.txt | select-string -pattern transcript -allmatches C:\PS> $a C:\Windows\system32\WindowsPowerShell\v1.0\en-us\about_Pssnapins.help.txt:39: Start-Transcript and Stop-Transcript. C:\PS> $b C:\Windows\system32\WindowsPowerShell\v1.0\en-us\about_Pssnapins.help.txt:39: Start-Transcript and Stop-Transcript. C:\PS>> $a.matches Groups : {Transcript} Success : True Captures : {Transcript} Index : 13 Length : 10 Value : Transcript C:\PS> $b.matches Groups : {Transcript} Success : True Captures : {Transcript} Index : 13 Length : 10 Value : Transcript Groups : {Transcript} Success : True Captures : {Transcript} Index : 33 Length : 10 Value : Transcript </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會示範 Select-String 之 AllMatches 參數的效果。AllMatches 會在每一行尋找所有模式比對項目,而不只是在每一行尋找第一個相符項目。 這個範例中的第一個命令會搜尋 Windows PowerShell 概念性說明檔 ("about" 說明) 以找出 "transcript" 字詞的例項。第二個命令與第一個完全一樣,但多了一個 AllMatches 參數。 第一個命令的輸出會儲存到 $a 變數。第二個命令的輸出會儲存到 $b 變數。 在顯示這兩個變數的值時,預設顯示會完全相同,如範例輸出所示。 但是,第五個和第六個命令會顯示每個物件的 Matches 屬性值。第一個命令的 Matches 屬性只包含一個相符項目 (也就是一個 System.Text.RegularExpressions.Match 物件),而第二個命令的 Matches 屬性則包含行中兩個相符項目的物件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113388</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Comparison_Operators</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Regular_Expressions</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Select-XML </command:name> <maml:description> <maml:para>在 XML 字串或文件中尋找文字。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Select</command:verb> <command:noun>XML</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Select-XML Cmdlet 能讓您以 XPath 查詢來搜尋 XML 字串和文件中的文字。請輸入 XPath 查詢,並使用 Content、Path 或 Xml 參數指定要搜尋的 XML。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Select-XML</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Content</maml:name> <maml:description> <maml:para>指定包含要搜尋之 XML 的字串。您也可經由管道將字串輸出至 Select-XML。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Xpath</maml:name> <maml:description> <maml:para>指定 XPath 搜尋查詢。該查詢語言有大小寫之分。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Namespace</maml:name> <maml:description> <maml:para>指定 XML 中使用之命名空間的雜湊表。請使用 @{<namespaceName> = <namespaceValue>} 格式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">hashtable</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Select-XML</maml:name> <command:parameter required="true" variableLength="true" globbing="true" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定要搜尋之 XML 檔案的路徑和檔案名稱。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Xpath</maml:name> <maml:description> <maml:para>指定 XPath 搜尋查詢。該查詢語言有大小寫之分。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Namespace</maml:name> <maml:description> <maml:para>指定 XML 中使用之命名空間的雜湊表。請使用 @{<namespaceName> = <namespaceValue>} 格式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">hashtable</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Select-XML</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="2"> <maml:name>Xml</maml:name> <maml:description> <maml:para>指定一個或多個 XML 節點。每一個命令都需要有 Path 或 XML 參數。 XML 文件會以 XML 節點集合的方式處理。如果您經由管道將 XML 文件輸出至 Select-XML,則當每個文件節點通過管線時將個別進行搜尋。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">XmlNode[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Xpath</maml:name> <maml:description> <maml:para>指定 XPath 搜尋查詢。該查詢語言有大小寫之分。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Namespace</maml:name> <maml:description> <maml:para>指定 XML 中使用之命名空間的雜湊表。請使用 @{<namespaceName> = <namespaceValue>} 格式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">hashtable</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Content</maml:name> <maml:description> <maml:para>指定包含要搜尋之 XML 的字串。您也可經由管道將字串輸出至 Select-XML。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Namespace</maml:name> <maml:description> <maml:para>指定 XML 中使用之命名空間的雜湊表。請使用 @{<namespaceName> = <namespaceValue>} 格式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">hashtable</command:parameterValue> <dev:type> <maml:name>hashtable</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="true" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Path</maml:name> <maml:description> <maml:para>指定要搜尋之 XML 檔案的路徑和檔案名稱。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="2"> <maml:name>Xml</maml:name> <maml:description> <maml:para>指定一個或多個 XML 節點。每一個命令都需要有 Path 或 XML 參數。 XML 文件會以 XML 節點集合的方式處理。如果您經由管道將 XML 文件輸出至 Select-XML,則當每個文件節點通過管線時將個別進行搜尋。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">XmlNode[]</command:parameterValue> <dev:type> <maml:name>XmlNode[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Xpath</maml:name> <maml:description> <maml:para>指定 XPath 搜尋查詢。該查詢語言有大小寫之分。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String 或 System.Xml.XmlNode</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經管道將路徑或 XML 節點輸出至 Select-XML。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Xml.XmlElement 或 System.Xml.XmlText</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> XPath 是一種標準語言,專門用來識別 XML 文件的部分。如需 XPath 語言的詳細資訊,請參閱 MSDN (Microsoft Developer Network) Library 中<事件選取範圍>主題的<選取範圍篩選器>一節 (英文),網址為:http://go.microsoft.com/fwlink/?LinkId=143608。此外,請參閱 MSDN Library 中的<XPath 參考>,網址為:http://go.microsoft.com/fwlink/?LinkId=143609。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $path = "$env:windir\System32\WindowsPowerShell\v1.0\Types.ps1xml" C:\PS> select-xml -path $path -xpath "/Types/Type/Members/AliasProperty" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會搜尋 Types.ps1xml 檔案以找出 AliasProperty 節點的子項目。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> select-xml -path test*.xml, help.xml -xpath "/Tests/Test[1]/Name" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 Select-XML 在數個 XML 檔案中進行搜尋。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> [xml]$Types = get-content "$env:windir\System32\WindowsPowerShell\v1.0\Types.ps1xml" C:\PS> select-xml -xml $Types -xpath "//MethodName" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何經由管道將 XML 文件輸出至 Search-Path。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $namespace = @{command="http://schemas.microsoft.com/maml/dev/command/2004/10"; maml="http://schemas.microsoft.com/maml/2004/10"; dev="http://schemas.microsoft.com/maml/dev/2004/10"} C:\PS> $path = "$env:windir\System32\WindowsPowerShell\V1.0\en-us\*dll-Help.xml" C:\PS> select-xml -path $path -namespace $namespace -xpath "//command:name" Text Node Path ---- ---- ---- Add-Computer name C:\Windows\System32\WindowsPowerShell\V... Add-Content name C:\Windows\System32\WindowsPowerShell\V... Checkpoint-Computer name C:\Windows\System32\WindowsPowerShell\V... Clear-Content name C:\Windows\System32\WindowsPowerShell\V... Clear-EventLog name C:\Windows\System32\WindowsPowerShell\V... ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用 Select-XML Cmdlet 搜尋 Windows PowerShell XML Cmdlet 說明檔。 第一個命令會建立代表 XML 命名空間的雜湊表,然後將其儲存到 $namespace 變數。 第二個命令會將說明檔的路徑儲存到 $path 變數。 第三個命令會透過在檔案中的任何位置找出 Command:Name 標記,使用 Select-Xml 搜尋 XML 以找出 Cmdlet 名稱。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> select-xml -content $xml -xpath "//edition" C:\PS> $xml = @" <?xml version="1.0" encoding="utf-8"?> <Book> <projects> <project name="Book1" date="2009-01-20"> <editions> <edition language="English">En.Book1.com</edition> <edition language="German">Ge.Book1.Com</edition> <edition language="French">Fr.Book1.com</edition> <edition language="Polish">Pl.Book1.com</edition> </editions> </project> </projects> </Book> "@ C:\PS> select-xml -content $xml -xpath "//edition" Text Node Path ---- ---- ---- En.Book1.com edition InputStream Ge.Book1.Com edition InputStream Fr.Book1.com edition InputStream Pl.Book1.com edition InputStream C:\PS> $xml | select-xml -xpath "//edition" Text Node Path ---- ---- ---- En.Book1.com edition InputStream Ge.Book1.Com edition InputStream Fr.Book1.com edition InputStream Pl.Book1.com edition InputStream </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會使用 Select-XML 的 Content 參數搜尋 here-string 中的 XML 內容。 第一個命令會將 here-string 儲存到 $xml 變數。 第二個命令會使用 Content 參數指定 $xml 變數中的 XML。 第三個命令相當於第二個命令。此命令會使用管線運算子 (|) 將 $xml 變數中的 XML 傳送給 Select-XML Cmdlet。 如需 here-string 的詳細資訊,請輸入 about_Quoting_Rules。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135255</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>ConvertTo-XML</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Send-MailMessage </command:name> <maml:description> <maml:para>傳送電子郵件訊息。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Send</command:verb> <command:noun>MailMessage</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Send-MailMessage Cmdlet 會從 Windows PowerShell 內傳送電子郵件訊息。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Send-MailMessage</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>To</maml:name> <maml:description> <maml:para>指定郵件傳送的目標地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Subject</maml:name> <maml:description> <maml:para>指定電子郵件訊息的主旨。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>From</maml:name> <maml:description> <maml:para>指定郵件傳送的來源地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Body</maml:name> <maml:description> <maml:para>指定電子郵件訊息的內文 (內容)。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="4"> <maml:name>SmtpServer</maml:name> <maml:description> <maml:para>指定傳送電子郵件訊息的 SMTP 伺服器名稱。 預設值為 $PSEmailServer 喜好設定變數的值。如果未設定該喜好設定變數,而且省略此參數,則命令會失敗。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Attachments</maml:name> <maml:description> <maml:para>指定要在電子郵件訊息中附加之檔案的路徑和檔名。您可以直接使用此參數,或經由管道將路徑和檔名輸出至 Send-MailMessage。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Bcc</maml:name> <maml:description> <maml:para>指定接收郵件副本但不列為訊息收件者的電子郵件地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>BodyAsHtml</maml:name> <maml:description> <maml:para>表示 Body 參數的值包含 HTML。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Cc</maml:name> <maml:description> <maml:para>指定要傳送電子郵件訊息副本 (CC) 至的電子郵件地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Credential</maml:name> <maml:description> <maml:para>指定具有執行此動作之權限的使用者帳戶。預設為目前使用者。 請輸入使用者名稱,例如 "User01" 或 "Domain01\User01"。或者輸入 PSCredential 物件,例如 Get-Credential Cmdlet 所傳回的物件。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSCredential</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DeliveryNotificationOption</maml:name> <maml:description> <maml:para>指定電子郵件訊息的傳遞通知選項。您可以指定多個值。預設值為 "None"。此參數的別名為 "dno"。 傳遞通知會以電子郵件訊息傳送到 To 參數值中所指定的地址。 有效的值包括: -- None:沒有通知。 -- OnSuccess:如果傳遞成功則發送通知。 -- OnFailure:如果傳遞失敗則發送通知。 -- Delay:如果傳遞延遲則發送通知。 -- Never:永不通知。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">OnSuccess</command:parameterValue> <command:parameterValue required="false" variableLength="false">OnFailure</command:parameterValue> <command:parameterValue required="false" variableLength="false">Delay</command:parameterValue> <command:parameterValue required="false" variableLength="false">Never</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定用於內文和主旨的編碼。有效的值包括 ASCII、UTF8、UTF7、UTF32、Unicode、BigEndianUnicode、Default 和 OEM。預設為 ASCII。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Encoding</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Priority</maml:name> <maml:description> <maml:para>指定電子郵件訊息的優先順序。此參數的有效值包括 Normal、High 和 Low。預設為 Normal。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Normal</command:parameterValue> <command:parameterValue required="false" variableLength="false">Low</command:parameterValue> <command:parameterValue required="false" variableLength="false">High</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UseSsl</maml:name> <maml:description> <maml:para>使用安全通訊端層 (SSL) 通訊協定來建立遠端電腦的連線,以便傳送郵件。根據預設,系統不會使用 SSL。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>Attachments</maml:name> <maml:description> <maml:para>指定要在電子郵件訊息中附加之檔案的路徑和檔名。您可以直接使用此參數,或經由管道將路徑和檔名輸出至 Send-MailMessage。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Bcc</maml:name> <maml:description> <maml:para>指定接收郵件副本但不列為訊息收件者的電子郵件地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Body</maml:name> <maml:description> <maml:para>指定電子郵件訊息的內文 (內容)。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>BodyAsHtml</maml:name> <maml:description> <maml:para>表示 Body 參數的值包含 HTML。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Cc</maml:name> <maml:description> <maml:para>指定要傳送電子郵件訊息副本 (CC) 至的電子郵件地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Credential</maml:name> <maml:description> <maml:para>指定具有執行此動作之權限的使用者帳戶。預設為目前使用者。 請輸入使用者名稱,例如 "User01" 或 "Domain01\User01"。或者輸入 PSCredential 物件,例如 Get-Credential Cmdlet 所傳回的物件。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSCredential</command:parameterValue> <dev:type> <maml:name>PSCredential</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>目前使用者</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DeliveryNotificationOption</maml:name> <maml:description> <maml:para>指定電子郵件訊息的傳遞通知選項。您可以指定多個值。預設值為 "None"。此參數的別名為 "dno"。 傳遞通知會以電子郵件訊息傳送到 To 參數值中所指定的地址。 有效的值包括: -- None:沒有通知。 -- OnSuccess:如果傳遞成功則發送通知。 -- OnFailure:如果傳遞失敗則發送通知。 -- Delay:如果傳遞延遲則發送通知。 -- Never:永不通知。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DeliveryNotificationOptions</command:parameterValue> <dev:type> <maml:name>DeliveryNotificationOptions</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Encoding</maml:name> <maml:description> <maml:para>指定用於內文和主旨的編碼。有效的值包括 ASCII、UTF8、UTF7、UTF32、Unicode、BigEndianUnicode、Default 和 OEM。預設為 ASCII。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Encoding</command:parameterValue> <dev:type> <maml:name>Encoding</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>ASCII</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>From</maml:name> <maml:description> <maml:para>指定郵件傳送的來源地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Priority</maml:name> <maml:description> <maml:para>指定電子郵件訊息的優先順序。此參數的有效值包括 Normal、High 和 Low。預設為 Normal。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">MailPriority</command:parameterValue> <dev:type> <maml:name>MailPriority</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Normal.</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="4"> <maml:name>SmtpServer</maml:name> <maml:description> <maml:para>指定傳送電子郵件訊息的 SMTP 伺服器名稱。 預設值為 $PSEmailServer 喜好設定變數的值。如果未設定該喜好設定變數,而且省略此參數,則命令會失敗。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>$PSEmailServer</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Subject</maml:name> <maml:description> <maml:para>指定電子郵件訊息的主旨。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>To</maml:name> <maml:description> <maml:para>指定郵件傳送的目標地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。此參數為必要項。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>UseSsl</maml:name> <maml:description> <maml:para>使用安全通訊端層 (SSL) 通訊協定來建立遠端電腦的連線,以便傳送郵件。根據預設,系統不會使用 SSL。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>False</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將附件的路徑和檔名輸出至 Send-MailMessage。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> send-mailmessage -to "User01 <user01@example.com>" -from "User02 <user02@example.com>" -subject "Test mail" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從 User01 傳送一封電子郵件訊息給 User02。 這封電子郵件訊息有必要的主旨,但沒有選擇性的內容。此外,由於未指定 SmtpServer 參數,Send-MailMessage 會為 SMTP 伺服器使用 $PSEmailServer 喜好設定變數的值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> send-mailmessage -from "User01 <user01@example.com>" -to "User02 <user02@example.com>", "User03 <user03@example.com>" -subject "Sending the Attachment" -body "Forgot to send the attachment. Sending now." -Attachment "data.csv" -priority High -dno onSuccess, onFailure -smtpServer smtp.fabrikam.com </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從 User01 傳送一封有附件的電子郵件訊息給其他兩位使用者。 它會指定優先順序值為 "High",並要求在電子郵件訊息已經傳遞時或失敗時以電子郵件傳遞通知。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> send-mailmessage -to "User01 <user01@example.com>" -from "ITGroup <itdept@example.com>" -cc "User02 <user02@example.com>" -bcc ITMgr <itmgr@example.com> -subject "Don't forget today's meeting!" -credential domain01\admin01 -useSSL </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會從 User01 傳送一封電子郵件訊息給 ITGroup 郵寄清單,同時將副本 (CC) 寄給 User02,以及將密件副本 (BCC) 寄給 IT 主管 (ITMgr)。 這個命令會使用網域系統管理員的認證和 UseSSL 參數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135256</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Set-Alias </command:name> <maml:description> <maml:para>在目前的 Windows PowerShell 工作階段建立或變更 cmdlet 或其他命令元素的別名 (交替名稱)。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Set</command:verb> <command:noun>Alias</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Set-Alias Cmdlet 會建立或變更 Cmdlet 或命令元素 (例如函數、指令碼、檔案或其他執行檔) 的別名 (交替名稱)。您也可以使用 Set-Alias,將目前的別名重新指派給新的命令,或變更別名的任何屬性 (例如其描述)。除非您將別名加入 Windows PowerShell 設定檔,否則對別名所做的變更將會在結束工作階段或關閉 Windows PowerShell 時遺失。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Set-Alias</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定新別名。別名可使用任意英數字元,但第一個字元不可以是數字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Value</maml:name> <maml:description> <maml:para>指定要建立別名的 cmdlet 或命令元素的名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Description</maml:name> <maml:description> <maml:para>指定別名的描述。可輸入任意字串。如果描述中包含空格,請將其置於引號內。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 設定唯讀的別名。請使用 Option 參數來建立唯讀的別名。Force 參數無法設定常數別名。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Option</maml:name> <maml:description> <maml:para>設定別名的 Options 屬性值。 有效的值包括: -- None:不設定選項。(預設值)。 -- ReadOnly:無法變更別名的屬性,除非使用 Force 參數。您可以使用 Remove-Item 刪除別名。 -- Constant:無法刪除別名,而且無法變更別名的屬性。只有建立別名時才能使用 Constant。既有的別名無法將選項變更為 Constant。 -- Private:別名僅可在 Scope 參數所指定的範圍內使用。在其餘所有範圍內,別名均為不可見。 -- AllScope:將別名複製到所有新建立的範圍。 若要查看別名的 Options 屬性,請輸入 "get-alias | format-table -property Name, Definition, Options -autosize"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">ReadOnly</command:parameterValue> <command:parameterValue required="false" variableLength="false">Constant</command:parameterValue> <command:parameterValue required="false" variableLength="false">Private</command:parameterValue> <command:parameterValue required="false" variableLength="false">AllScope</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表別名的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定此別名仍屬有效的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Description</maml:name> <maml:description> <maml:para>指定別名的描述。可輸入任意字串。如果描述中包含空格,請將其置於引號內。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 設定唯讀的別名。請使用 Option 參數來建立唯讀的別名。Force 參數無法設定常數別名。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定新別名。別名可使用任意英數字元,但第一個字元不可以是數字。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Option</maml:name> <maml:description> <maml:para>設定別名的 Options 屬性值。 有效的值包括: -- None:不設定選項。(預設值)。 -- ReadOnly:無法變更別名的屬性,除非使用 Force 參數。您可以使用 Remove-Item 刪除別名。 -- Constant:無法刪除別名,而且無法變更別名的屬性。只有建立別名時才能使用 Constant。既有的別名無法將選項變更為 Constant。 -- Private:別名僅可在 Scope 參數所指定的範圍內使用。在其餘所有範圍內,別名均為不可見。 -- AllScope:將別名複製到所有新建立的範圍。 若要查看別名的 Options 屬性,請輸入 "get-alias | format-table -property Name, Definition, Options -autosize"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">ScopedItemOptions</command:parameterValue> <dev:type> <maml:name>ScopedItemOptions</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表別名的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>指定此別名仍屬有效的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Value</maml:name> <maml:description> <maml:para>指定要建立別名的 cmdlet 或命令元素的名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.AliasInfo</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 PassThru 參數時,Set-Alias 會產生代表別名的 System.Management.Automation.AliasInfo 物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 別名是 cmdlet 或命令元素的交替名稱或暱稱。若要執行 cmdlet,您可以使用其全名或任何有效的別名。如需詳細資訊,請參閱 about_Aliases。 若要建立新的別名,請使用 Set-Alias 或 New-Alias。若要刪除別名,請使用 Remove-Item。 cmdlet 可以有多個別名,但是別名一次只能與一個 cmdlet 相關聯。如果您使用 set-alias 將別名與不同的 Cmdlet 產生關聯,這個別名就不再與原來的 Cmdlet 有關聯。 您可以建立 cmdlet 的別名,但是無法為帶有參數及值的命令建立別名。例如,您可以建立 Set-Location 的別名,但是無法為 "Set-Location C:\Windows\System32" 建立別名。若要建立命令的別名,請先建立包含命令的函數,然後建立該函數的別名。 若要儲存某個工作階段中的別名,然後在不同的工作階段中使用這些別名,請將 set-alias 命令加入至 Windows PowerShell 設定檔。預設情況下,設定檔並不存在。若要在 $profile 變數儲存的路徑中建立設定檔,請輸入 "new-item -type file -force $profile"。若要查看 $profile 變數的值,請輸入 "$profile"。 您也可以使用 Export-Alias,從工作階段將別名複製到檔案來儲存別名,然後使用 Import-Alias 將這些別名加入至新工作階段的別名清單。 您也可以利用內建的別名 "sal" 來參照 Set-Alias。如需詳細資訊,請參閱 about_Aliases。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-alias -name list -value get-childitem </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會為 Get-ChildItem Cmdlet 建立別名 "list"。建立別名後,您可以在命令列及指令碼中使用 "list" 取代 "Get-ChildItem"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-alias list get-location </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將別名 "list" 與 Get-Location Cmdlet 產生關聯。如果 "list" 是另一個 Cmdlet 的別名,這個命令會變更其關聯,使得它現在變成 Get-Location 專屬的別名。 這個命令使用與前一個範例的命令相同的格式,但是省略了選擇性參數名稱 -Name 和 -Value。當您省略參數名稱時,這些參數的值必須在命令中依照指定的順序出現。在此例中,-Name 的值 ("list") 必須是第一個參數,而 -Value 的值 ("get-location") 則必須是第二個參數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-alias scrub remove-item -option readonly -passthru | format-list </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將別名 "scrub" 與 Remove-Item Cmdlet 產生關聯。它使用 "ReadOnly" 選項,防止別名遭到刪除或被指派給另一個 cmdlet。 PassThru 參數會指示 Windows PowerShell,透過管線將代表新別名的物件傳遞給 Format-List Cmdlet。如果省略 PassThru 參數,這個 Cmdlet 就沒有要顯示的輸出 (在清單中或以其他方式顯示)。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> Set-Alias np c:\windows\notepad.exe </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將別名 "np" 與「記事本」的執行檔產生關聯。命令完成後,若要從 Windows PowerShell 命令列開啟「記事本」,只需輸入 "np" 即可。 這個範例表明,您可以為 cmdlet 以外的執行檔和元素建立別名。 若要讓命令更能普遍適用,您可以使用 "Windir" 環境變數 (${env:windir}) 來代表 C\Windows 目錄。此命令的一般形式為 "set-alias np ${env:windir}\notepad.exe"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> function CD32 {set-location c:\windows\system32} C:\PS>set-alias go cd32 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令顯示如何指派別名給帶有參數的命令,甚或給許多命令的管線。 您可以建立 cmdlet 的別名,但是無法為包含 cmdlet 及其參數的命令建立別名。不過,如果將命令放在函數或指令碼中,則可以先建立有用的函數或指令碼名稱,再為函數或指令碼建立一或多個別名。 在這個範例中,使用者想要為命令 "set-location c:\windows\system32" 建立別名,其中 "set-location" 是 Cmdlet,而 "C:\Windows\System32" 則是 Path 參數的值。 為此目的,第一個命令建立了名為 "CD32" 的函數,內含 Set-Location 命令。 第二個命令會為 CD32 函數建立別名 "go"。然後,若要執行 Set-Location 命令,使用者可輸入 "CD32" 或 "go"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113390</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Export-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Import-Alias</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Set-Date </command:name> <maml:description> <maml:para>將電腦的系統時間變更為指定的時間。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Set</command:verb> <command:noun>Date</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Set-Date Cmdlet 可將電腦的系統日期和時間變更為您所指定的日期和時間。輸入字串,或傳遞 DateTime 或 TimeSpan 物件給 Set-Date,即可指定新的日期和/或時間。若要指定新的日期或時間,請使用 Date 參數。若要指定變更的間隔,請使用 Adjust 參數。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Set-Date</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Adjust</maml:name> <maml:description> <maml:para>從目前的日期和時間加上或減去指定的值。您可以為您的地區設定以標準日期和時間格式輸入調整值,或使用 Adjust 參數將 TimeSpan 物件從 New-TimeSpan 傳遞到 Set-Date。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">TimeSpan</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayHint</maml:name> <maml:description> <maml:para>決定所要顯示的日期和時間元素 有效的值包括: -- date:僅顯示日期 -- time:僅顯示時間 -- datetime:顯示日期和時間 此參數只會影響顯示,不會影響 Get-Date 擷取的 DateTime 物件。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Date</command:parameterValue> <command:parameterValue required="false" variableLength="false">Time</command:parameterValue> <command:parameterValue required="false" variableLength="false">DateTime</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Set-Date</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Date</maml:name> <maml:description> <maml:para>將日期和時間變更為指定的值。您可依所在地區輸入簡短日期格式的新日期,以及標準時間格式的新時間。或者,您可以從 Get-Date 傳遞 Date-Time 物件。 若僅指定日期而未指定時間,Set-Date 會將時間變更為指定日期當天的午夜。若僅指定時間,日期將維持不變。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayHint</maml:name> <maml:description> <maml:para>決定所要顯示的日期和時間元素 有效的值包括: -- date:僅顯示日期 -- time:僅顯示時間 -- datetime:顯示日期和時間 此參數只會影響顯示,不會影響 Get-Date 擷取的 DateTime 物件。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Date</command:parameterValue> <command:parameterValue required="false" variableLength="false">Time</command:parameterValue> <command:parameterValue required="false" variableLength="false">DateTime</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Adjust</maml:name> <maml:description> <maml:para>從目前的日期和時間加上或減去指定的值。您可以為您的地區設定以標準日期和時間格式輸入調整值,或使用 Adjust 參數將 TimeSpan 物件從 New-TimeSpan 傳遞到 Set-Date。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">TimeSpan</command:parameterValue> <dev:type> <maml:name>TimeSpan</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Date</maml:name> <maml:description> <maml:para>將日期和時間變更為指定的值。您可依所在地區輸入簡短日期格式的新日期,以及標準時間格式的新時間。或者,您可以從 Get-Date 傳遞 Date-Time 物件。 若僅指定日期而未指定時間,Set-Date 會將時間變更為指定日期當天的午夜。若僅指定時間,日期將維持不變。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DateTime</command:parameterValue> <dev:type> <maml:name>DateTime</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>DisplayHint</maml:name> <maml:description> <maml:para>決定所要顯示的日期和時間元素 有效的值包括: -- date:僅顯示日期 -- time:僅顯示時間 -- datetime:顯示日期和時間 此參數只會影響顯示,不會影響 Get-Date 擷取的 DateTime 物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">DisplayHintType</command:parameterValue> <dev:type> <maml:name>DisplayHintType</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.DateTime</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將日期輸出至 Set-Date。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.DateTime</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Set-Date 會傳回代表它所設定之日期的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 請審慎使用這個 cmdlet。變更電腦的日期和時間。此項變更可能妨礙電腦接收依據日期或時間所觸發的全系統事件與更新。請使用 -WhatIf 和 -Confirm 參數來避免錯誤。 您可以使用標準的 .NET 方法搭配 Set-Date 所使用的 DateTime 和 TimeSpan 物件,如 AddDays、AddMonths 和 FromFileTime。如需詳細資訊,請參閱「DateTime 方法」和「TimeSpan 方法」。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> Set-Date -Date (Get-Date).AddDays(3) </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將目前的系統日期加上 3 日。這不會影響時間。命令使用 Date 參數來指定日期。它會使用 Get-Date Cmdlet 來取得目前的日期和時間,並以 3 (日) 的值來套用 DateTime 物件的 .NET 方法 AddDays。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-date -adjust -0:10:0 -displayHint time </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將目前的系統時間往回設定 10 分鐘。它使用 Adjust 參數指定變更的間隔,而時間即依照地區設定的標準時間格式產生變更 (減去 10 分鐘)。DisplayHint 參數指示 Windows PowerShell 僅顯示時間,但是這不會影響 Set-Date 傳回的 DateTime 物件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $t = get-date C:\PS>set-date -date $t </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將電腦的系統日期和時間變更為儲存在變數 $t 中的日期和時間。第一個命令會取得日期並將它儲存在 $t 中。第二個命令會使用 Date 參數,將 $t 中的 DateTime 物件傳遞給 Set-Date Cmdlet。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $90mins = new-timespan -minutes 90 C:\PS>set-date -adjust $90mins </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令將本機電腦的系統時間提前 90 分鐘。第一個命令會使用 New-Timespan Cmdlet,以 90 分鐘的間隔建立 TimeSpan 物件,然後將 TimeSpan 物件儲存在 $90mins 變數中。第二個命令會使用 Set-Date 的 Adjust 參數,依據 $90mins 變數中的 TimeSpan 物件值調整日期。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113393</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Date</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-TimeSpan</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Set-PSBreakpoint </command:name> <maml:description> <maml:para>在行、命令或變數上設定中斷點。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Set</command:verb> <command:noun>PSBreakpoint</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Set-PSBreakpoint Cmdlet 會在目前工作階段內的任一指令碼或任何命令中設定中斷點。在執行指令碼或命令之前、在偵錯期間或當停在另一個中斷點時,都可以使用 Set-PSBreakpoint 設定中斷點。 注意:Set-PSBreakpoint 無法在遠端電腦上設定中斷點。若要偵錯遠端電腦上的指令碼,請指令碼複製到本機電腦,然後在本機進行偵錯。 每個 Set-PSBreakpoint 命令都會建立下列其中一種中斷點: -- 行中斷點:在特定的行和欄座標設定中斷點。 -- 命令中斷點: 在行和函數上設定中斷點。 -- 變數中斷點:在變數上設定中斷點。 您可以用單一 Set-PSBreakpoint 命令在多行、多個命令或多個變數上設定中斷點,但是每個 Set-PSBreakpoint 命令只能設定一種中斷點。 在中斷點,Windows PowerShell 會暫停執行,並將控制權給予偵錯工具。命令提示字元會變更為 "DBG>",而一組偵錯工具命令會變成可用。不過,您可以使用 Action 參數來指定代替的回應,例如中斷點或指令執行其他工作 (如記錄或診斷) 的條件。 Set-PSBreakpoint Cmdlet 是其中幾個專為偵錯 Windows PowerShell 指令碼所設計的 Cmdlet。如需 Windows PowerShell 偵錯工具的詳細資訊,請參閱 about_Debuggers。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Set-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="true" pipelineInput="false" position="named"> <maml:name>Command</maml:name> <maml:description> <maml:para>設定命令中斷點。請輸入命令名稱,例如 "Get-Process" 或函數名稱。允許使用萬用字元。 執行會在每個命令的每個執行個體執行之前停止。如果命令為函數,執行會在函數被呼叫時停止,而且在 BEGIN、PROCESS 和 END 區段停止。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="1"> <maml:name>Script</maml:name> <maml:description> <maml:para>在每個指定的指令碼檔內設定中斷點。請輸入一個或多個指令碼檔的路徑和檔案名稱。如果這些檔案位於目前的目錄,就可以省略路徑。允許使用萬用字元。 根據預設,在任何於目前工作階段中執行的命令上都會設定變數中斷點和命令中斷點。只有在設定行中斷點時才必須提供此參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Action</maml:name> <maml:description> <maml:para>指定在每個中斷點執行的命令,而不是進行中斷。請輸入包含命令的指令碼區塊。您可以使用此參數,設定條件式中斷點或執行其他工作 (如測試或記錄)。 如果省略此參數或未指定任何動作,執行會在中斷點停止,而偵錯工具會啟動。 使用 Action 參數時,在每個中斷點都會執行 Action 指令碼區塊。除非指令碼區塊包含 Break 關鍵字,否則執行不會停止。如果在指令碼區塊中使用 Continue 關鍵字,執行會一直繼續到下一個中斷點。 如需詳細資訊,請參閱 about_Script_Blocks、about_Break 和 about_Continue。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Set-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="true" pipelineInput="false" position="1"> <maml:name>Script</maml:name> <maml:description> <maml:para>在每個指定的指令碼檔內設定中斷點。請輸入一個或多個指令碼檔的路徑和檔案名稱。如果這些檔案位於目前的目錄,就可以省略路徑。允許使用萬用字元。 根據預設,在任何於目前工作階段中執行的命令上都會設定變數中斷點和命令中斷點。只有在設定行中斷點時才必須提供此參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="2"> <maml:name>Line</maml:name> <maml:description> <maml:para>在指令碼內設定行中斷點。請輸入一個或多個行號 (以逗號分隔)。Windows PowerShell 會在執行每個指定的行開始的陳述式之前立即停止。 行是從指令碼檔的左上邊界算起,從 1 (非 0) 開始編號。如果指定空白行,執行會在下一個非空白行之前停止。如果該行超出範圍,中斷點將永遠不會被叫用。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Column</maml:name> <maml:description> <maml:para>指定指令碼檔中執行停止的欄號。請輸入一個欄號即可。預設為欄 1。 Column 值與 Line 參數的值搭配使用可以指定中斷點。如果 Line 參數指定多行,Column 參數會在指定的行的指定的欄設定中斷點。Windows PowerShell 會在指定的行和欄處有字元的陳述式或運算式之前停止執行。 欄是從左上邊界算起,從 1 (非 0) 開始編號。若指定的欄不存在於指令碼中,則不會宣告錯誤,但中斷點永遠不會執行。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Action</maml:name> <maml:description> <maml:para>指定在每個中斷點執行的命令,而不是進行中斷。請輸入包含命令的指令碼區塊。您可以使用此參數,設定條件式中斷點或執行其他工作 (如測試或記錄)。 如果省略此參數或未指定任何動作,執行會在中斷點停止,而偵錯工具會啟動。 使用 Action 參數時,在每個中斷點都會執行 Action 指令碼區塊。除非指令碼區塊包含 Break 關鍵字,否則執行不會停止。如果在指令碼區塊中使用 Continue 關鍵字,執行會一直繼續到下一個中斷點。 如需詳細資訊,請參閱 about_Script_Blocks、about_Break 和 about_Continue。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Set-PSBreakpoint</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Variable</maml:name> <maml:description> <maml:para>設定變數中斷點。請輸入以逗號分隔的變數 (不含貨幣符號 ($)) 清單。 Mode 參數可以用來決定觸發變數中斷點的存取模式。預設模式,Write,會在新值寫入變數之前停止執行。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="1"> <maml:name>Script</maml:name> <maml:description> <maml:para>在每個指定的指令碼檔內設定中斷點。請輸入一個或多個指令碼檔的路徑和檔案名稱。如果這些檔案位於目前的目錄,就可以省略路徑。允許使用萬用字元。 根據預設,在任何於目前工作階段中執行的命令上都會設定變數中斷點和命令中斷點。只有在設定行中斷點時才必須提供此參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Mode</maml:name> <maml:description> <maml:para>決定觸發變數中斷點的存取模式。預設為 Write。 只有當 Variable 參數用於命令中的時候此參數才有效。模式會套用到命令中所設定的所有中斷點。 有效的值包括: -- Write:在新值寫入變數之前立即停止執行。 -- Read:在讀取變數時 (也就是存取其值以進行指派、顯示或使用時) 停止執行。在讀取模式下,執行不會在變數的值變更時停止。 -- ReadWrite:在讀取或寫入變數時停止執行。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Read</command:parameterValue> <command:parameterValue required="false" variableLength="false">Write</command:parameterValue> <command:parameterValue required="false" variableLength="false">ReadWrite</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Action</maml:name> <maml:description> <maml:para>指定在每個中斷點執行的命令,而不是進行中斷。請輸入包含命令的指令碼區塊。您可以使用此參數,設定條件式中斷點或執行其他工作 (如測試或記錄)。 如果省略此參數或未指定任何動作,執行會在中斷點停止,而偵錯工具會啟動。 使用 Action 參數時,在每個中斷點都會執行 Action 指令碼區塊。除非指令碼區塊包含 Break 關鍵字,否則執行不會停止。如果在指令碼區塊中使用 Continue 關鍵字,執行會一直繼續到下一個中斷點。 如需詳細資訊,請參閱 about_Script_Blocks、about_Break 和 about_Continue。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Action</maml:name> <maml:description> <maml:para>指定在每個中斷點執行的命令,而不是進行中斷。請輸入包含命令的指令碼區塊。您可以使用此參數,設定條件式中斷點或執行其他工作 (如測試或記錄)。 如果省略此參數或未指定任何動作,執行會在中斷點停止,而偵錯工具會啟動。 使用 Action 參數時,在每個中斷點都會執行 Action 指令碼區塊。除非指令碼區塊包含 Break 關鍵字,否則執行不會停止。如果在指令碼區塊中使用 Continue 關鍵字,執行會一直繼續到下一個中斷點。 如需詳細資訊,請參閱 about_Script_Blocks、about_Break 和 about_Continue。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> <dev:type> <maml:name>scriptblock</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Column</maml:name> <maml:description> <maml:para>指定指令碼檔中執行停止的欄號。請輸入一個欄號即可。預設為欄 1。 Column 值與 Line 參數的值搭配使用可以指定中斷點。如果 Line 參數指定多行,Column 參數會在指定的行的指定的欄設定中斷點。Windows PowerShell 會在指定的行和欄處有字元的陳述式或運算式之前停止執行。 欄是從左上邊界算起,從 1 (非 0) 開始編號。若指定的欄不存在於指令碼中,則不會宣告錯誤,但中斷點永遠不會執行。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="true" pipelineInput="false" position="named"> <maml:name>Command</maml:name> <maml:description> <maml:para>設定命令中斷點。請輸入命令名稱,例如 "Get-Process" 或函數名稱。允許使用萬用字元。 執行會在每個命令的每個執行個體執行之前停止。如果命令為函數,執行會在函數被呼叫時停止,而且在 BEGIN、PROCESS 和 END 區段停止。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="2"> <maml:name>Line</maml:name> <maml:description> <maml:para>在指令碼內設定行中斷點。請輸入一個或多個行號 (以逗號分隔)。Windows PowerShell 會在執行每個指定的行開始的陳述式之前立即停止。 行是從指令碼檔的左上邊界算起,從 1 (非 0) 開始編號。如果指定空白行,執行會在下一個非空白行之前停止。如果該行超出範圍,中斷點將永遠不會被叫用。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Int32[]</command:parameterValue> <dev:type> <maml:name>Int32[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Mode</maml:name> <maml:description> <maml:para>決定觸發變數中斷點的存取模式。預設為 Write。 只有當 Variable 參數用於命令中的時候此參數才有效。模式會套用到命令中所設定的所有中斷點。 有效的值包括: -- Write:在新值寫入變數之前立即停止執行。 -- Read:在讀取變數時 (也就是存取其值以進行指派、顯示或使用時) 停止執行。在讀取模式下,執行不會在變數的值變更時停止。 -- ReadWrite:在讀取或寫入變數時停止執行。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">VariableAccessMode</command:parameterValue> <dev:type> <maml:name>VariableAccessMode</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="1"> <maml:name>Script</maml:name> <maml:description> <maml:para>在每個指定的指令碼檔內設定中斷點。請輸入一個或多個指令碼檔的路徑和檔案名稱。如果這些檔案位於目前的目錄,就可以省略路徑。允許使用萬用字元。 根據預設,在任何於目前工作階段中執行的命令上都會設定變數中斷點和命令中斷點。只有在設定行中斷點時才必須提供此參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Variable</maml:name> <maml:description> <maml:para>設定變數中斷點。請輸入以逗號分隔的變數 (不含貨幣符號 ($)) 清單。 Mode 參數可以用來決定觸發變數中斷點的存取模式。預設模式,Write,會在新值寫入變數之前停止執行。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至 Set-PSBreakpoint。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>中斷點物件 (System.Management.Automation.LineBreakpoint、System.Management.Automation.VariableBreakpoint、System.Management.Automation.CommandBreakpoint)</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Set-PSBreakpoint 會傳回代表它所設定之每個中斷點的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> Set-PSBreakpoint 無法在遠端電腦上設定中斷點。若要偵錯遠端電腦上的指令碼,請指令碼複製到本機電腦,然後在本機進行偵錯。 當您在一個以上的行、命令或函數上設定中斷點時,Set-PSBreakpoint 會為每個項目產生中斷點物件。 在命令列提示字元下設定函數或變數上的中斷點時,可以在建立函數或變數之前或之後設定中斷點。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-psbreakpoint -script sample.ps1 -line 5 Column : 0 Line : 5 Action : Enabled : True HitCount : 0 Id : 0 Script : C:\ps-test\sample.ps1 ScriptName : C:\ps-test\sample.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在 Sample.ps1 指令碼的第 5 行設定中斷點。因此,指令碼執行時,執行會在第 5 行要執行之前立即停止。 當您依行號設定新的中斷點時,Set-PSBreakpoint Cmdlet 會產生行中斷點物件 (System.Management.Automation.LineBreakpoint),其包含中斷點識別碼和叫用次數,如下列範例輸出所示。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-psbreakpoint -command Increment -script sample.ps1 Command : Increment Action : Enabled : True HitCount : 0 Id : 1 Script : C:\ps-test\sample.ps1 ScriptName : C:\ps-test\sample.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在 Sample.ps1 Cmdlet 的 Increment 函數上建立命令中斷點。此指令碼會在每次呼叫指定的函數之前立即停止執行。 結果為命令中斷點物件。此指令碼執行之前,HitCount 屬性的值為 0。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-psbreakpoint -script sample.ps1 -variable Server -Mode ReadWrite </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在 Sample.ps1 指令碼的 Server 變數上設定中斷點,並使用 Mode 參數搭配 ReadWrite 的值,以便在讀取變數的值時而且在值變更之前停止執行。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-psbreakpoint -script Sample.ps1 -command "write*" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在 Sample.ps1 指令碼中所有開頭為 "write" (如 "write-host") 的命令上設定中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-psbreakpoint -script test.ps1 -command DiskTest ` -action { (if $disk -gt 2) { break } } </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在只有當 $disk 變數的值大於 2 時,才在 Test.ps1 指令碼的 DiskTest 函數處停止執行。 它會使用 Set-PSBreakpoint Cmdlet,在 DiskTest 函數上設定命令中斷點。動作的值為指令碼區塊,以便測試此函數中 $disk 變數的值。 如果條件符合,動作會使用 BREAK 關鍵字停止執行。替代 (和預設) 的關鍵字為 CONTINUE。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-psbreakpoint -command checkpoint-computer Id : 0 Command : checkpoint-computer Enabled : True HitCount : 0 Action : C:\PS> function CheckLog { >> get-eventlog -log Application | >> where {($_.source -like "TestApp") -and ($_.Message -like "*failed*")} >>} >> C:\PS> Checklog DEBUG: Hit breakpoint(s) DEBUG: Function breakpoint on 'prompt:Checklog' C:\PS>>> </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在 CheckLog 函數上設定中斷點。因為這個命令沒有指定指令碼,中斷點會設定在目前工作階段內執行的任何項目上。在呼叫 (而非宣告) 該函數時,偵錯工具會進入命令列。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-psbreakpoint -script sample.ps1 -line 1, 14, 19 -column 2 -action {&(log.ps1)} Column : 2 Line : 1 Action : Enabled : True HitCount : 0 Id : 6 Script : C:\ps-test\sample.ps1 ScriptName : C:\ps-test\sample.ps1 Column : 2 Line : 14 Action : Enabled : True HitCount : 0 Id : 7 Script : C:\ps-test\sample.ps1 ScriptName : C:\ps-test\sample.ps1 Column : 2 Line : 19 Action : Enabled : True HitCount : 0 Id : 8 Script : C:\ps-test\sample.ps1 ScriptName : C:\ps-test\sample.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在 Sample.ps1 指令碼中設定三個行中斷點,並在指令碼中指定的每一行的第 2 欄設定中斷點。Action 參數中指定的動作會套用到所有中斷點。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113449</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Debuggers</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Enable-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Disable-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-PSBreakpoint</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-PSCallStack</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Set-TraceSource </command:name> <maml:description> <maml:para>設定、啟動和停止追蹤 Windows PowerShell 元件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Set</command:verb> <command:noun>TraceSource</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Set-TraceSource Cmdlet 會設定、啟動和停止追蹤 Windows PowerShell 元件。您可以使用它來指定所要追蹤的元件以及傳送追蹤輸出的目的地。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Set-TraceSource</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Option</maml:name> <maml:description> <maml:para>決定所要追蹤的事件類型。 有效的值包括:"None"、"Constructor"、"Dispose"、"Finalizer"、"Method"、"Property"、"Delegates"、"Events"、"Exception"、"Lock"、"Error"、"Errors"、"Warning"、"Verbose"、"WriteLine"、"Data"、"Scope"、"ExecutionFlow"、"Assert" 和 "All"。預設值為 "All"。 下列值是其他值的組合: -- ExecutionFlow:(Constructor、Dispose、Finalizer、Method、Delegates、Events 和 Scope) -- Data:(Constructor、Dispose、Finalizer、Property、Verbose 和 WriteLine) -- Errors:(Error 和 Exception)。 若要指定多重選項,請用逗號分隔選項,但不能包含空格,然後置於引號內,例如 "Constructor,Dispose"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">Constructor</command:parameterValue> <command:parameterValue required="false" variableLength="false">Dispose</command:parameterValue> <command:parameterValue required="false" variableLength="false">Finalizer</command:parameterValue> <command:parameterValue required="false" variableLength="false">Method</command:parameterValue> <command:parameterValue required="false" variableLength="false">Property</command:parameterValue> <command:parameterValue required="false" variableLength="false">Delegates</command:parameterValue> <command:parameterValue required="false" variableLength="false">Events</command:parameterValue> <command:parameterValue required="false" variableLength="false">Exception</command:parameterValue> <command:parameterValue required="false" variableLength="false">Lock</command:parameterValue> <command:parameterValue required="false" variableLength="false">Error</command:parameterValue> <command:parameterValue required="false" variableLength="false">Errors</command:parameterValue> <command:parameterValue required="false" variableLength="false">Warning</command:parameterValue> <command:parameterValue required="false" variableLength="false">Verbose</command:parameterValue> <command:parameterValue required="false" variableLength="false">WriteLine</command:parameterValue> <command:parameterValue required="false" variableLength="false">Data</command:parameterValue> <command:parameterValue required="false" variableLength="false">Scope</command:parameterValue> <command:parameterValue required="false" variableLength="false">ExecutionFlow</command:parameterValue> <command:parameterValue required="false" variableLength="false">Assert</command:parameterValue> <command:parameterValue required="false" variableLength="false">All</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Debugger</maml:name> <maml:description> <maml:para>將追蹤輸出傳送至偵錯工具。您可以使用任何使用者模式或核心模式偵錯工具來檢視輸出,或在 Microsoft Visual Studio 中檢視輸出。此參數也會選取預設的追蹤接聽程式。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>FilePath</maml:name> <maml:description> <maml:para>將追蹤輸出傳送到指定的檔案。此參數也會選取檔案追蹤接聽程式。若您使用此參數啟動追蹤,請使用 RemoveFileListener 參數停止追蹤。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 覆寫唯讀的檔案。請搭配 FilePath 參數使用。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ListenerOption</maml:name> <maml:description> <maml:para>在輸出中的每個追蹤訊息開頭加入選用性資料。有效的值包括 "None"、"LogicalOperationStack"、"DateTime"、"Timestamp"、"ProcessId"、"ThreadId" 和 "Callstack"。預設值為 "None"。 若要指定多重選項,請用逗號分隔選項,但不能包含空格,然後置於引號內,例如 "ProcessID,ThreadID"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">LogicalOperationStack</command:parameterValue> <command:parameterValue required="false" variableLength="false">DateTime</command:parameterValue> <command:parameterValue required="false" variableLength="false">Timestamp</command:parameterValue> <command:parameterValue required="false" variableLength="false">ProcessId</command:parameterValue> <command:parameterValue required="false" variableLength="false">ThreadId</command:parameterValue> <command:parameterValue required="false" variableLength="false">Callstack</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表追蹤工作階段的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PSHost</maml:name> <maml:description> <maml:para>將追蹤輸出傳送至 Windows PowerShell 主機。此參數也會選取 PSHost 追蹤接聽程式。</maml:para> </maml:description> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>決定所要追蹤的元件。輸入每個元件的追蹤來源的名稱。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Set-TraceSource</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>RemoveListener</maml:name> <maml:description> <maml:para>移除追蹤接聽程式藉以停止追蹤。 可用的 RemoveListener 值如下: -- 若要移除 PSHost (主控台),請輸入 "Host"。 -- 若要移除偵錯工具,請輸入 "Debug"。 -- 若要移除所有的追蹤接聽程式,請輸入 "*"。 若要移除檔案追蹤接聽程式,請使用 RemoveFileListener 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>決定所要追蹤的元件。輸入每個元件的追蹤來源的名稱。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Set-TraceSource</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>RemoveFileListener</maml:name> <maml:description> <maml:para>移除與指定檔案相關聯的檔案追蹤接聽程式,藉以停止追蹤。輸入追蹤輸出檔的路徑和檔名。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>決定所要追蹤的元件。輸入每個元件的追蹤來源的名稱。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Debugger</maml:name> <maml:description> <maml:para>將追蹤輸出傳送至偵錯工具。您可以使用任何使用者模式或核心模式偵錯工具來檢視輸出,或在 Microsoft Visual Studio 中檢視輸出。此參數也會選取預設的追蹤接聽程式。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>FilePath</maml:name> <maml:description> <maml:para>將追蹤輸出傳送到指定的檔案。此參數也會選取檔案追蹤接聽程式。若您使用此參數啟動追蹤,請使用 RemoveFileListener 參數停止追蹤。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 覆寫唯讀的檔案。請搭配 FilePath 參數使用。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ListenerOption</maml:name> <maml:description> <maml:para>在輸出中的每個追蹤訊息開頭加入選用性資料。有效的值包括 "None"、"LogicalOperationStack"、"DateTime"、"Timestamp"、"ProcessId"、"ThreadId" 和 "Callstack"。預設值為 "None"。 若要指定多重選項,請用逗號分隔選項,但不能包含空格,然後置於引號內,例如 "ProcessID,ThreadID"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">TraceOptions</command:parameterValue> <dev:type> <maml:name>TraceOptions</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>決定所要追蹤的元件。輸入每個元件的追蹤來源的名稱。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="2"> <maml:name>Option</maml:name> <maml:description> <maml:para>決定所要追蹤的事件類型。 有效的值包括:"None"、"Constructor"、"Dispose"、"Finalizer"、"Method"、"Property"、"Delegates"、"Events"、"Exception"、"Lock"、"Error"、"Errors"、"Warning"、"Verbose"、"WriteLine"、"Data"、"Scope"、"ExecutionFlow"、"Assert" 和 "All"。預設值為 "All"。 下列值是其他值的組合: -- ExecutionFlow:(Constructor、Dispose、Finalizer、Method、Delegates、Events 和 Scope) -- Data:(Constructor、Dispose、Finalizer、Property、Verbose 和 WriteLine) -- Errors:(Error 和 Exception)。 若要指定多重選項,請用逗號分隔選項,但不能包含空格,然後置於引號內,例如 "Constructor,Dispose"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSTraceSourceOptions</command:parameterValue> <dev:type> <maml:name>PSTraceSourceOptions</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表追蹤工作階段的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PSHost</maml:name> <maml:description> <maml:para>將追蹤輸出傳送至 Windows PowerShell 主機。此參數也會選取 PSHost 追蹤接聽程式。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>RemoveFileListener</maml:name> <maml:description> <maml:para>移除與指定檔案相關聯的檔案追蹤接聽程式,藉以停止追蹤。輸入追蹤輸出檔的路徑和檔名。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>RemoveListener</maml:name> <maml:description> <maml:para>移除追蹤接聽程式藉以停止追蹤。 可用的 RemoveListener 值如下: -- 若要移除 PSHost (主控台),請輸入 "Host"。 -- 若要移除偵錯工具,請輸入 "Debug"。 -- 若要移除所有的追蹤接聽程式,請輸入 "*"。 若要移除檔案追蹤接聽程式,請使用 RemoveFileListener 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含名稱的字串輸出至 Set-TraceSource。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.PSTraceSource</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 PassThru 參數時,Set-TraceSource 會產生代表追蹤工作階段的 System.Management.Automation.PSTraceSource 物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 追蹤是開發人員用來偵錯和調整程式的一種方法。進行追蹤時,程式會產生詳細訊息列出每個內部處理步驟的相關資訊。 Windows PowerShell 追蹤 cmdlet 是專為輔助 Windows PowerShell 開發人員而設計,但所有的使用者皆可使用。這些 Cmdlet 幾乎可以監視 Windows PowerShell 每個層面的功能。 「追蹤來源」是每個 Windows PowerShell 元件的一部分,負責管理追蹤並產生元件的追蹤訊息。若要追蹤元件,您必須識別元件的追蹤來源。 「追蹤接聽程式」則接收追蹤的輸出,並顯示輸出供使用者檢視。您可以選擇將追蹤資料傳送到使用者模式或核心模式偵錯工具、主控台、檔案,或者傳送到衍生自 System.Diagnostics.TraceListener 類別的自訂接聽程式。 若要啟動追蹤,請使用 Name 參數指定追蹤來源 (要追蹤的元件),並使用 FilePath、Debugger 或 PSHost 參數指定接聽程式 (輸出的目的地)。使用 Options 參數決定要追蹤的事件類型,並使用 ListenerOptions 參數設定追蹤輸出。 若要變更追蹤的組態,請輸入 Set-TraceSource 命令,如同啟動追蹤時所做的。Windows PowerShell 察覺追蹤來源已經在追蹤當中,便會停止追蹤、加入新組態,然後啟動或重新啟動追蹤。 若要停止追蹤,請使用 RemoveListener 參數。若要將使用檔案接聽程式 (使用 -FilePath 參數啟動的追蹤) 的追蹤停止,請使用 RemoveFileListener 參數。當您移除接聽程式時,追蹤就會停止。 若要判斷可以追蹤哪些元件,請使用 Get-TraceSource。每個模組的追蹤來源會在元件處於使用中狀態時自動載入,並且會在 Get-TraceSource 的輸出中出現。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> Set-TraceSource -Name Parameterbinding -Option ExecutionFlow -PSHost ' -ListenerOption "ProcessID,TimeStamp" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會為 Windows PowerShell 的 ParameterBinding 元件啟動追蹤。它使用 Name 參數指定追蹤來源;使用 Options 參數選取 ExecutionFlow 追蹤事件;並使用 PSHost 參數選取 Windows PowerShell 主機接聽程式,以將輸出傳送到主控台。ListenerOption 參數會在追蹤訊息開頭加入 "ProcessID" 和 "TimeStamp" 值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-tracesource -name ParameterBinding -RemoveListener Host </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會停止追蹤 Windows PowerShell 的 ParameterBinding 元件。它使用 Name 參數識別正在追蹤的元件,並使用 RemoveListener 參數識別追蹤接聽程式。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113400</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-TraceSource</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Trace-Command</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-PSDebug</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Set-Variable </command:name> <maml:description> <maml:para>設定變數的值。如果所要求之名稱的變數不存在,即建立變數。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Set</command:verb> <command:noun>Variable</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Set-Variable Cmdlet 會將值指派給指定的變數,或變更目前的值。如果變數不存在,此 Cmdlet 會加以建立。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Set-Variable</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定變數名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="2"> <maml:name>Value</maml:name> <maml:description> <maml:para>指定變數的值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Description</maml:name> <maml:description> <maml:para>指定變數的描述。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。此參數的值用於限定 Path 參數。輸入路徑元素或模式,例如 "*.txt"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許建立與現有唯讀變數同名的變數,或變更唯讀變數的值。 根據預設,除非變數的選項值為 "ReadOnly" 或 "Constant",否則可以覆寫變數。如需詳細資訊,請參閱 Option 參數。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>只變更指定的項目。此參數的值用於限定 Name 參數。請輸入名稱或名稱模式,例如 "c*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Option</maml:name> <maml:description> <maml:para>變更變數的 Options 屬性值。有效的值包括: -- None:不設定選項。(預設值為 "None")。 -- ReadOnly:無法變更變數的屬性,除非使用 Force 參數。您可以使用 Remove-Variable 刪除變數。 -- Constant:無法刪除變數,且無法變更其屬性。只有建立別名時才能使用 "Constant"。您無法將現有變數的選項變更為 "Constant"。 -- Private:變數只在 Scope 參數所指定的範圍內有效。此範圍由子範圍繼承。 -- AllScope:將變數複製到所有新建立的範圍。 若要查看變數的 Options 屬性,請輸入 "get-variable| format-table -property name, options -autosize"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">ReadOnly</command:parameterValue> <command:parameterValue required="false" variableLength="false">Constant</command:parameterValue> <command:parameterValue required="false" variableLength="false">Private</command:parameterValue> <command:parameterValue required="false" variableLength="false">AllScope</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表新變數的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>決定變數的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Visibility</maml:name> <maml:description> <maml:para>決定變數是否可在其建立所在的工作階段以外顯示。此參數是專為用在提供給其他使用者的指令碼和命令所設計。 有效的值包括: -- Public:看得到變數 (預設值為 "Public")。 -- Private:看不到變數。 變數為私用時,不會出現在變數的清單 (例如由 Get-Variable 傳回的清單),也不會在 Variable:磁碟機中顯示。對私用變數的值進行讀取或變更的命令會傳回錯誤。但是,如果使用私用變數的命令是在該變數定義所在的工作階段中撰寫的,使用者就可以執行這種命令。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Public</command:parameterValue> <command:parameterValue required="false" variableLength="false">Private</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Description</maml:name> <maml:description> <maml:para>指定變數的描述。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Exclude</maml:name> <maml:description> <maml:para>忽略指定的項目。此參數的值用於限定 Path 參數。輸入路徑元素或模式,例如 "*.txt"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許建立與現有唯讀變數同名的變數,或變更唯讀變數的值。 根據預設,除非變數的選項值為 "ReadOnly" 或 "Constant",否則可以覆寫變數。如需詳細資訊,請參閱 Option 參數。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Include</maml:name> <maml:description> <maml:para>只變更指定的項目。此參數的值用於限定 Name 參數。請輸入名稱或名稱模式,例如 "c*"。允許使用萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>指定變數名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Option</maml:name> <maml:description> <maml:para>變更變數的 Options 屬性值。有效的值包括: -- None:不設定選項。(預設值為 "None")。 -- ReadOnly:無法變更變數的屬性,除非使用 Force 參數。您可以使用 Remove-Variable 刪除變數。 -- Constant:無法刪除變數,且無法變更其屬性。只有建立別名時才能使用 "Constant"。您無法將現有變數的選項變更為 "Constant"。 -- Private:變數只在 Scope 參數所指定的範圍內有效。此範圍由子範圍繼承。 -- AllScope:將變數複製到所有新建立的範圍。 若要查看變數的 Options 屬性,請輸入 "get-variable| format-table -property name, options -autosize"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">ScopedItemOptions</command:parameterValue> <dev:type> <maml:name>ScopedItemOptions</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PassThru</maml:name> <maml:description> <maml:para>傳回代表新變數的物件。根據預設,此 Cmdlet 不會產生任何輸出。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Scope</maml:name> <maml:description> <maml:para>決定變數的範圍。有效的值包括 "Global"、"Local"、"Script" 或相對於目前範圍的數字 (從 0 到範圍總數,其中 0 代表目前範圍,1 代表其上層)。預設值為 "Local"。如需詳細資訊,請參閱 about_Scopes。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="2"> <maml:name>Value</maml:name> <maml:description> <maml:para>指定變數的值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Visibility</maml:name> <maml:description> <maml:para>決定變數是否可在其建立所在的工作階段以外顯示。此參數是專為用在提供給其他使用者的指令碼和命令所設計。 有效的值包括: -- Public:看得到變數 (預設值為 "Public")。 -- Private:看不到變數。 變數為私用時,不會出現在變數的清單 (例如由 Get-Variable 傳回的清單),也不會在 Variable:磁碟機中顯示。對私用變數的值進行讀取或變更的命令會傳回錯誤。但是,如果使用私用變數的命令是在該變數定義所在的工作階段中撰寫的,使用者就可以執行這種命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">SessionStateEntryVisibility</command:parameterValue> <dev:type> <maml:name>SessionStateEntryVisibility</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>Public</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Object</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將代表變數值的物件輸出至 Set-Variable。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無或 System.Management.Automation.PSVariable</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 當您使用 PassThru 參數時,Set-Variable 會產生代表新或變更變數的 System.Management.Automation.PSVariable 物件。否則,這個 Cmdlet 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-variable -name desc -value "A description" C:\PS>get-variable -name desc </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會將 "desc" 變數的值設為 "A description",然後取得變數的值。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> set-variable -name processes -value (Get-Process) -option constant -scope global -description "All processes" -passthru | format-list -property * </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會建立含有系統中所有處理序的全域唯讀變數,然後顯示變數的所有屬性。 此命令會使用 Set-Variable Cmdlet 來建立變數。它會使用 PassThru 參數建立代表新變數的物件,然後使用管線運算子 (|) 將該物件傳遞給 Format-List Cmdlet。它會將 Format-List 的 Property 參數值設定為全部 (*),用以顯示新建立變數的所有屬性。 "(Get-Process)" 這個值是放在括弧內,確保會在儲存至變數之前執行它。否則,變數會包含單字 "Get-Process"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> # set-variable -name counter -visibility private C:\PS> new-variable -name counter -visibility public -value 26 C:\PS> $counter 26 C:\PS> get-variable c* Name Value ---- ----- Culture en-US ConsoleFileName ConfirmPreference High CommandLineParameters {} Counter 26 C:\PS> set-variable -name counter -visibility private C:\PS> get-variable c* Name Value ---- ----- Culture en-US ConsoleFileName ConfirmPreference High CommandLineParameters {} C:\PS> $counter "Cannot access the variable '$counter' because it is a private variable" C:\PS> .\use-counter.ps1 Commands completed successfully. </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會示範如何將變數的可見度變更為 "Private"。此變數可由具備必要權限的指令碼來讀取和變更,但使用者無法看到它。 範例輸出會顯示公用變數與私用變數之間的行為差異。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113401</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Clear-Variable</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Sort-Object </command:name> <maml:description> <maml:para>依據屬性值排序物件。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Sort</command:verb> <command:noun>Object</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Sort-Object Cmdlet 會依據物件的屬性值以遞減或遞減順序來排序物件。 您可以指定一個屬性或多個屬性 (用於多重索引鍵排序),並選取區分大小寫的排序或不區分大小寫的排序。也可以指示 Sort-Object 只顯示特定屬性有唯一值的物件。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Sort-Object</maml:name> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定排序時所要使用的屬性。物件是依據這些屬性的值來排序。請輸入屬性的名稱。允許使用萬用字元。 如果指定多個屬性,會先依據第一個屬性排序物件。如果有一個以上的物件的值與第一個屬性的值相同,會再依據第二個屬性排序。這個過程會持續到已無指定的屬性可套用,或不再有物件群組需要排序為止。 如果未指定屬性,Cmdlet 會依據物件型別的預設屬性進行排序。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Expression <字串> 或 <指令碼區塊> -- Ascending <布林值> -- Descending <布林值> </maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CaseSensitive</maml:name> <maml:description> <maml:para>指出排序應區分大小寫。根據預設,排序不會區分大小寫。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Culture</maml:name> <maml:description> <maml:para>指定排序時使用的文化特性設定。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Descending</maml:name> <maml:description> <maml:para>物件以遞減順序排序。預設為遞增順序。 Descending 參數會套用到所有屬性。若要以遞增順序 排序一些屬性,以遞減順序排序其他屬性,就必須使用雜湊表指定屬性值。如需詳細資料,請參閱範例。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要排序的物件。 當您使用 InputObject 參數送出項目的集合時,Sort-Object 會接收一個代表集合的物件。因為一個物件無法進行排序,Sort-Object 將原封不動地傳回整個集合。 若要排序物件,請經由管道將物件輸出至 Sort-Object。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Unique</maml:name> <maml:description> <maml:para>排除重複的成員,並只傳回集合的唯一成員。此參數可以用來代替 Get-Unique Cmdlet。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CaseSensitive</maml:name> <maml:description> <maml:para>指出排序應區分大小寫。根據預設,排序不會區分大小寫。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Culture</maml:name> <maml:description> <maml:para>指定排序時使用的文化特性設定。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Descending</maml:name> <maml:description> <maml:para>物件以遞減順序排序。預設為遞增順序。 Descending 參數會套用到所有屬性。若要以遞增順序 排序一些屬性,以遞減順序排序其他屬性,就必須使用雜湊表指定屬性值。如需詳細資料,請參閱範例。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要排序的物件。 當您使用 InputObject 參數送出項目的集合時,Sort-Object 會接收一個代表集合的物件。因為一個物件無法進行排序,Sort-Object 將原封不動地傳回整個集合。 若要排序物件,請經由管道將物件輸出至 Sort-Object。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="true" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>指定排序時所要使用的屬性。物件是依據這些屬性的值來排序。請輸入屬性的名稱。允許使用萬用字元。 如果指定多個屬性,會先依據第一個屬性排序物件。如果有一個以上的物件的值與第一個屬性的值相同,會再依據第二個屬性排序。這個過程會持續到已無指定的屬性可套用,或不再有物件群組需要排序為止。 如果未指定屬性,Cmdlet 會依據物件型別的預設屬性進行排序。 Property 參數的值可以是新的計算屬性。若要建立計算屬性,請使用雜湊表。有效的索引鍵包括: -- Expression <字串> 或 <指令碼區塊> -- Ascending <布林值> -- Descending <布林值> </maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Unique</maml:name> <maml:description> <maml:para>排除重複的成員,並只傳回集合的唯一成員。此參數可以用來代替 Get-Unique Cmdlet。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將要排序的物件輸出至 Sort-Object。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Sort-Object 會傳回已排序的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> Sort-Object 會依據您所指定的屬性或該物件型別的預設排序屬性來排序物件。 如果物件沒有其中一個指定的屬性,Cmdlet 會將該物件的屬性值解譯為 NULL,並放在排序順序的最後。 排序物件時,Sort-Object 會使用每個屬性的 Compare 方法。如果屬性沒有實作 IComparable,Cmdlet 會將屬性值轉換成字串,並使用 System.String 的 Compare 方法。 Sort-Object Cmdlet 會依據物件的屬性值以遞減或遞減順序來排序物件。 如果排序依據的屬性值為列舉,Sort-Object 會以數值順序來排序列舉值,不會對列舉成員名稱進行排序。例如,若依據狀態排序服務,狀態為 "Stopped" 的服務會出現在狀態為 "Running" 的服務的前面,因為 Status 的值為 ServiceControllerStatus 列舉,其中 "Stopped" 的值為 1,而 "Running" 的值為 4。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | sort-object Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 9/13/2005 4:24 PM 0 0 -a--- 9/6/2005 4:19 PM 12 a.csv -a--- 9/21/2005 3:49 PM 529 a.Ps -a--- 8/22/2005 4:14 PM 22 a.pl -a--- 9/27/2005 10:33 AM 24 a.txt -a--- 9/15/2005 10:31 AM 398 a.vbs -a--- 7/21/2005 12:39 PM 37066 a.xml -a--- 8/28/2005 11:30 PM 5412 a.xslt -a--- 10/25/2005 1:59 PM 125 AdamTravel.txt -a--- 7/21/2005 9:49 AM 59 add2Num.Ps -a--- 8/29/2005 5:42 PM 7111 add-content.xml -a--- 9/21/2005 12:46 PM 8771 aliens.Ps -a--- 8/10/2005 2:10 PM 798 array.xml -a--- 8/4/2004 5:00 AM 110 AUTORUN.INF -a--- 9/6/2005 4:20 PM 245 b.csv ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會對目前目錄中的子目錄和檔案進行排序。因為未指定任何屬性,這個命令會依據檔案和目錄的預設排序屬性、Name,以遞增字母順序來進行排序。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | sort-object -property length Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 12/3/2006 5:35 PM 2 pref.txt -a--- 9/6/2006 3:33 PM 15 count.txt -a--- 7/26/2006 10:01 AM 30 filenoext -a--- 8/18/2006 9:02 AM 52 temp.ps1 -a--- 8/18/2006 9:02 AM 52 temp.msh -a--- 9/6/2006 3:33 PM 56 fivewords.txt -a--- 7/26/2006 9:28 AM 80 date.csv -a--- 7/29/2006 7:15 PM 84 test2.txt -a--- 7/29/2006 7:15 PM 84 test.ps1 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會依照檔案長度的遞增順序,顯示目前目錄中的檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | sort-object -property WS | select-object -last 5 Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 1105 25 44236 18932 197 93.81 2032 iexplore 2526 66 37668 36836 221 393.27 868 svchost 974 19 22844 45928 371 88.39 3952 WINWORD 1371 22 42192 61872 323 75.75 1584 INFOPATH 2145 58 93088 70680 619 396.69 3908 OUTLOOK </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會依據處理序的工作組大小,顯示電腦上佔用最多記憶體的五個處理序。 該命令會使用 Get-Process Cmdlet 取得處理序清單,並使用管線運算子 (|) 將結果傳遞給 Sort-Object Cmdlet,讓後者依照工作組順序來排序物件。 另一個管線運算子會將結果傳送給 Select-Object,讓後者只顯示清單中的後五個項目。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-history | sort-object -descending Id CommandLine -- ----------- 51 get-history | sort -descending 50 get-history | sort -descending 49 get-history | sort -descending 48 get-history | sort -descending 47 get-history | sort -descending 46 get-history | sort -descending 45 get-history | sort -descending 44 cd $pshome 43 get-childitem | sort-object 42 gci *.txt </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令使用 Id 屬性做為預設索引鍵,以排序 HistoryInfo 物件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 5 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> C:\PS> get-service | sort-object -property ` @{Expression="Status";Descending=$true}, ` @{Expression="DisplayName";Descending=$false} Status Name DisplayName ------ ---- ----------- Running ALG Application Layer Gateway Service Running Ati HotKey Poller Ati HotKey Poller Running wuauserv Automatic Updates Running BITS Background Intelligent Transfer Ser... Running Client for NFS Client for NFS ... Stopped clr_optimizatio... .NET Runtime Optimization Service v... Stopped Alerter Alerter Stopped AppMgmt Application Management Stopped aspnet_state ASP.NET State Service Stopped ATI Smart ATI Smart Stopped ClipSrv ClipBook </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會以 Status 的遞減順序和 DisplayName 的遞增順序來顯示電腦上的服務。 該命令會使用 Get-Service Cmdlet 取得電腦上的服務,並使用管線運算子 (|) 將服務傳送給 Sort-Object Cmdlet。 為了讓一個屬性依照遞增順序排序,另一個屬性依照遞減順序排序,該命令會為 Property 參數的值使用雜湊表。此雜湊表會以 Expression 索引鍵來指定屬性名稱,並以 Ascending 或 Descending 索引鍵來指定排序順序。 依照遞減順序排序 Status 值所產生的檢視,會將 Status 值為 "Running" 的屬性列在 Status 值為 "Stopped" 的屬性的前面。依照遞增順序排序時,"Stopped" 會出現在 "Running" 的前面,因為 Status 為列舉屬性,其中 "Stopped" 的值 (1) 小於 "Running" 的值 (4)。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 6 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem *.txt | sort-object -property @{Expression={$_.LastWriteTime - $_.CreationTime}; Ascending=$false} | Format-Table LastWriteTime, CreationTime LastWriteTime CreationTime ------------- ------------ 2/21/2006 10:22:20 AM 10/3/2005 4:19:40 PM 2/27/2006 8:14:24 AM 2/23/2006 10:41:08 PM 2/24/2006 1:26:19 PM 2/23/2006 11:23:36 PM 1/5/2006 12:01:35 PM 1/5/2006 11:35:30 AM 2/24/2006 9:25:40 AM 2/24/2006 9:22:24 AM 2/24/2006 9:40:01 AM 2/24/2006 9:39:41 AM 2/21/2006 10:21:30 AM 2/21/2006 10:21:30 AM </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令根據 CreationTime 與 LastWriteTime 之間的時間長度,依遞減順序排序文字檔。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 7 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-content servers.txt localhost test01 server01 server02 localhost server01 C:\PS> get-content servers.txt | sort-object -unique localhost server01 server02 test01 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會對文字檔中的伺服器名稱進行排序。第二個命令會使用 Sort-Object Cmdlet 搭配 Unique 參數,傳回內容不重複的排序清單。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113403</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Group-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Start-Sleep </command:name> <maml:description> <maml:para>讓指令碼或工作階段中的活動暫停一段指定的時間。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Start</command:verb> <command:noun>Sleep</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Start-Sleep Cmdlet 會讓指令碼或工作階段中的活動暫停一段指定的時間。此 Cmdlet 可以用在許多工作上,例如等候作業完成或是在進行重複作業之前暫停。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Start-Sleep</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named"> <maml:name>Milliseconds</maml:name> <maml:description> <maml:para>指定資源處在睡眠狀態的毫秒數。此參數可縮寫成 "-m"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Start-Sleep</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Seconds</maml:name> <maml:description> <maml:para>指定資源處在睡眠狀態的秒數。您可以省略參數名稱 ("Seconds") 或將它縮寫成 "-s"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named"> <maml:name>Milliseconds</maml:name> <maml:description> <maml:para>指定資源處在睡眠狀態的毫秒數。此參數可縮寫成 "-m"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>Seconds</maml:name> <maml:description> <maml:para>指定資源處在睡眠狀態的秒數。您可以省略參數名稱 ("Seconds") 或將它縮寫成 "-s"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Int32</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將秒數輸出至 Start-Sleep。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 這個 Cmdlet 不會傳回任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以利用內建的別名 "sleep" 來參照 Start-Sleep。如需詳細資訊,請參閱 about_Aliases。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> Start-Sleep -s 15 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會讓工作階段中的所有命令都進入 15 秒的睡眠狀態。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> Start-Sleep -m 500 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會讓工作階段中的所有命令都進入二分之一秒 (500 毫秒) 的睡眠狀態。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113407</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Tee-Object </command:name> <maml:description> <maml:para>將命令輸出儲存到檔案或變數,然後在主控台中顯示。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Tee</command:verb> <command:noun>Object</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Tee-Object Cmdlet 會以兩個方向 (像字母 "T") 傳送命令的輸出。此 Cmdlet 會將輸出儲存到檔案或變數,同時沿著管線向下傳送。如果 Tee-Object 是管線中的最後一個命令,命令輸出則會顯示在主控台中。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Tee-Object</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>FilePath</maml:name> <maml:description> <maml:para>指定 cmdlet 用來儲存物件的檔案。接受解析結果為單一檔案的萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要對 cmdlet 輸入的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Tee-Object</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Variable</maml:name> <maml:description> <maml:para>將輸入物件的參照指派給指定的變數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要對 cmdlet 輸入的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>FilePath</maml:name> <maml:description> <maml:para>指定 cmdlet 用來儲存物件的檔案。接受解析結果為單一檔案的萬用字元。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要對 cmdlet 輸入的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Variable</maml:name> <maml:description> <maml:para>將輸入物件的參照指派給指定的變數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將要重新導向的物件輸出至 Tee-Object。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Tee-Object 會傳回它重新導向的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 您也可以使用 Out-File Cmdlet 或重新導向運算子,兩者都會將輸出儲存到檔案,但不沿著管線向下傳送。 Tee-Object 在寫入檔案時會使用 Unicode 編碼。因此,不同編碼的檔案可能會造成輸出格式錯誤。若要指定編碼,請使用 Out-File Cmdlet。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process | tee-object -filepath C:\Test1\testfile2.txt Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 83 4 2300 4520 39 0.30 4032 00THotkey 272 6 1400 3944 34 0.06 3088 alg 81 3 804 3284 21 2.45 148 ApntEx 81 4 2008 5808 38 0.75 3684 Apoint ... </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令取得電腦中執行之處理序的清單,並將結果傳送到檔案。因為沒有指定第二個路徑,所以結果將會顯示在主控台中。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-process notepad | tee-object -variable proc | select-object processname,handles ProcessName Handles ----------- ------- notepad 43 notepad 37 notepad 38 notepad 38 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取得電腦中執行之處理序的清單,並將結果傳送到名為 "proc" 的變數。然後,它會經由管道將產生的物件輸出至 Select-Object,後者再接著選取 ProcessName 和 Handles 屬性。請注意,$proc 變數包含 Get-Process 所傳回的預設資訊。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113417</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Redirection</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Select-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Trace-Command </command:name> <maml:description> <maml:para>為指定的運算式或命令設定並啟動追蹤。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Trace</command:verb> <command:noun>Command</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Trace-Command Cmdlet 會為指定的運算式或命令設定並啟動追蹤。它的作用類似 Set-TraceSource,但是只能套用到指定的命令。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Trace-Command</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Command</maml:name> <maml:description> <maml:para>指定追蹤期間所要處理的命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>ArgumentList</maml:name> <maml:description> <maml:para>為追蹤的命令指定參數和參數值。ArgumentList 的別名為 Args。此功能特別有助於對動態參數進行偵錯。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>決定要追蹤的 Windows PowerShell 元件。輸入每個元件的追蹤來源的名稱。允許使用萬用字元。若要找出電腦上的追蹤來源,請輸入 "Get-TraceSource"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Option</maml:name> <maml:description> <maml:para>決定所要追蹤的事件類型。 有效的值包括 None、Constructor、Dispose、Finalizer、Method、Property、Delegates、Events、Exception、Lock、Error、Errors、Warning、Verbose、WriteLine、Data、Scope、ExecutionFlow、Assert 和 All。預設值為 "All"。 下列值是其他值的組合: -- ExecutionFlow:(Constructor、Dispose、Finalizer、Method、Delegates、Events 和 Scope) -- Data:(Constructor、Dispose、Finalizer、Property、Verbose 和 WriteLine) -- Errors:(Error 和 Exception)。 若要指定多重選項,請用逗號分隔選項,但不能包含空格,然後置於引號內,例如 "Constructor,Dispose"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">Constructor</command:parameterValue> <command:parameterValue required="false" variableLength="false">Dispose</command:parameterValue> <command:parameterValue required="false" variableLength="false">Finalizer</command:parameterValue> <command:parameterValue required="false" variableLength="false">Method</command:parameterValue> <command:parameterValue required="false" variableLength="false">Property</command:parameterValue> <command:parameterValue required="false" variableLength="false">Delegates</command:parameterValue> <command:parameterValue required="false" variableLength="false">Events</command:parameterValue> <command:parameterValue required="false" variableLength="false">Exception</command:parameterValue> <command:parameterValue required="false" variableLength="false">Lock</command:parameterValue> <command:parameterValue required="false" variableLength="false">Error</command:parameterValue> <command:parameterValue required="false" variableLength="false">Errors</command:parameterValue> <command:parameterValue required="false" variableLength="false">Warning</command:parameterValue> <command:parameterValue required="false" variableLength="false">Verbose</command:parameterValue> <command:parameterValue required="false" variableLength="false">WriteLine</command:parameterValue> <command:parameterValue required="false" variableLength="false">Data</command:parameterValue> <command:parameterValue required="false" variableLength="false">Scope</command:parameterValue> <command:parameterValue required="false" variableLength="false">ExecutionFlow</command:parameterValue> <command:parameterValue required="false" variableLength="false">Assert</command:parameterValue> <command:parameterValue required="false" variableLength="false">All</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Debugger</maml:name> <maml:description> <maml:para>將追蹤輸出傳送至偵錯工具。可使用任何的使用者模式或核心模式偵錯工具,或在 Visual Studio 中檢視輸出。此參數也會選取預設的追蹤接聽程式。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>FilePath</maml:name> <maml:description> <maml:para>將追蹤輸出傳送到指定的檔案。此參數也會選取檔案追蹤接聽程式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 將追蹤資訊附加至唯讀的檔案。請搭配 FilePath 參數使用。即便使用 Force 參數,此 Cmdlet 也無法覆寫安全性限制。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>為追蹤期間處理的運算式提供輸入項。 可輸入代表運算式所接受之輸入項的變數,或透過管線傳遞物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ListenerOption</maml:name> <maml:description> <maml:para>在輸出中的每個追蹤訊息開頭加入選用性資料。有效的值包括 None、LogicalOperationStack、DateTime、Timestamp、ProcessId、ThreadId 和 Callstack。預設值為 "None"。 若要指定多重選項,請用逗號分隔選項,但不能包含空格,然後置於引號內,例如 "ProcessID,ThreadID"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">LogicalOperationStack</command:parameterValue> <command:parameterValue required="false" variableLength="false">DateTime</command:parameterValue> <command:parameterValue required="false" variableLength="false">Timestamp</command:parameterValue> <command:parameterValue required="false" variableLength="false">ProcessId</command:parameterValue> <command:parameterValue required="false" variableLength="false">ThreadId</command:parameterValue> <command:parameterValue required="false" variableLength="false">Callstack</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PSHost</maml:name> <maml:description> <maml:para>將追蹤輸出傳送至 Windows PowerShell 主機。此參數也會選取 PSHost 追蹤接聽程式。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Trace-Command</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Expression</maml:name> <maml:description> <maml:para>指定追蹤期間所要處理的運算式。將運算式置於大括號 ({}) 內。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>決定要追蹤的 Windows PowerShell 元件。輸入每個元件的追蹤來源的名稱。允許使用萬用字元。若要找出電腦上的追蹤來源,請輸入 "Get-TraceSource"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Option</maml:name> <maml:description> <maml:para>決定所要追蹤的事件類型。 有效的值包括 None、Constructor、Dispose、Finalizer、Method、Property、Delegates、Events、Exception、Lock、Error、Errors、Warning、Verbose、WriteLine、Data、Scope、ExecutionFlow、Assert 和 All。預設值為 "All"。 下列值是其他值的組合: -- ExecutionFlow:(Constructor、Dispose、Finalizer、Method、Delegates、Events 和 Scope) -- Data:(Constructor、Dispose、Finalizer、Property、Verbose 和 WriteLine) -- Errors:(Error 和 Exception)。 若要指定多重選項,請用逗號分隔選項,但不能包含空格,然後置於引號內,例如 "Constructor,Dispose"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">Constructor</command:parameterValue> <command:parameterValue required="false" variableLength="false">Dispose</command:parameterValue> <command:parameterValue required="false" variableLength="false">Finalizer</command:parameterValue> <command:parameterValue required="false" variableLength="false">Method</command:parameterValue> <command:parameterValue required="false" variableLength="false">Property</command:parameterValue> <command:parameterValue required="false" variableLength="false">Delegates</command:parameterValue> <command:parameterValue required="false" variableLength="false">Events</command:parameterValue> <command:parameterValue required="false" variableLength="false">Exception</command:parameterValue> <command:parameterValue required="false" variableLength="false">Lock</command:parameterValue> <command:parameterValue required="false" variableLength="false">Error</command:parameterValue> <command:parameterValue required="false" variableLength="false">Errors</command:parameterValue> <command:parameterValue required="false" variableLength="false">Warning</command:parameterValue> <command:parameterValue required="false" variableLength="false">Verbose</command:parameterValue> <command:parameterValue required="false" variableLength="false">WriteLine</command:parameterValue> <command:parameterValue required="false" variableLength="false">Data</command:parameterValue> <command:parameterValue required="false" variableLength="false">Scope</command:parameterValue> <command:parameterValue required="false" variableLength="false">ExecutionFlow</command:parameterValue> <command:parameterValue required="false" variableLength="false">Assert</command:parameterValue> <command:parameterValue required="false" variableLength="false">All</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Debugger</maml:name> <maml:description> <maml:para>將追蹤輸出傳送至偵錯工具。可使用任何的使用者模式或核心模式偵錯工具,或在 Visual Studio 中檢視輸出。此參數也會選取預設的追蹤接聽程式。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>FilePath</maml:name> <maml:description> <maml:para>將追蹤輸出傳送到指定的檔案。此參數也會選取檔案追蹤接聽程式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 將追蹤資訊附加至唯讀的檔案。請搭配 FilePath 參數使用。即便使用 Force 參數,此 Cmdlet 也無法覆寫安全性限制。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>為追蹤期間處理的運算式提供輸入項。 可輸入代表運算式所接受之輸入項的變數,或透過管線傳遞物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ListenerOption</maml:name> <maml:description> <maml:para>在輸出中的每個追蹤訊息開頭加入選用性資料。有效的值包括 None、LogicalOperationStack、DateTime、Timestamp、ProcessId、ThreadId 和 Callstack。預設值為 "None"。 若要指定多重選項,請用逗號分隔選項,但不能包含空格,然後置於引號內,例如 "ProcessID,ThreadID"。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">None</command:parameterValue> <command:parameterValue required="false" variableLength="false">LogicalOperationStack</command:parameterValue> <command:parameterValue required="false" variableLength="false">DateTime</command:parameterValue> <command:parameterValue required="false" variableLength="false">Timestamp</command:parameterValue> <command:parameterValue required="false" variableLength="false">ProcessId</command:parameterValue> <command:parameterValue required="false" variableLength="false">ThreadId</command:parameterValue> <command:parameterValue required="false" variableLength="false">Callstack</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PSHost</maml:name> <maml:description> <maml:para>將追蹤輸出傳送至 Windows PowerShell 主機。此參數也會選取 PSHost 追蹤接聽程式。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>ArgumentList</maml:name> <maml:description> <maml:para>為追蹤的命令指定參數和參數值。ArgumentList 的別名為 Args。此功能特別有助於對動態參數進行偵錯。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Command</maml:name> <maml:description> <maml:para>指定追蹤期間所要處理的命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Debugger</maml:name> <maml:description> <maml:para>將追蹤輸出傳送至偵錯工具。可使用任何的使用者模式或核心模式偵錯工具,或在 Visual Studio 中檢視輸出。此參數也會選取預設的追蹤接聽程式。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Expression</maml:name> <maml:description> <maml:para>指定追蹤期間所要處理的運算式。將運算式置於大括號 ({}) 內。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">scriptblock</command:parameterValue> <dev:type> <maml:name>scriptblock</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>FilePath</maml:name> <maml:description> <maml:para>將追蹤輸出傳送到指定的檔案。此參數也會選取檔案追蹤接聽程式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>允許此 Cmdlet 將追蹤資訊附加至唯讀的檔案。請搭配 FilePath 參數使用。即便使用 Force 參數,此 Cmdlet 也無法覆寫安全性限制。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>為追蹤期間處理的運算式提供輸入項。 可輸入代表運算式所接受之輸入項的變數,或透過管線傳遞物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ListenerOption</maml:name> <maml:description> <maml:para>在輸出中的每個追蹤訊息開頭加入選用性資料。有效的值包括 None、LogicalOperationStack、DateTime、Timestamp、ProcessId、ThreadId 和 Callstack。預設值為 "None"。 若要指定多重選項,請用逗號分隔選項,但不能包含空格,然後置於引號內,例如 "ProcessID,ThreadID"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">TraceOptions</command:parameterValue> <dev:type> <maml:name>TraceOptions</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="1"> <maml:name>Name</maml:name> <maml:description> <maml:para>決定要追蹤的 Windows PowerShell 元件。輸入每個元件的追蹤來源的名稱。允許使用萬用字元。若要找出電腦上的追蹤來源,請輸入 "Get-TraceSource"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Option</maml:name> <maml:description> <maml:para>決定所要追蹤的事件類型。 有效的值包括 None、Constructor、Dispose、Finalizer、Method、Property、Delegates、Events、Exception、Lock、Error、Errors、Warning、Verbose、WriteLine、Data、Scope、ExecutionFlow、Assert 和 All。預設值為 "All"。 下列值是其他值的組合: -- ExecutionFlow:(Constructor、Dispose、Finalizer、Method、Delegates、Events 和 Scope) -- Data:(Constructor、Dispose、Finalizer、Property、Verbose 和 WriteLine) -- Errors:(Error 和 Exception)。 若要指定多重選項,請用逗號分隔選項,但不能包含空格,然後置於引號內,例如 "Constructor,Dispose"。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">PSTraceSourceOptions</command:parameterValue> <dev:type> <maml:name>PSTraceSourceOptions</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PSHost</maml:name> <maml:description> <maml:para>將追蹤輸出傳送至 Windows PowerShell 主機。此參數也會選取 PSHost 追蹤接聽程式。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將代表運算式輸入的物件輸出至 Trace-Command。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 在偵錯資料流中傳回命令追蹤。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 追蹤是開發人員用來偵錯和調整程式的一種方法。進行追蹤時,程式會產生詳細訊息列出每個內部處理步驟的相關資訊。 Windows PowerShell 追蹤 cmdlet 是專為輔助 Windows PowerShell 開發人員而設計,但所有的使用者皆可使用。這些 cmdlet 幾乎可以監視殼層每個層面的功能。 若要尋找啟用追蹤的 Windows PowerShell 元件,請輸入 "Get-Help Get-TraceSource"。 「追蹤來源」是每個 Windows PowerShell 元件的一部分,負責管理追蹤並產生元件的追蹤訊息。若要追蹤元件,您必須識別元件的追蹤來源。 「追蹤接聽程式」則接收追蹤的輸出,並顯示輸出供使用者檢視。您可以選擇將追蹤資料傳送到使用者模式或核心模式偵錯工具、主機或主控台、檔案,或者傳送到衍生自 System.Diagnostics.TraceListener 類別的自訂接聽程式。 當您使用 Command 參數集時,Windows PowerShell 處理命令的方式就如同在管線中處理一般。例如,不會針對每個內送物件重複命令搜索。 Name、Expression、Option 和 Command 參數的名稱為選擇性。如果省略參數名稱,就必須依此順序列出未具名的參數值:Name、Expression、Option (或 Name)、Command、-Option。如果包含參數名稱,則可依任意順序列出參數。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> trace-command -name metadata,parameterbinding,cmdlet -expression {get-process notepad} -pshost </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會針對 "get-process notepad" 運算式之中繼資料處理、參數繫結以及 Cmdlet 建立與解構啟動追蹤。它使用 Name 參數指定追蹤來源;使用 Expression 參數指定命令;並使用 PSHost 參數,將輸出傳送到主控台。因為沒有指定任何追蹤選項或接聽程式選項,所以此命令會使用預設值:以 "All" 為追蹤選項,並以 "None" 為接聽程式選項。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> trace-command -name commandprocessor,pipelineprocessor -command get-alias -argumentlist "ghy" -option executionflow -listenerOption "timestamp,callstack" -filepath c:\test\debug.txt </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在處理 "get-alias cd" 命令時,為命令處理程式和管線處理程式啟動追蹤。 它會使用 Name 參數指定追蹤來源、使用 Command 參數指定命令、使用 ArgumentList 參數指定 Get-Alias 命令的參數、使用 Option 參數指定追蹤選項,並使用 ListenerOption 參數指定追蹤訊息開頭中的欄位。FilePath 參數會將輸出傳送到 C:\Test\Debug.txt 檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $a = "i*" C:\PS> trace-command parameterbinding {get-alias $input} -pshost -inputobject $a </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會在 Windows PowerShell 處理由管線取得輸入的 Get-Alias 運算式時,追蹤其 ParameterBinding 作業的動作。 在 Trace-Command 中,InputObject 參數會在追蹤期間將物件傳遞給處理中的運算式。 第一個命令將字串 "i*" 儲存在 $a 變數中。第二個命令會搭配 ParameterBinding 追蹤來源,使用 Trace-Command Cmdlet。PSHost 參數將輸出傳送到主控台。 正在處理中的運算式是 "get-alias $input",其中 $input 變數與 InputObject 參數相關聯。InputObject 參數會將變數 $a 傳遞給運算式。實際上,在追蹤期間所處理的命令為 "get-alias -inputobject $a" 或 "$a | get-alias"。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113419</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-TraceSource</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Set-TraceSource</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Unregister-Event </command:name> <maml:description> <maml:para>取消事件訂閱。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Unregister</command:verb> <command:noun>Event</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Unregister-Event Cmdlet 會取消使用 Register-EngineEvent、Register-ObjectEvent 或 Register-WmiEvent Cmdlet 所建立的事件訂閱。 取消事件訂閱時,會從工作階段刪除事件訂閱者,而已訂閱的事件無法再新增到事件佇列。取消以 New-Event Cmdlet 所建立的事件訂閱時,也會從工作階段刪除新的事件。 Unregister-Event 不會從事件佇列刪除事件。若要刪除事件,請使用 Remove-Event Cmdlet。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Unregister-Event</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SubscriptionId</maml:name> <maml:description> <maml:para>取消有指定的訂閱識別元的事件訂閱。 每一個命令都需要有 SourceIdentifier 或 SubscriptionId 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>取消所有事件訂閱,包括已經使用 Register-ObjectEvent、Register-WmiEvent 和 Register-EngineEvent 的 SupportEvent 參數隱藏的事件訂閱。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Unregister-Event</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>取消有指定的來源識別元的事件訂閱。 每一個命令都需要有 SourceIdentifier 或 SubscriptionId 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>取消所有事件訂閱,包括已經使用 Register-ObjectEvent、Register-WmiEvent 和 Register-EngineEvent 的 SupportEvent 參數隱藏的事件訂閱。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Force</maml:name> <maml:description> <maml:para>取消所有事件訂閱,包括已經使用 Register-ObjectEvent、Register-WmiEvent 和 Register-EngineEvent 的 SupportEvent 參數隱藏的事件訂閱。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>取消有指定的來源識別元的事件訂閱。 每一個命令都需要有 SourceIdentifier 或 SubscriptionId 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SubscriptionId</maml:name> <maml:description> <maml:para>取消有指定的訂閱識別元的事件訂閱。 每一個命令都需要有 SourceIdentifier 或 SubscriptionId 參數。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSEventSubscriber</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將輸出從 Get-EventSubscriber 輸出至 Unregister-Event。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 這個 Cmdlet 不會傳回任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 事件、事件訂閱和事件佇列只存在於目前的工作階段中。如果關閉目前的工作階段,則會捨棄事件佇列並取消事件訂閱。 除非您已經使用 Register-EngineEvent Cmdlet 訂閱事件,否則 Unregister-Event 無法刪除以 New-Event Cmdlet 所建立的事件。若要從工作階段刪除自訂事件,必須以程式設計方式將它移除或關閉工作階段。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> unregister-event -sourceIdentifier ProcessStarted </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取消來源識別元為 "ProcessStarted" 的事件訂閱。 若要找出事件的來源識別元,請使用 Get-Event Cmdlet。若要找出事件訂閱的來源識別元,請使用 Get-EventSubscriber Cmdlet。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> unregister-event -subscriptionId 2 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取消訂閱識別元為 2 的事件訂閱。 若要找出事件訂閱的訂閱識別元,請使用 Get-EventSubscriber Cmdlet。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-eventsubscriber -force | unregister-event -force </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會取消工作階段中的所有事件訂閱。 該命令會使用 Get-EventSubscriber Cmdlet 取得工作階段中的所有事件訂閱者物件,包括已經使用事件註冊 Cmdlet 的 SupportEvent 參數隱藏的訂閱者。 它會使用管線運算子 (|) 將訂閱者物件傳送給 Unregister-Event,讓後者從工作階段中刪除這些物件。Unregister-Event 也需要有 Force 參數,才能完成工作。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135269</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-ObjectEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-EngineEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-WmiEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Unregister-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Wait-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-EventSubscriber</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Update-FormatData </command:name> <maml:description> <maml:para>更新目前工作階段中的格式化資料。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Update</command:verb> <command:noun>FormatData</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Update-FormatData Cmdlet 會將格式化檔案的格式化資料重新載入目前的工作階段中。這個 Cmdlet 可讓您更新格式化資料,而不需要重新啟動 Windows PowerShell。 如果沒有參數,Update-FormatData 就會重新載入它先前所載入的格式化檔案。您可以使用 Update-FormatData 的參數,將新的格式化檔案加入至工作階段。 格式化檔案是指採用 XML 格式且副檔名為 format.ps1xml 的文字檔。這些檔案中的格式化資料會定義 Microsoft .NET Framework 物件在工作階段中的顯示方式。 當 Windows PowerShell 啟動時,它會從 Windows PowerShell 安裝目錄 ($pshome) 的格式化檔案,將格式化資料載入工作階段中。您可以使用 Update-FormatData,將格式化資料重新載入目前的工作階段中,而不需要重新啟動 Windows PowerShell。當您已經加入或變更格式化檔案,但是不想要中斷工作階段時,這就很有用。 如需 Windows PowerShell 中格式化檔案的詳細資訊,請參閱 about_Format.ps1xml。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Update-FormatData</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>AppendPath</maml:name> <maml:description> <maml:para>將指定的格式化檔案加入至工作階段。這些檔案會在 Windows PowerShell 載入內建的格式化檔案之後載入。 格式化 .NET 物件時,Windows PowerShell 會針對每個 .NET 型別使用它找到的第一個格式化定義。如果您使用 AppendPath 參數,Windows PowerShell 會在遇到您所加入的格式化資料之前,從內建的檔案中搜尋資料。 您可以使用這個參數來加入格式化為 .NET 物件而且內建格式化檔案沒有參考此物件的檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>PrependPath</maml:name> <maml:description> <maml:para>將指定的格式化檔案加入至工作階段。這些檔案會在 Windows PowerShell 載入內建的格式化檔案之前載入。 格式化 .NET 物件時,Windows PowerShell 會針對每個 .NET 型別使用它找到的第一個格式化定義。如果您使用 PrependPath 參數,Windows PowerShell 會在遇到內建檔案的格式化資料之前,從您所加入的檔案中搜尋資料。 您可以使用這個參數來加入格式化為 .NET 物件而且內建格式化檔案也有參考此物件的檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>AppendPath</maml:name> <maml:description> <maml:para>將指定的格式化檔案加入至工作階段。這些檔案會在 Windows PowerShell 載入內建的格式化檔案之後載入。 格式化 .NET 物件時,Windows PowerShell 會針對每個 .NET 型別使用它找到的第一個格式化定義。如果您使用 AppendPath 參數,Windows PowerShell 會在遇到您所加入的格式化資料之前,從內建的檔案中搜尋資料。 您可以使用這個參數來加入格式化為 .NET 物件而且內建格式化檔案沒有參考此物件的檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>PrependPath</maml:name> <maml:description> <maml:para>將指定的格式化檔案加入至工作階段。這些檔案會在 Windows PowerShell 載入內建的格式化檔案之前載入。 格式化 .NET 物件時,Windows PowerShell 會針對每個 .NET 型別使用它找到的第一個格式化定義。如果您使用 PrependPath 參數,Windows PowerShell 會在遇到內建檔案的格式化資料之前,從您所加入的檔案中搜尋資料。 您可以使用這個參數來加入格式化為 .NET 物件而且內建格式化檔案也有參考此物件的檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含附加路徑的字串輸出至 Update-FormatData。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 這個 Cmdlet 不會傳回任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> Update-FormatData 也會在工作階段中更新從模組匯入之命令的格式化資料。如果模組的格式化檔案已變更,您就可以執行 Update-FormatData 命令來更新匯入命令的格式化資料。不過,您不需要再次匯入模組。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> update-formatdata </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會重新載入它先前所載入的格式化檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> update-formatdata -appendpath trace.format.ps1xml, log.format.ps1xml </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將格式化檔案重新載入工作階段中,包括 Trace.format.ps1xml 和 Log.format.ps1xml 這兩個新檔案。 因為此命令會使用 AppendPath 參數,所以新檔案中的格式化資料會在系統載入內建檔案的格式化資料之後載入。 使用 AppendPath 參數的原因是新檔案包含內建檔案沒有參考之物件的格式化資料。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> update-formatdata -prependPath c:\test\NewFiles.format.ps1xml # Edit the NewFiles.format.ps1 file. C:\PS> update-formatdata </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會示範如何在您已經編輯格式化檔案之後,重新載入格式化檔案。 第一個命令會將 NewFiles.format.ps1xml 檔案加入至工作階段。它會使用 PrependPath 參數的原因是該檔案包含內建檔案已參考之物件的格式化資料。 加入 NewFiles.format.ps1xml 檔案並在這些工作階段中進行測試之後,作者會編輯該檔案。 第二個命令會使用 Update-FormatData Cmdlet 來重新載入格式化檔案。因為先前已經載入 NewFiles.format.ps1xml 檔案,所以 Update-FormatData 會自動重新載入該檔案,而不需要使用參數。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113420</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Update-List </command:name> <maml:description> <maml:para>在包含物件集合的屬性值中新增及移除項目。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Update</command:verb> <command:noun>List</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Update-List Cmdlet 會在物件的屬性值中新增及移除項目,然後傳回已更新的物件。此 Cmdlet 專為包含物件集合的屬性而設計。 Add 和 Remove 參數會在集合中新增及移除個別項目。Replace 參數則會取代整個集合。 如果您沒有在命令中指定屬性,Update-List 會傳回描述更新的物件,而不是更新物件。您可以將更新物件送出給會變更物件的 Cmdlet,例如 Set-* Cmdlet。 只有當正在進行更新的屬性支援 Update-List 使用的 IList 介面時,才能使用此 Cmdlet。此外,任何接受更新的 Set-* Cmdlet 必須支援 IList 介面。隨 Windows PowerShell 安裝的核心 Cmdlet 並不支援此介面。若要判斷某個 Cmdlet 是否支援 Update-List,請參閱該 Cmdlet 的說明主題。 </maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Update-List</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Add</maml:name> <maml:description> <maml:para>指定要新增到集合中的屬性值。請依照應該出現在集合中的順序輸入值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Remove</maml:name> <maml:description> <maml:para>指定要從集合中移除的屬性值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>識別包含正在進行更新的集合之屬性。如果省略此參數,Update-List 就會傳回代表變更的物件,而不是變更物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要更新的物件。您也可經由管道將要更新的物件輸出至 Update-List。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Update-List</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Replace</maml:name> <maml:description> <maml:para>指定新的集合。此參數會以本身指定的項目來代替原始集合中的所有項目。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>識別包含正在進行更新的集合之屬性。如果省略此參數,Update-List 就會傳回代表變更的物件,而不是變更物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要更新的物件。您也可經由管道將要更新的物件輸出至 Update-List。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Add</maml:name> <maml:description> <maml:para>指定要新增到集合中的屬性值。請依照應該出現在集合中的順序輸入值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要更新的物件。您也可經由管道將要更新的物件輸出至 Update-List。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">psobject</command:parameterValue> <dev:type> <maml:name>psobject</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Property</maml:name> <maml:description> <maml:para>識別包含正在進行更新的集合之屬性。如果省略此參數,Update-List 就會傳回代表變更的物件,而不是變更物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Remove</maml:name> <maml:description> <maml:para>指定要從集合中移除的屬性值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Replace</maml:name> <maml:description> <maml:para>指定新的集合。此參數會以本身指定的項目來代替原始集合中的所有項目。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">Object[]</command:parameterValue> <dev:type> <maml:name>Object[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將要更新的物件輸出至 Update-List。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>物件或 System.Management.Automation.PSListModifier</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Update-List 會傳回已更新的物件,或傳回代表更新動作的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-mailbox | update-list -Property aliases -Add "A","B" -Remove "X","Y" | set-mailbox </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會在信箱的 Aliases 屬性中新增 A 和 B 並移除 X 和 Y。 此命令會使用 Microsoft Exchange Server 的 Get-MailBox Cmdlet 來取得信箱。管線運算子會將信箱物件傳送給 Update-List Cmdlet。 Update-List 命令會使用 Property 參數來表示信箱的 Aliases 屬性正在進行更新,以及使用 Add 和 Remove 參數來指定正在集合中新增及移除的項目。Aliases 屬性符合 Update-List 的條件,因為其儲存的 Microsoft .NET Framework 物件集合具有 Add 和 Remove 方法。 Update-List Cmdlet 會傳回已更新的信箱,然後這個信箱會經由管道輸出至 Set-MailBox Cmdlet,讓後者變更信箱。 如需 Get-Mailbox 的詳細資訊,請參閱 http://go.microsoft.com/fwlink/?LinkId=111536。 </maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $m = get-mailbox C:\PS> update-list -InputObject $m -Property aliases -Add "A","B" -Remove "X", "Y" | set-mailbox </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將 A 和 B 新增到信箱的 Aliases 屬性值,並移除 X 與 Y。這個命令具有與前一個命令同等的效果,但有些許不同。 這個命令會使用 Get-MailBox Cmdlet 取得信箱,然後將信箱儲存到 $m 變數。它也會使用 Update-List 的 InputObject 參數指定信箱。InputObject 的值為 $m 變數中的信箱。這個命令會使用 Property 參數指定 Aliases 屬性,以及使用 Add 和 Remove 參數指定正在從 Aliases 的值中新增及移除的項目。 它也會使用管線運算子 (|) 將已更新的信箱物件傳送給 Set-Mailbox Cmdlet,讓後者變更信箱。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-mailbox | set-mailbox -alias (update-list -Add "A", "B" -Remove "X","Y") </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將 A 和 B 新增到信箱的 Aliases 屬性值,並移除 X 與 Y。這個命令具有與前兩個命令同等的效果,但是使用不同的程序執行工作。 相對於在更新信箱的 Aliases 屬性後再將信箱傳送給 Set-Mailbox,這個命令會使用 Update-List 建立代表變更的物件,然後將變更送出給 Set-Mailbox 的 Alias 參數。 該命令會使用 Get-MailBox Cmdlet 取得信箱。管線運算子 (|) 會將信箱物件傳送給 Set-Mailbox Cmdlet,讓後者變更信箱。 該命令會使用 Set-Mailbox 的 Alias 參數變更信箱物件的 Aliases 屬性。Alias 參數的值為 Update-List 命令,它會建立代表更新的物件。Update-List 命令是放在括弧內,確保會在 Alias 參數的值被評估之前執行它。當 Set-Mailbox 命令完成時,也就變更了信箱。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> update-list -InputObject $a -Property aliases -replace "A", "B" | set-mailbox </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 Update-List 的 Replace 運算子,以新的集合來代替 $a 中物件的 Aliases 屬性內的集合。 這個命令使用 InputObject 參數,在本例中相當於使用管線運算子將 $a 傳遞給 Update-List。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113447</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Select-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Update-TypeData </command:name> <maml:description> <maml:para>將 *.types.ps1xml 檔案重新載入記憶體,藉以更新目前的擴充型別設定。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Update</command:verb> <command:noun>TypeData</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Update-TypeData Cmdlet 會將 *.types.ps1xml 檔案重新載入記憶體,藉以更新目前的擴充型別設定。擴充型別資訊一般是在 Windows PowerShell 需要其所包含的型別資訊時載入。Update-TypeData Cmdlet 可以用來預先載入所有型別資訊。當您在開發型別,並且想要載入這些新型別進行測試時,這種作法會特別有用。 如需 Windows PowerShell 中 *types.ps1xml 檔案的詳細資訊,請參閱 about_Types.ps1xml。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Update-TypeData</maml:name> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>AppendPath</maml:name> <maml:description> <maml:para>指定選擇性 .ps1xml 檔案的路徑,以便將這些檔案包含在載入的檔案清單中。載入內建的檔案後才會處理這些檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>PrependPath</maml:name> <maml:description> <maml:para>指定選擇性 .ps1xml 檔案的路徑,以便將這些檔案包含在載入的檔案清單中。然而,在載入內建的檔案前,會依檔案指定順序先處理這些檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="true (ByValue, ByPropertyName)" position="1"> <maml:name>AppendPath</maml:name> <maml:description> <maml:para>指定選擇性 .ps1xml 檔案的路徑,以便將這些檔案包含在載入的檔案清單中。載入內建的檔案後才會處理這些檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>PrependPath</maml:name> <maml:description> <maml:para>指定選擇性 .ps1xml 檔案的路徑,以便將這些檔案包含在載入的檔案清單中。然而,在載入內建的檔案前,會依檔案指定順序先處理這些檔案。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">string[]</command:parameterValue> <dev:type> <maml:name>string[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>Confirm</maml:name> <maml:description> <maml:para>在執行命令前先提示確認。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> <command:parameter required="false" variableLength="true" globbing="false" pipelineInput="false" position="named"> <maml:name>WhatIf</maml:name> <maml:description> <maml:para>說明執行命令時將會發生何種情況,但不會實際執行命令。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue /> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含附加路徑的字串輸出至 Update-TypeData。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 這個 Cmdlet 不會傳回任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> update-typedata </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會從 *.types.ps1xml 檔案更新擴充型別設定。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> update-typedata -prependpath typesA.types.Ps1xml, typesB.types.Ps1xml </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會從 *.types.ps1xml 檔案中更新擴充型別設定,並且先處理 typesA 和 typesB 檔案。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113421</maml:uri> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Wait-Event </command:name> <maml:description> <maml:para>等到特定事件引發後才繼續執行。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Wait</command:verb> <command:noun>Event</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Wait-Event Cmdlet 會暫停執行指令碼或函數直到特定事件引發為止。偵測到事件時會繼續執行。若要取消等候,請按 CTRL+C。 這項功能不但提供輪詢事件的替代方式,還能讓您決定以兩種不同的方式回應事件:一種是使用事件訂閱的 Action 參數,另一種是等候事件傳回後再以動作回應。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Wait-Event</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>只等候有指定的來源識別元的事件。根據預設,Wait-Event 會等候任何事件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Timeout</maml:name> <maml:description> <maml:para>決定 Wait-Event 等候事件發生的時間上限,以秒為單位。預設值 -1 會無限期等候。在提交 Wait-Event 命令後就會開始計時。 如果超過指定的時間,等候便結束並傳回命令提示字元,即使尚未引發事件也一樣。並且不會顯示任何錯誤訊息。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1"> <maml:name>SourceIdentifier</maml:name> <maml:description> <maml:para>只等候有指定的來源識別元的事件。根據預設,Wait-Event 會等候任何事件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>所有事件</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Timeout</maml:name> <maml:description> <maml:para>決定 Wait-Event 等候事件發生的時間上限,以秒為單位。預設值 -1 會無限期等候。在提交 Wait-Event 命令後就會開始計時。 如果超過指定的時間,等候便結束並傳回命令提示字元,即使尚未引發事件也一樣。並且不會顯示任何錯誤訊息。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 事件、事件訂閱和事件佇列只存在於目前的工作階段中。如果關閉目前的工作階段,則會捨棄事件佇列並取消事件訂閱。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> wait-event </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會等候下一個引發的事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> wait-event -sourceIdentifier "ProcessStarted" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會等候下一個引發且來源識別元為 "ProcessStarted" 的事件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $timer.Interval = 2000 C:\PS> $timer.Autoreset = $false C:\PS> $timer.Enabled = $true; Wait-Event Timer.Elapsed # After 2 seconds EventIdentifier : 12 Sender : System.Timers.Timer SourceEventArgs : System.Timers.ElapsedEventArgs SourceArgs : {System.Timers.Timer, System.Timers.ElapsedEventArgs} SourceIdentifier : Timer.Elapsed TimeGenerated : 6/10/2008 3:24:18 PM MessageData : ForwardEvent : False </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會使用 Wait-Event Cmdlet 等候已設定成 2000 毫秒的計時器上的計時器物件。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> wait-event -sourceIdentifier "ProcessStarted" -timeout 90 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會等候下一個引發且來源識別元為 "ProcessStarted" 的事件 (最多 90 秒)。如果超過指定的時間,等候便結束。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=135276</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-ObjectEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-EngineEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Register-WmiEvent</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Unregister-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>New-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Remove-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Wait-Event</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Get-EventSubscriber</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Write-Debug </command:name> <maml:description> <maml:para>將偵錯訊息寫入主控台。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Write</command:verb> <command:noun>Debug</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Write-Debug Cmdlet 會從指令碼或命令將偵錯訊息寫入主控台。 根據預設,主控台不會顯示偵錯訊息,但是您可以使用 Debug 參數或 $DebugPreference 變數顯示偵錯訊息。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Write-Debug</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Message</maml:name> <maml:description> <maml:para>指定要傳送至主控台的偵錯訊息。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Message</maml:name> <maml:description> <maml:para>指定要傳送至主控台的偵錯訊息。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含偵錯訊息的字串輸出至 Write-Debug。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Write-Debug 只會寫入偵錯資料流。它不會傳回任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> Write-Debug "Cannot open file." </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將偵錯訊息寫入主控台。$DebugPreference 的值為 "SilentlyContinue",因此主控台不顯示訊息。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $DebugPreference SilentlyContinue C:\PS> Write-Debug "Cannot open file." C:\PS> C:\PS> Write-Debug "Cannot open file." -debug DEBUG: Cannot open file. </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例示範如何使用一般的 Debug 參數覆寫特定命令的 $DebugPreference 變數值。 第一個命令會顯示 $DebugPreference 變數的值,即預設的 "SilentlyContinue"。 第二個命令會寫入偵錯訊息,但是由於 $DebugPreference 的值,訊息不會出現。 這三個命令會寫入偵錯訊息。它會使用一般的 Debug 參數,覆寫 $DebugPreference 的值,以及顯示其所產生的偵錯訊息。 因此,即使 $DebugPreference 的值為 "SilentlyContinue",偵錯訊息還是會出現。 如需 Debug 一般參數的詳細資訊,請參閱 about_CommonParameters。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $DebugPreference SilentlyContinue C:\PS> Write-Debug "Cannot open file." C:\PS> C:\PS> $DebugPreference = "Continue" C:\PS> Write-Debug "Cannot open file." DEBUG: Cannot open file. </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令示範 $DebugPreference 變數值在顯示偵錯訊息上的變更效果。 第一個命令會顯示 $DebugPreference 變數的值,即預設的 "SilentlyContinue"。 第二個命令會寫入偵錯訊息,但是由於 $DebugPreference 的值,訊息不會出現。 第三個命令會將 "Continue" 的值指派給 $DebugPreference 變數。 第四個命令會寫入偵錯訊息,該訊息會在主控台上顯示。 如需 $DebugPreference 的詳細資訊,請參閱 about_Preference_Variables。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113424</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Verbose</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Error</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Progress</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Output</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Warning</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Write-Error </command:name> <maml:description> <maml:para>將物件寫入錯誤資料流。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Write</command:verb> <command:noun>Error</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Write-Error Cmdlet 會將錯誤寫入 Windows PowerShell 錯誤資料流。根據預設,錯誤會連同輸出一起傳送至即將顯示的主機程式。 您可以透過提交錯誤訊息字串、ErrorRecord 物件或 Exception 物件,寫入錯誤。請使用 Write-Error 的其他參數來填入錯誤記錄。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Write-Error</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ErrorRecord</maml:name> <maml:description> <maml:para>指定錯誤記錄物件,其中包含描述錯誤的屬性。 若要取得錯誤記錄物件,請使用 New-Object Cmdlet,或從 $Error 自動變數中的陣列取得錯誤記錄物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">ErrorRecord</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryActivity</maml:name> <maml:description> <maml:para>描述造成錯誤的動作。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryReason</maml:name> <maml:description> <maml:para>說明活動造成錯誤的情況或原因。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryTargetName</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件之名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryTargetType</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件之 .NET 型別。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>RecommendedAction</maml:name> <maml:description> <maml:para>描述使用者可採取的因應措施,以解決或防止錯誤。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Write-Error</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Message</maml:name> <maml:description> <maml:para>指定錯誤的訊息文字。如果文字中包含空格或特殊字元,請將其置於引號內。您也可經由管道將訊息字串輸出至 Write-Error。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Category</maml:name> <maml:description> <maml:para>指定錯誤的類別。預設值為 NotSpecified。 如需錯誤類別的詳細資訊,請參閱 MSDN (Microsoft Developer Network) Library 中的<ErrorCategory 列舉>(英文),網址為:http://go.microsoft.com/fwlink/?LinkId=143600。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">NotSpecified</command:parameterValue> <command:parameterValue required="false" variableLength="false">OpenError</command:parameterValue> <command:parameterValue required="false" variableLength="false">CloseError</command:parameterValue> <command:parameterValue required="false" variableLength="false">DeviceError</command:parameterValue> <command:parameterValue required="false" variableLength="false">DeadlockDetected</command:parameterValue> <command:parameterValue required="false" variableLength="false">InvalidArgument</command:parameterValue> <command:parameterValue required="false" variableLength="false">InvalidData</command:parameterValue> <command:parameterValue required="false" variableLength="false">InvalidOperation</command:parameterValue> <command:parameterValue required="false" variableLength="false">InvalidResult</command:parameterValue> <command:parameterValue required="false" variableLength="false">InvalidType</command:parameterValue> <command:parameterValue required="false" variableLength="false">MetadataError</command:parameterValue> <command:parameterValue required="false" variableLength="false">NotImplemented</command:parameterValue> <command:parameterValue required="false" variableLength="false">NotInstalled</command:parameterValue> <command:parameterValue required="false" variableLength="false">ObjectNotFound</command:parameterValue> <command:parameterValue required="false" variableLength="false">OperationStopped</command:parameterValue> <command:parameterValue required="false" variableLength="false">OperationTimeout</command:parameterValue> <command:parameterValue required="false" variableLength="false">SyntaxError</command:parameterValue> <command:parameterValue required="false" variableLength="false">ParserError</command:parameterValue> <command:parameterValue required="false" variableLength="false">PermissionDenied</command:parameterValue> <command:parameterValue required="false" variableLength="false">ResourceBusy</command:parameterValue> <command:parameterValue required="false" variableLength="false">ResourceExists</command:parameterValue> <command:parameterValue required="false" variableLength="false">ResourceUnavailable</command:parameterValue> <command:parameterValue required="false" variableLength="false">ReadError</command:parameterValue> <command:parameterValue required="false" variableLength="false">WriteError</command:parameterValue> <command:parameterValue required="false" variableLength="false">FromStdErr</command:parameterValue> <command:parameterValue required="false" variableLength="false">SecurityError</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ErrorId</maml:name> <maml:description> <maml:para>指定要識別錯誤的識別碼字串。此字串對錯誤而言必須是唯一的。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>TargetObject</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件。請輸入物件 (如字串)、含有物件的變數或可取得物件的命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryActivity</maml:name> <maml:description> <maml:para>描述造成錯誤的動作。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryReason</maml:name> <maml:description> <maml:para>說明活動造成錯誤的情況或原因。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryTargetName</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件之名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryTargetType</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件之 .NET 型別。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>RecommendedAction</maml:name> <maml:description> <maml:para>描述使用者可採取的因應措施,以解決或防止錯誤。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> <command:syntaxItem> <maml:name>Write-Error</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Exception</maml:name> <maml:description> <maml:para>指定代表錯誤的例外狀況。 您可以用例外狀況來代替指定訊息文字或例外狀況記錄。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Exception</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Category</maml:name> <maml:description> <maml:para>指定錯誤的類別。預設值為 NotSpecified。 如需錯誤類別的詳細資訊,請參閱 MSDN (Microsoft Developer Network) Library 中的<ErrorCategory 列舉>(英文),網址為:http://go.microsoft.com/fwlink/?LinkId=143600。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">NotSpecified</command:parameterValue> <command:parameterValue required="false" variableLength="false">OpenError</command:parameterValue> <command:parameterValue required="false" variableLength="false">CloseError</command:parameterValue> <command:parameterValue required="false" variableLength="false">DeviceError</command:parameterValue> <command:parameterValue required="false" variableLength="false">DeadlockDetected</command:parameterValue> <command:parameterValue required="false" variableLength="false">InvalidArgument</command:parameterValue> <command:parameterValue required="false" variableLength="false">InvalidData</command:parameterValue> <command:parameterValue required="false" variableLength="false">InvalidOperation</command:parameterValue> <command:parameterValue required="false" variableLength="false">InvalidResult</command:parameterValue> <command:parameterValue required="false" variableLength="false">InvalidType</command:parameterValue> <command:parameterValue required="false" variableLength="false">MetadataError</command:parameterValue> <command:parameterValue required="false" variableLength="false">NotImplemented</command:parameterValue> <command:parameterValue required="false" variableLength="false">NotInstalled</command:parameterValue> <command:parameterValue required="false" variableLength="false">ObjectNotFound</command:parameterValue> <command:parameterValue required="false" variableLength="false">OperationStopped</command:parameterValue> <command:parameterValue required="false" variableLength="false">OperationTimeout</command:parameterValue> <command:parameterValue required="false" variableLength="false">SyntaxError</command:parameterValue> <command:parameterValue required="false" variableLength="false">ParserError</command:parameterValue> <command:parameterValue required="false" variableLength="false">PermissionDenied</command:parameterValue> <command:parameterValue required="false" variableLength="false">ResourceBusy</command:parameterValue> <command:parameterValue required="false" variableLength="false">ResourceExists</command:parameterValue> <command:parameterValue required="false" variableLength="false">ResourceUnavailable</command:parameterValue> <command:parameterValue required="false" variableLength="false">ReadError</command:parameterValue> <command:parameterValue required="false" variableLength="false">WriteError</command:parameterValue> <command:parameterValue required="false" variableLength="false">FromStdErr</command:parameterValue> <command:parameterValue required="false" variableLength="false">SecurityError</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ErrorId</maml:name> <maml:description> <maml:para>指定要識別錯誤的識別碼字串。此字串對錯誤而言必須是唯一的。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Message</maml:name> <maml:description> <maml:para>指定錯誤的訊息文字。如果文字中包含空格或特殊字元,請將其置於引號內。您也可經由管道將訊息字串輸出至 Write-Error。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>TargetObject</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件。請輸入物件 (如字串)、含有物件的變數或可取得物件的命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryActivity</maml:name> <maml:description> <maml:para>描述造成錯誤的動作。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryReason</maml:name> <maml:description> <maml:para>說明活動造成錯誤的情況或原因。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryTargetName</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件之名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryTargetType</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件之 .NET 型別。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>RecommendedAction</maml:name> <maml:description> <maml:para>描述使用者可採取的因應措施,以解決或防止錯誤。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Category</maml:name> <maml:description> <maml:para>指定錯誤的類別。預設值為 NotSpecified。 如需錯誤類別的詳細資訊,請參閱 MSDN (Microsoft Developer Network) Library 中的<ErrorCategory 列舉>(英文),網址為:http://go.microsoft.com/fwlink/?LinkId=143600。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">ErrorCategory</command:parameterValue> <dev:type> <maml:name>ErrorCategory</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>NotSpecified</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryActivity</maml:name> <maml:description> <maml:para>描述造成錯誤的動作。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryReason</maml:name> <maml:description> <maml:para>說明活動造成錯誤的情況或原因。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryTargetName</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件之名稱。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CategoryTargetType</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件之 .NET 型別。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ErrorId</maml:name> <maml:description> <maml:para>指定要識別錯誤的識別碼字串。此字串對錯誤而言必須是唯一的。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ErrorRecord</maml:name> <maml:description> <maml:para>指定錯誤記錄物件,其中包含描述錯誤的屬性。 若要取得錯誤記錄物件,請使用 New-Object Cmdlet,或從 $Error 自動變數中的陣列取得錯誤記錄物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">ErrorRecord</command:parameterValue> <dev:type> <maml:name>ErrorRecord</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Exception</maml:name> <maml:description> <maml:para>指定代表錯誤的例外狀況。 您可以用例外狀況來代替指定訊息文字或例外狀況記錄。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Exception</command:parameterValue> <dev:type> <maml:name>Exception</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Message</maml:name> <maml:description> <maml:para>指定錯誤的訊息文字。如果文字中包含空格或特殊字元,請將其置於引號內。您也可經由管道將訊息字串輸出至 Write-Error。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>RecommendedAction</maml:name> <maml:description> <maml:para>描述使用者可採取的因應措施,以解決或防止錯誤。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>TargetObject</maml:name> <maml:description> <maml:para>指定錯誤發生時正在進行處理的物件。請輸入物件 (如字串)、含有物件的變數或可取得物件的命令。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含錯誤訊息的字串輸出至 Write-Error。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>Error object</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Write-Error 只會寫入錯誤資料流。它不會傳回任何物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> get-childitem | foreach-object { if ($_.gettype().tostring() -eq "Microsoft.Win32.RegistryKey") {write-error "Out-of-band object" -errorID B1 -targetobject $_ } else {$_ } } </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>當 Get-ChildItem Cmdlet 傳回 Microsoft.Win32.RegistryKey 物件 (例如 Windows PowerShell 登錄提供者之 HKLM: 或 HKCU 磁碟機中的物件) 時,這個命令就會寫入錯誤。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> write-error "Access denied." </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會寫入 "Access denied" 錯誤,並使用 Message 參數指定該訊息,但省略選擇性的 Message 參數名稱。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> write-error -message "Error: Too many input values." -category InvalidArgument </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會寫入錯誤並指定錯誤類別。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113425</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Debug</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Verbose</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Output</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Progress</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Warning</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Write-Host </command:name> <maml:description> <maml:para>將自訂輸出寫入主控程式。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Write</command:verb> <command:noun>Host</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Write-Host Cmdlet 會自訂輸出。您可以使用 ForegroundColor 參數指定文字色彩,也可以使用 BackgroundColor 參數指定背景色彩。Separator 參數可讓您指定要用來分隔顯示物件的字串。特定效果需視主控 Windows PowerShell 的程式而定。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Write-Host</maml:name> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Object</maml:name> <maml:description> <maml:para>要顯示於主控台的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>BackgroundColor</maml:name> <maml:description> <maml:para>指定背景色彩。無預設值。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Black</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkBlue</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkGreen</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkCyan</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkRed</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkMagenta</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkYellow</command:parameterValue> <command:parameterValue required="false" variableLength="false">Gray</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkGray</command:parameterValue> <command:parameterValue required="false" variableLength="false">Blue</command:parameterValue> <command:parameterValue required="false" variableLength="false">Green</command:parameterValue> <command:parameterValue required="false" variableLength="false">Cyan</command:parameterValue> <command:parameterValue required="false" variableLength="false">Red</command:parameterValue> <command:parameterValue required="false" variableLength="false">Magenta</command:parameterValue> <command:parameterValue required="false" variableLength="false">Yellow</command:parameterValue> <command:parameterValue required="false" variableLength="false">White</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ForegroundColor</maml:name> <maml:description> <maml:para>指定文字色彩。無預設值。</maml:para> </maml:description> <command:parameterValueGroup> <command:parameterValue required="false" variableLength="false">Black</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkBlue</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkGreen</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkCyan</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkRed</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkMagenta</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkYellow</command:parameterValue> <command:parameterValue required="false" variableLength="false">Gray</command:parameterValue> <command:parameterValue required="false" variableLength="false">DarkGray</command:parameterValue> <command:parameterValue required="false" variableLength="false">Blue</command:parameterValue> <command:parameterValue required="false" variableLength="false">Green</command:parameterValue> <command:parameterValue required="false" variableLength="false">Cyan</command:parameterValue> <command:parameterValue required="false" variableLength="false">Red</command:parameterValue> <command:parameterValue required="false" variableLength="false">Magenta</command:parameterValue> <command:parameterValue required="false" variableLength="false">Yellow</command:parameterValue> <command:parameterValue required="false" variableLength="false">White</command:parameterValue> </command:parameterValueGroup> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoNewline</maml:name> <maml:description> <maml:para>指定顯示於主控台的內容不要以新行字元結尾。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Separator</maml:name> <maml:description> <maml:para>輸出至主控台以顯示於各個物件之間的字串。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>BackgroundColor</maml:name> <maml:description> <maml:para>指定背景色彩。無預設值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">ConsoleColor</command:parameterValue> <dev:type> <maml:name>ConsoleColor</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ForegroundColor</maml:name> <maml:description> <maml:para>指定文字色彩。無預設值。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">ConsoleColor</command:parameterValue> <dev:type> <maml:name>ConsoleColor</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>NoNewline</maml:name> <maml:description> <maml:para>指定顯示於主控台的內容不要以新行字元結尾。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Object</maml:name> <maml:description> <maml:para>要顯示於主控台的物件。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Separator</maml:name> <maml:description> <maml:para>輸出至主控台以顯示於各個物件之間的字串。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">Object</command:parameterValue> <dev:type> <maml:name>Object</maml:name> <maml:uri /> </dev:type> <dev:defaultValue>無</dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Object</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將要寫入的物件輸出至主機。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Write-Host 會將物件傳送至主機。它不會傳回任何物件。不過,主機可能會顯示 Write-Host 傳送給它的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> write-host "no newline test " -nonewline no newline test C:\PS> </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會將輸入顯示到主控台,但由於 NoNewline 參數,輸出後面會緊跟著出現提示字元。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> write-host (2,4,6,8,10,12) -Separator ", +2= " 2, +2= 4, +2= 6, +2= 8, +2= 10, +2= 12 </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令顯示從 2 到 12 的偶數。Separator 參數用來加入字串:, +2= (逗號、空格、+、2、=、空格)。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> write-host (2,4,6,8,10,12) -Separator ", -> " -foregroundcolor DarkGreen -backgroundcolor white </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示從 2 到 12 的偶數。它會使用 ForegroundColor 參數輸出深綠色文字,並使用 BackgroundColor 參數顯示白色背景。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> write-host "Red on white text." -ForegroundColor red -BackgroundColor white Red on white text. </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示 "Red on white text." 字串。文字是紅色,如 ForegroundColor 參數所定義。背景是白色,如 BackgroundColor 參數所定義。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113426</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Verbose</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Error</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Progress</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Debug</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Output</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Warning</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Out-Host</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Write-Output </command:name> <maml:description> <maml:para>將指定的物件傳送給管線中的下一個命令。如果此命令是管線中的最後一個命令,這些物件就會顯示在主控台中。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Write</command:verb> <command:noun>Output</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Write-Output Cmdlet 會將指定的物件往下傳送給管線中的下一個命令。如果此命令是管線中的最後一個命令,該物件就會顯示在主控台中。 Write-Output 會將物件往下傳送給主要管線,也稱為「輸出資料流」或「成功管線」。若要將錯誤往下傳送給錯誤管線,請使用 Write-Error。 此 Cmdlet 通常用於指令碼,在主控台上顯示字串或其他物件。不過,由於預設的行為是在管線的末端顯示物件,因此一般沒有必要使用該 Cmdlet。例如,"get-process | write-output" 相當於 "get-process"。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Write-Output</maml:name> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要往下傳送給管線的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="true" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>InputObject</maml:name> <maml:description> <maml:para>指定要往下傳送給管線的物件。請輸入包含物件的變數,或輸入可取得物件的命令或運算式。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="true">PSObject[]</command:parameterValue> <dev:type> <maml:name>PSObject[]</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將物件輸出至 Write-Output。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>System.Management.Automation.PSObject</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Write-Output 會傳回當做輸入提交的物件。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $p = get-process c:\PS> write-output $p c:\PS> $p </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會取得代表正在電腦上執行之處理序的物件,並在主控台上加以顯示。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> write-output "test output" | get-member </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會經由管道將 "test output" 字串輸出至 Get-Member Cmdlet,讓後者顯示 String 類別的成員,以此示範字串是沿著管線進行傳送的。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113427</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Debug</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Verbose</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Error</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Progress</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Warning</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Tee-Object</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Write-Progress </command:name> <maml:description> <maml:para>在 Windows PowerShell 命令視窗中顯示進度列。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Write</command:verb> <command:noun>Progress</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Write-Progress Cmdlet 會在 Windows PowerShell 命令視窗中顯示進度列,它是用來描述執行中的命令或指令碼的狀態。您可以選取進度列反射的指示器,以及出現在進度列上方或下方的文字。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Write-Progress</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Activity</maml:name> <maml:description> <maml:para>指定狀態列上方的標題第一行文字。此文字描述正在被報告進度的活動。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Status</maml:name> <maml:description> <maml:para>指定狀態列上方的標題第二行文字。此文字描述活動的目前狀態。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Id</maml:name> <maml:description> <maml:para>指定可區別每個進度列的識別碼。當您以單一命令建立一個以上的進度列時,請使用此參數。如果進度列之間沒有不同的識別碼,它們會相互覆蓋,而不是以序列顯示。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Completed</maml:name> <maml:description> <maml:para>指出能否看見進度列。如果省略這個參數,Write-Progress 就會顯示進度資訊。</maml:para> </maml:description> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CurrentOperation</maml:name> <maml:description> <maml:para>指定進度列下方的文字行。此文字描述目前正在進行的作業。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ParentId</maml:name> <maml:description> <maml:para>識別目前活動的父活動。值為 -1 表示目前的活動沒有父活動。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PercentComplete</maml:name> <maml:description> <maml:para>指定活動已完成百分比。值為 -1 表示已完成百分比未知或不適用。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SecondsRemaining</maml:name> <maml:description> <maml:para>指定截至活動完成預計剩餘的秒數。值為 -1 表示剩餘秒數未知或不適用。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SourceId</maml:name> <maml:description> <maml:para>識別記錄的來源。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="1"> <maml:name>Activity</maml:name> <maml:description> <maml:para>指定狀態列上方的標題第一行文字。此文字描述正在被報告進度的活動。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>Completed</maml:name> <maml:description> <maml:para>指出能否看見進度列。如果省略這個參數,Write-Progress 就會顯示進度資訊。</maml:para> </maml:description> <command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue> <dev:type> <maml:name>SwitchParameter</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>CurrentOperation</maml:name> <maml:description> <maml:para>指定進度列下方的文字行。此文字描述目前正在進行的作業。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="3"> <maml:name>Id</maml:name> <maml:description> <maml:para>指定可區別每個進度列的識別碼。當您以單一命令建立一個以上的進度列時,請使用此參數。如果進度列之間沒有不同的識別碼,它們會相互覆蓋,而不是以序列顯示。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>ParentId</maml:name> <maml:description> <maml:para>識別目前活動的父活動。值為 -1 表示目前的活動沒有父活動。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>PercentComplete</maml:name> <maml:description> <maml:para>指定活動已完成百分比。值為 -1 表示已完成百分比未知或不適用。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SecondsRemaining</maml:name> <maml:description> <maml:para>指定截至活動完成預計剩餘的秒數。值為 -1 表示剩餘秒數未知或不適用。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named"> <maml:name>SourceId</maml:name> <maml:description> <maml:para>識別記錄的來源。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">int</command:parameterValue> <dev:type> <maml:name>int</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="2"> <maml:name>Status</maml:name> <maml:description> <maml:para>指定狀態列上方的標題第二行文字。此文字描述活動的目前狀態。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您無法經由管道將輸入輸出至這個 Cmdlet。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Write-Progress 不會產生任何輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> 如果進度列沒有出現,請檢查 $ProgressPreference 變數的值。如果這個值是設為 SilentlyContinue,就不會顯示進度列。如需 Windows PowerShell 喜好設定的詳細資訊,請參閱 about_Preference_Variables。 此 Cmdlet 的參數會對應至 ProgressRecord 類別 (System.Management.Automation.ProgressRecord) 的屬性。如需詳細資訊,請參閱 Windows PowerShell 軟體開發套件 (SDK) 中的 ProgressRecord 主題。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> for ($i = 1; $i -lt 101; $i++ ) {for ($j=0;$j -lt 10000;$j++) {} write-progress -activity "Search in Progress" -status "% Complete:" -percentcomplete $i;} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會顯示兩個巢狀 For 迴圈的進度。第一個迴圈會計數到 100。針對該迴圈的每一個增量,第二個迴圈會計數到 10,000。 Write-Progress 命令包含狀態列標題 ("activity")、狀態行和變數 $i (For 迴圈中的計數器),而這個變數表示工作的相對完成度。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> for($i = 1; $i -lt 101; $i++ ) {write-progress -activity Updating -status progress-> -percentcomplete $i -currentOperation OuterLoop} for($i = 1; $i -lt 101; $i++ ) {write-progress -activity Updating -status progress -percentcomplete $i -id 1 -currentOperation InnerLoop} Updating progress -> [oooooooooooooooooo ] OutsideLoop Updating progress [oooooooooooooooooo ] InnerLoop </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會顯示兩個巢狀 For 迴圈的進度,而每個 For 迴圈都以一個進度列代表。 第二個進度列的 Write-Progress 命令包含 Id 參數,以便區別於第一個進度列。如果沒有 Id 參數,進度列會互相覆蓋,而不是一上一下顯示。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $events = get-eventlog -logname system C:\PS> $events | foreach-object -begin {clear-host;$i=0;$out=""} ` -process {if($_.message -like "*bios*") {$out=$out + $_.Message}; $i = $i+1;` write-progress -activity "Searching Events" ` -status "Progress:" -percentcomplete ($i/$events.count*100)} ` -end {$out} </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令會為要尋找系統事件記錄檔中 "bios" 字串的命令顯示進度。 這個命令的第一行,Get-EventLog Cmdlet 會取得系統記錄檔的事件,然後將這些事件儲存到 $events 變數。 在第二行中,這些事件會經由管道輸出至 ForEach-Object Cmdlet。在開始處理之前,Clear-Host Cmdlet 會用來清除螢幕、將計數器變數 $i 設為零,並將 $out 輸出變數設為空白字串。 第三行,即 ForEach-Object Cmdlet 的 Process 指令碼區塊,此 Cmdlet 會搜尋每個傳入的物件的 message 屬性以找出 "bios"。如果找到該字串,就會在 $out 中加入訊息。 第四行,計數器變數 $i 會增加 1 以記錄「又檢查了一個事件」。 第五行,使用 Write-Progress Cmdlet 搭配 Activity 和 Status 文字欄位的值,這兩個欄位會分別建立進度列標題的第一行和第二行。PercentComplete 參數值的計算方式是將已處理的事件數 ($i) 除以擷取的事件總數 ($events.count),再將該結果乘以 100。 最後一行,ForEach-Object Cmdlet 的 End 參數是用來顯示 $out 變數中儲存的訊息。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113428</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Verbose</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Error</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Debug</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Output</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Warning</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Write-Verbose </command:name> <maml:description> <maml:para>將文字寫入詳細訊息資料流。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Write</command:verb> <command:noun>Verbose</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Write-Verbose Cmdlet 會在 Windows PowerShell 中將文字寫入詳細訊息資料流。基本上,詳細訊息資料流是用來傳遞有關命令處理的資訊,用於偵錯命令。 根據預設,雖然系統不會顯示詳細訊息資料流,不過您可以變更 $VerbosePreference 變數的值或在任何命令中使用 Verbose 一般參數,藉以顯示此資料流。 </maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Write-Verbose</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Message</maml:name> <maml:description> <maml:para>指定要顯示的訊息。此參數為必要項。您也可經由管道將訊息字串輸出至 Verbose-Message。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Message</maml:name> <maml:description> <maml:para>指定要顯示的訊息。此參數為必要項。您也可經由管道將訊息字串輸出至 Verbose-Message。 </maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含訊息的字串輸出至 Write-Verbose。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Write-Verbose 只會寫入詳細訊息資料流。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> Write-Verbose -message "Searching the Application Event Log." C:\PS> Write-Verbose -message "Searching the Application Event Log." -verbose </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會使用 Write-Verbose Cmdlet 來顯示狀態訊息。根據預設,系統不會顯示此訊息。 第二個命令會使用 Verbose 一般參數,以便顯示任何詳細訊息,不論 $VerbosePreference 變數的值為何。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $VerbosePreference = "Continue" C:\PS> Write-Verbose "Copying file $filename" </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這些命令會使用 Write-Verbose Cmdlet 來顯示狀態訊息。根據預設,系統不會顯示此訊息。 第一個命令會將 "Continue" 值指派給 $VerbosePreference 喜好設定變數。預設值 "SilentlyContinue" 會抑制詳細訊息。 第二個命令會寫入詳細訊息。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113429</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Error</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Warning</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Preference_Variables</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> <!-- v 1.1.0.9 --> <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10"> <command:details> <command:name> Write-Warning </command:name> <maml:description> <maml:para>寫入警告訊息。</maml:para> </maml:description> <maml:copyright> <maml:para></maml:para> </maml:copyright> <command:verb>Write</command:verb> <command:noun>Warning</command:noun> <dev:version></dev:version> </command:details> <maml:description> <maml:para>Write-Warning Cmdlet 會將警告訊息寫入 Windows PowerShell 主機。對警告的回應取決於使用者的 $WarningPreference 變數值和一般的 WarningAction 參數的使用。</maml:para> </maml:description> <!-- Cmdlet syntax section--> <command:syntax> <command:syntaxItem> <maml:name>Write-Warning</maml:name> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Message</maml:name> <maml:description> <maml:para>指定警告訊息。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> </command:parameter> </command:syntaxItem> </command:syntax> <!-- Cmdlet parameter section --> <command:parameters> <command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="1"> <maml:name>Message</maml:name> <maml:description> <maml:para>指定警告訊息。</maml:para> </maml:description> <command:parameterValue required="true" variableLength="false">string</command:parameterValue> <dev:type> <maml:name>string</maml:name> <maml:uri /> </dev:type> <dev:defaultValue></dev:defaultValue> </command:parameter> </command:parameters> <!-- Input - Output section--> <command:inputTypes> <command:inputType> <dev:type> <maml:name>System.String</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> 您可經由管道將包含警告的字串輸出至 Write-Warning。 </maml:para> </maml:description> </command:inputType> </command:inputTypes> <command:returnValues> <command:returnValue> <dev:type> <maml:name>無</maml:name> <maml:uri /> <maml:description /> </dev:type> <maml:description> <maml:para> <!-- description --> Write-Warning 只會寫入警告資料流。它不會產生任何其他輸出。 </maml:para> </maml:description> </command:returnValue> </command:returnValues> <!-- Error section--> <command:terminatingErrors /> <command:nonTerminatingErrors /> <!-- Notes section --> <maml:alertSet> <maml:title></maml:title> <maml:alert> <maml:para> $WarningPreference 變數的預設值為 "Continue",即在顯示警告後再繼續執行命令。若要判斷喜好設定變數 (例如 $WarningPreference) 的有效值,請將它設為任意字元的字串,例如 "abc"。產生的錯誤訊息將會列出有效值。 </maml:para> </maml:alert> <maml:alert> <maml:para></maml:para> </maml:alert> </maml:alertSet> <!-- Example section --> <command:examples> <command:example> <maml:title> -------------------------- 範例 1 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> write-warning "This is only a test warning." </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令將會顯示「警告:This is only a test warning.」。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 2 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $w = "This is only a test warning." C:\PS> $w | write-warning </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個範例會示範您可以使用管線運算子 (|) 將字串傳送給 Write-Warning。您可以將該字串儲存到變數,如這個命令所示,或經由管道將該字串直接輸出至 Write-Warning。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 3 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> $warningpreference Continue C:\PS> write-warning "This is only a test warning." This is only a test warning. C:\PS> $warningpreference = "SilentlyContinue" C:\PS> write-warning "This is only a test warning." C:\PS> C:\PS> $warningpreference = "Stop" C:\PS> write-warning "This is only a test warning." WARNING: This is only a test message. Write-Warning : Command execution stopped because the shell variable "WarningPreference" is set to Stop. At line:1 char:14 + write-warning <<<< "This is only a test message." </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令示範 $WarningPreference 變數值在 Write-Warning 命令上的效果。 第一個命令會顯示 $WarningPreference 變數的預設值,即 "Continue"。因此,當您寫入警告時,會出現警告訊息,但執行會繼續。 當您變更 $WarningPreference 變數的值時,Write-Warning 命令的效果會再次變更。值為 "SilentlyContinue" 會隱藏訊息。值為 "Stop" 會顯示警告後再停止命令的執行。 如需 $WarningPreference 變數的詳細資訊,請參閱 about_Preference_Variables。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> <command:example> <maml:title> -------------------------- 範例 4 -------------------------- </maml:title> <maml:introduction> <maml:para>C:\PS></maml:para> </maml:introduction> <dev:code> write-warning "This is only a test warning." -warningaction Inquire WARNING: This is only a test warning. Confirm Continue with this operation? [Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): </dev:code> <dev:remarks> <maml:para>描述</maml:para> <maml:para>-----------</maml:para> <maml:para>這個命令示範一般的 WarningAction 參數在 Write-Warning 命令上的效果。您可以使用一般的 WarningAction 參數搭配任何 Cmdlet,以決定 Windows PowerShell 對那個命令所產生之警告的回應方式。一般的 WarningAction 參數只會覆寫該特定命令的 $WarningPreference 值。 這個命令會使用 Write-Warning Cmdlet 顯示警告。值為 "Inquire" 的一般 WarningAction 參數會指示系統在命令顯示警告時提示使用者。 如需 WarningAction 一般參數的詳細資訊,請參閱 about_CommonParameters。</maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> <maml:para></maml:para> </dev:remarks> <command:commandLines> <command:commandLine> <command:commandText></command:commandText> </command:commandLine> </command:commandLines> </command:example> </command:examples> <!-- Link section --> <maml:relatedLinks> <maml:navigationLink> <maml:linkText>Online version:</maml:linkText> <maml:uri>http://go.microsoft.com/fwlink/?LinkID=113430</maml:uri> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_Preference_Variables</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>about_CommonParameters</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Debug</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Error</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Host</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Output</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Progress</maml:linkText> <maml:uri /> </maml:navigationLink> <maml:navigationLink> <maml:linkText>Write-Verbose</maml:linkText> <maml:uri /> </maml:navigationLink> </maml:relatedLinks> </command:command> </helpItems>