但是,如何获得默认长路径名称的短路径名称呢?一种方法是使用 Windows 脚本宿主使用的旧 COM 组件:
1 2 3 4 5 6 7 8 9 10 11
# take any path # in this example, I am taking the path where Powershell 7 is installed # this requires that PowerShell 7 in fact is installed. # You can use any other path as well $path = (Get-Command-Name pwsh).Source
"Long path: $path"
# convert it to 8.3 short name $shortPath = (New-Object-ComObject Scripting.FileSystemObject).GetFile($path).ShortPath "Short path: $shortPath"
结果看起来像这样:
Long path: C:\Program Files\PowerShell\7\pwsh.exe
Short path: C:\PROGRA~1\POWERS~1\7\pwsh.exe
# this fails when help defaults to show ONLINE help PS> help about_for Get-Help : The online version of this Help topic cannot be displayed because the Internet address (URI) of the Help topic is not specified in the command code or in the help file for the command.
# the -ShowWindow parameter always shows local help in an extra window PS C:\> help about_for -ShowWindow
PS> Update-Help-Verbose VERBOSE: Resolving URI: "https://go.microsoft.com/fwlink/?LinkId=717973" VERBOSE: Your connection has been redirected to the following URI: "https://pshelpprod.blob.core.windows.net/cabinets/powershell-5.1/" VERBOSE: Performing the operation "Update-Help" on target "Microsoft.PowerShell.LocalAccounts, Current Version: 5.2.0.0, Available Version: 5.2.0.0, UICulture: en-US". VERBOSE: Microsoft.PowerShell.LocalAccounts: Updated C:\Users\USERNAME\Dokumente\PowerShell\Help\Microsoft.PowerShell.LocalAccounts\1.0.0.0\en-US\Microsoft.Powershell.LocalAccounts.dll-Help.xml. Culture en-US Version 5.2.0.0 VERBOSE: Resolving URI: "https://go.microsoft.com/fwlink/?linkid=2113632" VERBOSE: Your connection has been redirected to the following URI: "https://pshelp.blob.core.windows.net/powershell/help/7.0/Microsoft.PowerShell.Management/" VERBOSE: Performing the operation "Update-Help" on target "Microsoft.PowerShell.Management, Current Version: 7.0.1.0, Available Version: 7.0.1.0, UICulture: en-US". VERBOSE: Microsoft.PowerShell.Management: Updated C:\Users\USERNAME\Dokumente\PowerShell\Help\en-US\Microsoft.PowerShell.Commands.Management.dll-Help.xml. Culture en-US Version 7.0.1.0 ...
要使用下载的本地帮助文件,您可以在想了解的命令后添加 “-?“ 通用参数:
1 2 3 4 5 6 7 8
PS> Get-Process -?
NAME Get-Process
SYNOPSIS Gets the processes that are running on the local computer or a remote computer. ...
# calculate the parent paths that can contain profile scripts $Paths = @{ AllUser_WPS = $pshome CurrentUser_WPS = Join-Path-Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath"WindowsPowerShell" AllUser_PS = "$env:programfiles\PowerShell\*" CurrentUser_PS = Join-Path-Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath"PowerShell" }
# check all paths for PowerShell scripts ending on "profile.ps1" $Paths.Keys | ForEach-Object { $key = $_ $path = Join-Path-Path$paths[$key] -ChildPath'*profile.ps1' Get-ChildItem-Path$Path | ForEach-Object { # create a custom object with all relevant details for any # found profile script
# name of PowerShell host is the prefix of profile file name if ($_.Name -like'*_*') { $hostname = $_.Name.Substring(0, $_.Name.Length-12) } else { $hostname = 'any' } [PSCustomObject]@{ # scope and PowerShell version is found in the # name of the parent folder Scope = $key.Split('_')[0] PowerShell = $key.Split('_')[1]
TimeCreated LevelDisplayName Id ProviderName Message
----------- ---------------- -- ------------ -------
04.08.2020 13:03:42 Warning 10016 Microsoft-Windows-DistributedCOM The Anwendungsspezifisch permission settings do...
04.08.2020 13:03:20 Error 1 MTConfig An attempt to configure the input mode of a mul...
04.08.2020 13:03:19 Error 1 MTConfig An attempt to configure the input mode of a mul...
04.08.2020 12:58:18 Error 1 MTConfig An attempt to configure the input mode of a mul...
04.08.2020 11:53:38 Error 10010 Microsoft-Windows-DistributedCOM The server Microsoft.SkypeApp_15.61.100.0_x86__...
04.08.2020 11:23:48 Error 10010 Microsoft-Windows-DistributedCOM The server microsoft.windowscommunicationsapps_...
04.08.2020 11:23:41 Error 10010 Microsoft-Windows-DistributedCOM The server Microsoft.SkypeApp_15.61.100.0_x86__...
04.08.2020 11:23:37 Warning 701 Win32k Power Manager has not requested suppression of ...
04.08.2020 11:23:37 Warning 701 Win32k Power Manager has not requested suppression of ...
04.08.2020 11:23:37 Error 10317 Microsoft-Windows-NDIS Miniport Microsoft Wi-Fi Direct Virtual Adapter...