Date : 10/28/2016 3:47:27 PM BIOS : \DESKTOP-7AAMJLF\root\cimv2:Win32_BIOS.Name=”1.4.4”,SoftwareElementID=”1.4.4”,SoftwareElementState=3,TargetOpera tingSystem=0,Version=”DELL - 1072009” Computer : DESKTOP-7AAMJLF OS : Microsoft Windows NT 10.0.14393.0 Remark : Some remark
PS C:> $o.Remark Some remark
PS C:\> $o.OS
Platform ServicePack Version VersionString
-------- ----------- ------- -------------
Win32NT 10.0.14393.0 Microsoft Windows NT 10.0.14393.0
PS C:> $o.OS.VersionString Microsoft Windows NT 10.0.14393.0
PowerShell 将您的所有交互命令行输入“记录”到它的命令行历史中,而 Get-History 负责显示它们。如果您运行了一段时间 PowerShell 并且觉得运行的效果不错,那么可以用以下脚本将所有的交互命令从命令行历史中复制到剪贴板中。接下来您可以将它们粘贴到 PowerShell ISE 中,并使之成为一个脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# define how old your commands may be at most to be included $MaxAgeHours = 4
# get all command history items that were started after this $DateLimit = (Get-Date).AddHours(-$MaxAgeHours)
# get all command-line commands Get-History | # exclude all that were aborted Where-Object ExecutionStatus -eq Completed | # exclude all that are older than the limit set above Where-Object StartExecutionTime -gt$DateLimit | # get just the command-line Select-Object-ExpandProperty CommandLine | # copy all to clipboard clip.exe
functionGet-PublishedModuleVersion($Name) { # access the main module page, and add a random number to trick proxies $url = "https://www.powershellgallery.com/packages/$Name/?dummy=$(Get-Random)" $request = [System.Net.WebRequest]::Create($url) # do not allow to redirect. The result is a "MovedPermanently" $request.AllowAutoRedirect=$false try { # send the request $response = $request.GetResponse() # get back the URL of the true destination page, and split off the version $response.GetResponseHeader("Location").Split("/")[-1] -as [Version] # make sure to clean up $response.Close() $response.Dispose() } catch { Write-Warning$_.Exception.Message } }
$path = 'c:\windows\explorer.exe' # any item type Test-Path-Path$path # just files Test-Path-Path$path-PathType Leaf # just folders Test-Path-Path$path-PathType Container
PS C:\> Get-Help -Name Get-Date -Parameter Format
-Format []
Displays the date and time in the Microsoft .NET Framework format indicated by the
format specifier. Enter a format specifier. For a list of available format
specifiers, see DateTimeFormatInfo Class
(http://msdn.microsoft.com/library/system.globalization.datetimeformatinfo.aspx)
in MSDN.
When you use the Format parameter, Windows PowerShell gets only the properties of
the DateTime object that it needs to display the date in the format that you
specify. As a result, some of the properties and methods of DateTime objects might
not be available.
Starting in Windows PowerShell 5.0, you can use the following additional formats
as values for the Format parameter.
-- FileDate. A file or path-friendly representation of the current date in local
time. It is in the form of yyyymmdd ( using 4 digits, 2 digits, and 2 digits). An
example of results when you use this format is 20150302.
-- FileDateUniversal. A file or path-friendly representation of the current date
in universal time. It is in the form of yyyymmdd + 'Z' (using 4 digits, 2 digits,
and 2 digits). An example of results when you use this format is 20150302Z.
-- FileDateTime. A file or path-friendly representation of the current date and
time in local time, in 24-hour format. It is in the form of yyyymmdd + 'T' +
hhmmssmsms, where msms is a four-character representation of milliseconds. An
example of results when you use this format is 20150302T1240514987.
-- FileDateTimeUniversal. A file or path-friendly representation of the current
date and time in universal time, in 24-hour format. It is in the form of yyyymmdd
+ 'T' + hhmmssmsms, where msms is a four-character representation of milliseconds,
+ 'Z'. An example of results when you use this format is 20150302T0840539947Z.
Required? false
Position? named
Default value none
Accept pipeline input? false
Accept wildcard characters? false
通过这些信息,您现在可以知道如何格式化日期和时间:
1 2 3
$date = Read-Host-Prompt'Enter a date' $weekday = Get-Date-Date$date-Format'dddd' "$date is a $weekday"