OnITRoad - examples

Powershell-Where Object Cmdlet

Powershell-Where Object Cmdlet cmdlet Where-Object cmdlet可用于从传递给它的对象集合中选择具有特定属性值的对象。 例1 查看停止的服务。 Get-Service | Where-Object {$_.Status -eq "Stopped"} 输出 我们可以在PowerShell控制台中看到以下输出。 Sta

Views:0  2019-08-20

Powershell-Get-ChildItem Cmdlet

Powershell-Get-ChildItem Cmdlet Get-ChildItem Cmdlet Get-ChildItem cmdlet可用于获取一个或多个特定位置中的项或子项。 例1 获取变量中的文件详细信息。 $A = Get-ChildItem D:\temp\test\*.txt 使用Format-Wide-cmdlet获取文件详细信息。 Format-Wide -In

Views:0  2019-08-20

Powershell-ForEach Object Cmdlet

Powershell-ForEach Object Cmdlet Cmdlet ForEach Object cmdlet可用于对对象集合的每个对象执行操作。 例1 在这个例子中,我们将遍历一个数组,并除以1000。我们将使用$来引用每个对象。 1000,2000,3000 | ForEach-Object -Process {$_/1000} 输出 我们可以在PowerShell控

Views:0  2019-08-20

Powershell-Start-Sleep Cmdlet

Powershell-Start-Sleep Cmdlet Cmdlet Start-Sleep cmdlet在特定时间段内挂起脚本或会话中的活动。 例1 在本例中,我们将暂停当前进程15秒。 Start-Sleep -s 15 PowerShell控制台在15秒后恢复。 例2 在本例中,我们将挂起当前进程500毫秒。 Start-Sleep -m 500

Views:0  2019-08-20

Powershell-Read-Host Cmdlet

Powershell-Read-Host Cmdlet Cmdlet Read-Host cmdlet用于从控制台读取。 示例 在本例中,我们将要求用户传递一个输入并将输入保存到变量中。 $choice = Read-Host "Please put your choice" Powershell将显示一个弹出窗口来输入值。输入值后,它将保存在$choice变量中。

Views:0  2019-08-20

Powershell-Sort Object Cmdlet

Powershell-Sort Object Cmdlet Cmdlet Sort-Object cmdlet用于按对象的属性对其进行排序。 例1 根据属性对对象进行排序。 Windows 命令行如何查看内存占用最高的进程? Get-Process | Sort-Object -Property WS | Select-Object -Last 5 输出 我们可以看到内存使用率很高的

Views:0  2019-08-20

Powershell-写入警告Cmdlet

Powershell-写入警告Cmdlet Cmdlet Write Warning cmdlet用于写入警告消息。 示例 在本例中,我们将显示一条警告消息。 Write-Warning "Test Warning"

Views:0  2019-08-20

Powershell-Write-Host Cmdlet

Powershell-Write-Host Cmdlet Cmdlet Write-Host cmdlet用于写入自定义消息。 在这个示例中,我们看到了这个命令。 示例 在本例中,我们将显示一个自定义消息。 Write-Host (2,4,6,8,10,12) -Separator ", -> " -ForegroundColor DarkGreen -Backg

Views:0  2019-08-20

Powershell-Invoke-Item Cmdlet

Powershell-Invoke-Item Cmdlet Cmdlet Invoke-Item cmdlet用于对指定项执行默认操作。 示例 在本例中,我们将显示一个自定义消息。 Invoke-Item "D:\Temp\test.txt" 我们可以看到记事本将打开test.txt,因为Powershell将调用文件的默认操作。

Views:0  2019-08-20

Powershell-Invoke-Expression Cmdlet

Powershell-Invoke-Expression Cmdlet Cmdlet Invoke-Expression cmdlet用于在本地计算机上执行命令或表达式。 示例 在本例中,我们将演示如何调用表达式。 > $Command = 'Get-Process' > $Command Get-Process > Invoke-Expression $Comm

Views:0  2019-08-20

Powershell-Measure-CommandCmdlet

Powershell-Measure-CommandCmdlet Cmdlet Measure-Command cmdlet用于测量脚本或命令所用的时间。 示例 在这个例子中,我们将展示如何测量geteventlog命令在PowerShell事件日志中记录事件的时间。 Measure-Command { Get-EventLog "Windows PowerShell"

Views:0  2019-08-20

Powershell-Invoke-HistoryCmdlet

Powershell-Invoke-HistoryCmdlet Cmdlet Invoke-History cmdlet用于从已运行的当前会话运行命令。 示例 在本例中,我们将展示如何使用Invoke-History调用上一个运行的命令。 Invoke-History Measure-Command { Get-EventLog "Windows PowerShell"

Views:0  2019-08-20

Powershell-Add-History Cmdlet

Powershell-Add-History Cmdlet Cmdlet Add-History cmdlet用于在当前历史记录中添加命令。 示例 在本例中,我们将再次将前五个历史命令添加到当前历史记录中。 > get-history Id CommandLine

Views:0  2019-08-20

Powershell-Get-History Cmdlet

Powershell-Get-History Cmdlet Cmdlet Get-History cmdlet用于获取在当前会话中运行的命令。 示例 在本例中,我们将获取在当前历史中运行的命令。 > get-history Id CommandLine

Views:0  2019-08-20

Powershell-Get-Culture Cmdlet

Powershell-Get-Culture Cmdlet Cmdlet Get-Culture cmdlet用于获取windows中的当前区域设置。 示例 在本例中,我们将获得区域性设置。 > get-culture LCID Name DisplayName ---- ----

Views:0  2019-08-20

Powershell-For循环

Powershell-For循环 下面的脚本演示了Powershell中的for循环。 > $array = @("item1", "item2", "item3") > for($i = 0; $i -lt $array.length; $i++){ $array[$i] } item1 item2 item3

Views:0  2019-08-20