format fs=ntfs quick:快速格式化选定的分区为 NTFS 文件系统。 使用Diskpart 需要小心,操作不当可能导致数据丢失。在使用前务必确认你要操作的磁盘和分区。 PowerShell 和命令行工具 除了Diskpart,还可以使用 PowerShell 或者命令行工具来执行特定的分区管理操作: PowerShell: 使用Get-Disk 和Get-Partition 命令来获取...
Gets the current date and time.SyntaxPowerShell Copy Get-Date [[-Date] <DateTime>] [-Year <Int32>] [-Month <Int32>] [-Day <Int32>] [-Hour <Int32>] [-Minute <Int32>] [-Second <Int32>] [-Millisecond <Int32>] [-DisplayHint <DisplayHintType>] [-Format <String>] [-AsUT...
Input string was not in a correct format." PS> [string[]] $strings = 'one','two','three' ArrayList(陣列列表)將元素新增至陣列是其最大限制之一,但我們可以轉向一些其他集合來解決這個問題。ArrayList 通常是在我們需要更快速處理的陣列時,首先考慮的選擇之一。 它在我們需要的每個地方都像物件陣列,但...
PS> $date = Get-Date PS> $date.count 1 甚至$null 也有计数属性,但它会返回 0。PowerShell 复制 PS> $null.count 0 这里有一些陷阱,我将在本文稍后介绍检查 $null 或空数组时再来介绍。大小差一错误因为数组从索引 0 开始,所以产生了一个常见的编程错误。 大小差一错误可能通过两种方式引入。第...
Format-Table 显示包含两列的表:ProcessName(Get-Process 属性)和 TotalRunningTime(计算属性)。 TotalRunningTime 属性由具有两个键(Label 和Expression)的哈希表指定。 Label 键指定属性名称。 Expression 键指定计算。 表达式获取每个进程对象的 StartTime 属性,并从 Get-Date 命令(用于获取当前日期和时间)的结果中...
Get-WinEvent 参考 反馈 模块: Microsoft.PowerShell.Diagnostics 获取本地和远程计算机上的事件日志和事件跟踪日志文件中的事件。 语法 PowerShell复制 Get-WinEvent[[-LogName] <String[]>] [-MaxEvents <Int64>] [-ComputerName <String>] [-Credential <PSCredential>] [-FilterXPath <String>] [-Force] [...
Functions don't have to be complicated to be useful. The simplest functions have the following format: Syntax function <function-name> { statements } For example, the following function starts PowerShell with theRun as Administratoroption.
1.4kwatching Forks 7.6kforks Report repository Releases183 v7.5.1 Release of PowerShellLatest Apr 24, 2025 + 182 releases Contributors472 + 458 contributors Languages C#84.0% PowerShell15.1% Roff0.6% Shell0.2% Rich Text Format0.1% HTML0.0%...
Summary: Learn how to display only the current year. How can I use Windows PowerShell to display only the current year? get-date -Format yyyy get-date –format yy get-date –f yyyy (Get-Date).year Get-Date -UFormat %Y Get-Date -UFormat %...
In the following example, the -replace operator accepts a username in the form of DomainName\Username and converts to the Username@DomainName format: PowerShell Copy $SearchExp = '^(?<DomainName>[\w-.]+)\\(?<Username>[\w-.]+)$' $ReplaceExp = '${Username}@${DomainName}' ...