当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 PowerShell 中获取帮助 |获取有关技巧和快捷方式的帮助的示例

作者:精品下载站 日期:2024-12-14 04:57:07 浏览:14 分类:玩电脑

在 PowerShell 中获取帮助 |获取有关技巧和快捷方式的帮助的示例


[玩转系统] 在 PowerShell 中获取帮助 |获取有关技巧和快捷方式的帮助的示例

在 PowerShell 中获取帮助简介

Windows PowerShell 是一种基于 .net 平台构建的脚本语言,旨在自动执行与 Windows 应用程序和管理相关的任务。 PowerShell 一词是语言和运行命令/脚本的界面的组合。 PowerShell 的第一个版本于 2006 年推出。有两种类型的界面可以运行 PowerShell 命令: Windows PowerShell 就像可以运行 PowerShell cmdlet 的命令提示符,而 Windows PowerShell ISE 是可以运行和调试 PowerShell 脚本(PowerShell cmdlet 的编译)的地方。它是一种面向对象的语言,因此可以与 .net 接口集成。它现在是开源的,也可以安装在其他操作系统上。在这篇文章中,我们将了解在 Powershell 中获取帮助的各种示例。

要启动 PowerShell 会话,请在命令提示符中键入“PowerShell”。

PowerShell Cmdlet 和变量:PowerShell 中的命令称为“cmdlet”。可以通过运行以下 cmdlet 获取可用列表。

  • 获取命令:Cmdlet

在 PowerShell 中获取帮助:对于任何人来说,记住任何编程语言的语法或 cmdlet 都是困难且乏味的任务。为了克服这一挑战,PowerShell 有许多帮助文章。要获取有关任何 PowerShell cmdlet 的帮助,可以使用 Get-Help cmdlet。它提供了语法以及将其用于 cmdlet 的方法。例如:Get-Help Get-Process 这将显示 Get-Process Cmdlet 的语法和别名。

在 PowerShell 中获取帮助的示例

在 PowerShell 中获取帮助的示例解释如下:

1. 新建文件夹

Cmdlet:获取帮助新项目

语法:

New-Item [-Path] <string[]> [-ItemType <string>] [-Value <Object>] [-Force] [-Credential <pscredential>] [-WhatIf]
[-Confirm] [-UseTransaction]  [<CommonParameters>]
New-Item [[-Path] <string[]>] -Name <string> [-ItemType <string>] [-Value <Object>] [-Force] [-Credential
<pscredential>] [-WhatIf] [-Confirm] [-UseTransaction]  [<CommonParameters>]

别名: Ni

EG:New-Item -Path ‘C:\Vignesh\NewPowerShellFolder’-ItemType 目录。

输出:这将在指定路径中创建一个新文件夹“NewPowerShellFolder”。

2. 复制项目

Cmdlet:获取帮助复制项目

语法:

Copy-Item [-Path] <string[]> [[-Destination] <string>] [-Container] [-Force] [-Filter <string>] [-Include
<string[]>] [-Exclude <string[]>] [-Recurse] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm]
[-UseTransaction] [-FromSession <PSSession>] [-ToSession <PSSession>]  [<CommonParameters>]
Copy-Item [[-Destination] <string>] -LiteralPath <string[]> [-Container] [-Force] [-Filter <string>] [-Include
<string[]>] [-Exclude <string[]>] [-Recurse] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm]
[-UseTransaction] [-FromSession <PSSession>] [-ToSession <PSSession>]  [<CommonParameters>]

别名:

  • 消费者物价指数
  • CP
  • 复制

EG:New-Item -Path ‘C:\Vignesh\NewPowerShellFolder’-ItemType 目录。

输出:这将在指定路径中创建一个新文件夹“NewPowerShellFolder”。

3. 删除项目

Cmdlet:获取帮助删除项目

语法:

Remove-Item [-Path] <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-Recurse] [-Force]
[-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction] [-Stream <string[]>]  [<CommonParameters>]
Remove-Item -LiteralPath <string[]> [-Filter <string>] [-Include <string[]>] [-Exclude <string[]>] [-Recurse]
[-Force] [-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction] [-Stream <string[]>]
[<CommonParameters>]

别名:

  • rm
  • 目录
  • 德尔
  • 擦除
  • RD

EG:删除项目“C:\Vignesh\Vignesh.txt”。

输出:这将删除 txt 文件。

许多用户第一次可能无法理解 cmdlet 语法,或者某些用户可能需要一些有关如何将参数传递给 cmdlet 的示例。在这种情况下,他们显然会尝试上网并做一些研究。这可以从 PowerShell 窗口本身完成,如下所示,通过使用 Get-Help cmdlet 在线附加。

Get-Help Get-Child Item - 在线,这将在 Internet Explorer 中打开有关 Get-Child Item 的 Microsoft 帮助文章。

在 PowerShell 中获取帮助的技巧和快捷方式

1. 要返回到之前执行的 cmdlet,请按向上箭头。这将引导我们按降序浏览当前 PowerShell 会话中执行的命令。

2. Get-History cmdlet 可用于获取在当前会话中执行的单次运行中的 cmdlet,可以通过运行以下 cmdlet 将其导出到 CSV 文件。

Cmdlet: 获取历史记录 | Export-csv“要导出的路径.csv”

输出:

ID Command Line Execution Status

StartExecutionTime

EndExecutionTime

1 Get-Help Get-Process -Online Completed 11/18/2019 4:33 11/18/2019 4:36 2 Get-Help Get-Process -Online Completed 11/18/2019 4:33 11/18/2019 4:36 3 Get-Help Get-ChildItem -Online Completed 11/18/2019 4:33 11/18/2019 4:36 4 Get-Help Get-ChildItem -Online Completed 11/18/2019 4:33 11/18/2019 4:36 5 Get-Help Get-ChildItem -Online Completed 11/18/2019 4:33 11/18/2019 4:36

结论

本文只是简要介绍了什么是 PowerShell 以及如何使用“获取帮助”来了解 cmdlet。使用 PowerShell 可以完成许多更强大的操作,例如在 Active Directory 中更改属性、连接到 IIS、SQL Server 和 Microsoft Exchange。通过学习 PowerShell,人们可以通过编写一个脚本来处理这些日常任务,从而轻松节省花在日常任务上的工时。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯