zeromax 发表于 2018-9-3 07:09:41

powershell-path-format

  若要查看 Path 环境变量中的路径,请键入:
  PS> $env:path
  若要将目录添加到 Path 环境变量,请键入:
  PS> $env:path += ";newdirectory"
  例如,若要将 WordPad.exe 文件的目录添加到 Path 变量,请键入:
  PS> $env:path += ";C:\Program Files\Windows NT\Accessories"
  设置命令输出的格式
  在传统的 shell 中,每个工具或命令确定其输出的格式。一些工具允许自定义输出,因此它们包括用于控制输出格式的特殊参数。
  在 Windows PowerShell 中,只有下列 Format cmdlet 才设置输出格式:
  Format-List
  Format-Custom
  Format-Table
  Format-Wide
  其他 cmdlet 都不设置输出格式。因此,无需了解多个工具的格式设置例程和参数。只需了解 Format cmdlet 及其参数即可。
  运行命令时,Windows PowerShell 调用默认的格式化程序,该程序由所显示的数据类型确定。格式化程序确定显示输出的哪些属性以及用列表还是表显示它们。
  例如,使用 Get-Service cmdlet 时,默认显示是一个包含三列的表,如下所示:
  C:\PS> get-service
  Status   Name               DisplayName
  ------   ----               -----------
  RunningAdtAgent         Event Forwarder
  StoppedAlerter            Alerter
  RunningALG                Application Layer Gateway Service
  若要更改任何 cmdlet 的输出格式,请使用管道运算符 (|) 将命令输出发送到 Format cmdlet。
  例如,以下命令会将 Get-Service 命令的输出发送到 Format-List cmdlet。因此,对于每个服务,服务数据被设置为列表格式。
  C:\PS> get-service | format-list
  Name                : AdtAgent
  DisplayName         : Event Forwarder
  Status            : Running
  DependentServices   : {}
  ServicesDependedOn: {eventlog, dnscache}
  CanPauseAndContinue : False
  CanShutdown         : True
  CanStop             : True
  ServiceType         : Win32OwnProcess
  Name                : Alerter
  DisplayName         : Alerter
  Status            : Stopped
  DependentServices   : {}
  ServicesDependedOn: {LanmanWorkstation}
  CanPauseAndContinue : False
  CanShutdown         : False
  CanStop             : False
  ServiceType         : Win32ShareProcess
  Name                : ALG
  DisplayName         : Application Layer Gateway Service
  Status            : Running
  DependentServices   : {}
  在此格式中,不仅数据出现在列表(而不是表)中,而且存在有关每个服务的详细信息。每个服务的数据不是三列,而是有九行数据。Format-List 未检索额外的服务信息。该数据一直在 Get-Service 检索的对象中,但默认的格式化程序 Format-Table 因无法在屏幕上显示三列以上而忽略了它。
  除了确定数据出现在列表中还是表中之外,还可以确定显示对象的哪些属性。例如,Get-Service 的默认显示仅显示服务对象的 Status、Name 和 DisplayName 属性。
  若要查看对象的所有属性,请使用管道运算符 (|) 将命令输出发送到 Get-Member cmdlet。例如,若要查看服务对象的所有属性,请键入:
  get-service | get-member -membertype *property
  TypeName: System.ServiceProcess.ServiceController
  Name                MemberType    Definition
  ----                ----------    ----------
  Name                AliasProperty Name = ServiceName
  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;}
  ServicesDependedOnProperty      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;}
  由于所有这些属性都在 Get-Service 为每个服务检索的对象中,因此可以显示其中任一属性或所有属性。使用 Format cmdlet 的 Property 参数可以选择要显示的属性以及属性的显示顺序。例如,以下命令使用 Format-Table 命令仅显示服务的 Name、ServiceType 和 CanShutDown 属性。
  get-service | format-table name, Servicetype, Canshutdown
  这仅仅是可以对 Windows PowerShell 显示所执行操作的开始。有关更多详细信息,请使用以下命令来阅读有关 Format cmdlet 的帮助:
  get-help format-list
  get-help format-table
  get-help format-wide
  get-help format-custom

页: [1]
查看完整版本: powershell-path-format