PowerShell的小例子

  • 获得下一分钟的时间:

PS C:\> get-date -DisplayHint time
4:16:33
PS C:\> echo $(get-date -displayhint time).AddMinutes(1).toString()
2007-10-7 4:17:35

  • 单位换算:

PS C:\> 1+1KB+1MB+1GB
1074791425

  • 获取磁盘剩余空间:

PS C:\> Get-WMIObject Win32_LogicalDisk | ForEach-Object {$_.name,[math]::truncate($_.freespace / 1MB)}
C:
1021
D:
6276
E:
4170
F:
4330
G:
2032

  • 向标准输出写警告:

PS C:\> Write-Warning "The folder C:\Scripts2 does not exist."
警告: The folder C:\Scripts2 does not exist.

This entry was posted in PowerShell. Bookmark the permalink.

发表评论

您的电子邮箱不会被公开。 标记为 * 的区域必须填写

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>