复制代码
- get-psprovider
PS D:\> get-psprovider Name Capabilities Drives ---- ------------ ------ WSMan Credentials {WSMan} Alias ShouldProcess {Alias} Environment ShouldProcess {Env} FileSystem Filter, ShouldProcess {C, D, E} Function ShouldProcess {Function} Registry ShouldProcess, Transactions {HKLM, HKCU} Variable ShouldProcess {Variable} Certificate ShouldProcess {cert} |
cmdlet | 功能 | cmd command | alias |
get-location | 当前目录 | pwd | gl |
set-location | 改变操作目录 | cd,chdir | sl |
new-item | 新建文件或文件夹 | 无 | ni |
rename-item | 重命名 | rn | rni |
copy-item | 复制 | copy | cpi |
move-item | 移动 | move | mi |
remove-item | 删除 | del | ri |
set-item | 设置内容 | 无 | si |
clear-item | 删除内容 | 无 | cli |
mkdir | 新建文件夹 | md | 无 |
set-content | 设置内容 | 无 | sc |
get-content | 获取内容 | type | gc |
复制代码
- get-psdrive
PS D:\> get-psdrive Name Used (GB) Free (GB) Provider Root CurrentLocation ---- --------- --------- -------- ---- --------------- Alias Alias C 32.40 67.60 FileSystem C:\ cert Certificate \ D 28.30 104.28 FileSystem D:\ E FileSystem E:\ Env Environment Function Function HKCU Registry HKEY_CURRENT_USER HKLM Registry HKEY_LOCAL_MACHINE Variable Variable WSMan WSMan |
我们试着获取一些环境变量的值。复制代码
- cd env:
- ls
显示所有属性:复制代码
- ls OS
复制代码
- ls OS | format-list *
PS Env:\> ls OS | format-list * PSPath : Microsoft.PowerShell.Core\Environment::OS PSDrive : Env PSProvider : Microsoft.PowerShell.Core\Environment PSIsContainer : False Name : OS Key : OS Value : Windows_NT |
下面,我们接着认识一下在"get-childitem"时所显示的"Mode"。复制代码
- new-item -path . -Name New -Value "New"
PS D:\BatHome> ls Directory: D:\BatHome Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 8/30/2013 5:33 PM PowerShell -a--- 8/30/2013 3:03 PM 0 bathome.txt -a--- 8/30/2013 3:03 PM 0 bbs.txt -ar-- 8/30/2013 3:04 PM 0 net.txt |
那么新创建文件呢?我们试试如下命令:复制代码
- ls -force
此时要求输入文件类型,即"file"、"directory",我们使用"f"、"d"即可。复制代码
- new-item newfile
PowerShell中的Function复制代码
- new-item newfile -type f
复制代码
- cd function:
- ls
PS Function:\> ls CommandType Name Definition ----------- ---- ---------- Function A: Set-Location A: Function B: Set-Location B: Function C: Set-Location C: Function cd.. Set-Location .. Function cd\ Set-Location \ Function Clear-Host $space = New-Object System.Management.Automation... ... |
复制代码
- get-content clear-host
PS Function:\> get-content clear-host $space = New-Object System.Management.Automation.Host.BufferCell $space.Character = ' ' $space.ForegroundColor = $host.ui.rawui.ForegroundColor $space.BackgroundColor = $host.ui.rawui.BackgroundColor $rect = New-Object System.Management.Automation.Host.Rectangle $rect.Top = $rect.Bottom = $rect.Right = $rect.Left = -1 $origin = New-Object System.Management.Automation.Host.Coordinates $Host.UI.RawUI.CursorPosition = $origin $Host.UI.RawUI.SetBufferContents($rect, $space) |
证书复制代码
- cd hklm:
- cd software
- ls
复制代码
- cd cert:
- ls
PS Function:\> cd cert: PS cert:\> ls Location : CurrentUser StoreNames : {SmartCardRoot, UserDS, AuthRoot, CA...} Location : LocalMachine StoreNames : {SmartCardRoot, AuthRoot, CA, Trust...} |
好了,这一节内容就到这里~东西比较杂,也比较琐碎,但是这些将大大加深我们对PowerShell的理解与认识,以帮助我们以后更好的学习。复制代码
- ls -Recurse | Export-CSV "d:\Cert.csv"
欢迎光临 批处理之家 (http://www.bathome.net/) | Powered by Discuz! 7.2 |