admin 管理员组文章数量: 1184232
2024年4月17日发(作者:outputstreamreader)
POWERSHELL命令
1. new_item 新建文件或文件夹
a) new-item –name aaa –itemtype directory 在当前目录创建名为aaa的文件夹
b) new-item –path c: -name aaa –itemtype directory 在c:下创建名为aaa的文件夹
c) new-item –name –itemtype file 在当前目录创建名为的文档
d) new-item –name –itemtype file –value “xxx” 在当前目录创建名为的
文档并添加内容xxx
2. get-childitem 查看文件夹(或对象)里的内容
a) get-childitem 查看当前目录下所有文件的信息
b) get-childitem –path c: 查看c:下所有文件的信息
c) get-childitem * -include *.txt 查看当前目录下所有的txt文档信息
d) get-childitem * -exclude *.txt 查看当前目录下除txt文档外的信息
e) get-childitem –include *.txt –recurse 查看当前目录及下属所有子目录中的txt文档
信息
f) get-childitem –include *.txt –recurse –force查看当前目录及下属所有子目录(包括隐
藏及系统文件)中的txt文档信息
3. copy-item 复制文件到另外一个文件夹中
a) copy-item c: -destination d:将C:复制到D:根目录
b) copy-item c:abc –destination d: -recurse 将C:ABC目录及下属子目录中的所有内
容复制到d:根目录
4. move-item将文件剪切到另外一个文件夹中
a) 实例与copy-item相同
5. Remove-item 删除文件
a) Remove-item * 删除当前目录下所有内容
b) Remove-item –path c:abc*.* 删除c:abc文件夹下所有内容
c) Remove-item * -include *.txt 删除当前目录下所有文本文档
6. Get-help 获取命令帮助
a) Get-help new-item 获取new-item命令相关帮助
7. Get-eventlog 查看windows日志
a) Get-eventlog –list 查看windows日志列表名称
b) Get-eventlog –logname system 查看windows日志中系统分类的所有日志
c) Get-eventlog –logname system newest 100 查看windows日志中系统分类的最新100
条日志
8. Clear-eventlog 删除windows日志
a) Clear-eventlog –logname system 删除windows日志中系统分类下的所有日志
9. Get-service 查看系统服务
a) Get-service 查看所有windows服务信息
b) Get-service –name spooler 查看名为spooler的服务信息(-name可省略)
c) Get-service |where{$_.status –eq “running”}查看系统中所有正在运行的服务
d) Get-service|where{$_.name –eq “spooler”}查看系统中名为spooler的服务
10. Where 对前一条语句的结果进行条件筛选
a) Get-childitem|where{$_.name –eq “”}查看当前目录下名为的文档信息
b) Get-service|where{$_.status –eq “stopped”}查看系统中所有停止的服务
11. Format-list 查看前一条语句结果的所有属性
a) Get-service spooler |format-list 查看spooler服务的常用属性,以一行一个属性的形
式显示
b) Get-service spooler|format-list *查看spooler服务的所有属性,以一行一个属性的形
式显示
c) Get-service spooler|format-list name,status 查看spooler服务的name和status属性
12. Set-service 设置服务的属性
a) Set-service spooler –startuptype automatic 将spooler服务的启动状态改为自动(有
automatic,manual,disabled三种状态)
b) Set-service spooler –status running 将spooler服务启动(有running,stopped,paused
三种状态)
13. Start-service 开启服务
a) Start-service spooler 开启spooler服务
14. Stop-service 关闭服务
a) Stop-service spooler 关闭spooler服务
15. Get-wmiobject 获取windows对象
a) Gwmi win32_account 查看windows中所有账号的信息
b) Gwmi win32_logicaldisk 查看windows中所有逻辑磁盘的信息
c) Gwmi win32_account|where{$_.name –eq “administrator”}查看windows中名为
administrator账号的信息
16. 命令行安装dhcp服务器
servermanagercmd –install DHCP 安装DHCP服务(装完后应启动dhcp server服务,方法
略)
netsh dhcp server add scope 192.168.1.0 255.255.255.0 benet newscope 添加dhcp作用
域,IP网段为192.168.1.0,作用域名称为benet,描述是newscope
netsh dhcp add server 激活作用域(工作组环境可省略)
Netsh dhcp server scope 192.168.1.0 add iprange 192.168.1.10 192.168.1.100 DHCP 添加该
作用域可用ip范围(1.10-1.100)
Netsh dhcp server scope 192.168.1.0 add excluderange 192.168.1.50 192.168.1.70 添加该
作用域排除ip范围(1.50-1.70)
netsh dhcp server scope 192.168.1.0 set optionvalue 003 ipaddress 192.168.1.1 添加作用域
选项帮助用户设置网关
netsh dhcp server scope 192.168.1.0 set optionvalue 006 ipaddress 192.168.1.1 添加作用域
选项帮助用户设置dns服务器
17. $ 设置变量
a) $a=”abc” 在系统中设置一个变量,名称为$a,值为abc
b) $a=1在系统中设置一个变量,名称为$a,值为1
c) $a=get-service spooler 在系统中设置一个变量,名称为$a,值为spooler服务
d) $a=get-childitem|where{$_.name –eq “”}在系统中设置一个变量,名称为$a,
值为当前目录下的文档
18. 对象的属性和方法
a) $a=get-service spooler
$() 将系统中的spooler服务存为变量a,并调用start()方法将该服务开启
b) $ 查看变量a的name属性
版权声明:本文标题:POWERSHELL命令 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1713287940a627715.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论