问题1:判断文件夹和文件:
PS> (Get-Item .\dir).GetType().fullname
System.IO.DirectoryInfo
PS> (Get-Item .\file).GetType().fullname
System.IO.FileInfo
PS> (Get-Item .\file) -is [IO.fileinfo]
True
PS> (Get-Item .\file) -is [IO.DirectoryInfo]
False
问题2:D: 和D:\ 有什么区别,正如你所理解的,这个是规定。即使在cmd.exe 前者是定位到该盘的历史目录,后者是定位到根目录。
问题3:get-item支持那些类型?
这个问题可以换个问法?那些类型支持虚拟驱动器,支持虚拟驱动器的基本上都可以支持get-item。即使你自己自定义的某种类型。
PS> Get-PSDrive
Name Used (GB) Free (GB) Provider Root CurrentLocation
---- --------- --------- -------- ---- ---------------
Alias Alias
C 43.80 36.20 FileSystem C:\ Users\pstips.net
Cert Certificate \
D 5.41 74.44 FileSystem D:\
E 8.32 122.63 FileSystem E:\
Env Environment
F 59.50 20.50 FileSystem F:\
Function Function
H FileSystem H:\
HKCU Registry HKEY_CURRENT_USER
HKLM Registry HKEY_LOCAL_MACHINE
N 25.46 54.54 FileSystem N:\
Variable Variable
WSMan WSMan
更过虚拟驱动器的解释,请参考:
Powershell驱动器变量:http://www.pstips.net/powershell-drive-variables.html
PowerShell 添加个性化驱动器:http://www.pstips.net/powershell-add-special-vital-driver.html