windows的grep命令Select-String

2017年6月18日 10:53

 
喜欢用linux的grep命令查找文件内容,用起来很方便,windos是否也有grep命令呢?
 
在powershell中,提供了Select-String命令搜索文件内容
  • 通常用法
select-string -Pattern "Keyword"  -Path *.log
select-string "Error" *.log
  • 忽略大小写
select-string "Error" *.log -casesensitive
  • 多个关键词
select-string keyword1,keyword2 *.log
  • 递归查找
Get-ChildItem -include *.log -recurse |select-string keyword
 
此生必看的科学实验
精神病为什么治不好(上集)
百病之源(上集)
净土大经科注2014

 

评论(1412) 阅读(19341)

wmi接口如何通过Win32_Volume类修改盘符

2017年6月18日 10:06

想要通过wmi接口修改windows盘符,该如何实现呢?wmi提供了Win32_Volume类,通过该类可以修改盘符。
 
  • python脚本
import wmi
_root_conn = wmi.WMI(privileges=["Shutdown"])
query_str = "select * from Win32_Volume where DeviceID like '%%%s%%'" % volume_id
volume = _root_conn.query(query_str)[0]
volume.DriveLetter = "M:"
volume.put()
 
  • powershell脚本
$Drive = Get-WmiObject win32_volume -Filter "Label = 'xxxx'"
$Drive.DriveLetter = "m:"
$Drive.put()

 

Tags: wmi
评论(389) 阅读(13180)

查看windows磁盘剩余空间

2017年4月17日 22:57

  • 在powershell中运行Get-Volume
PS C:\Users\Administrator> Get-Volume

DriveLetter FileSystemLabel FileSystem DriveType HealthStatus OperationalStatus SizeRemaining      Size
----------- --------------- ---------- --------- ------------ ----------------- -------------      ----
G                           NTFS       Fixed     Healthy      OK                    320.86 GB 372.61 GB
            系统保留        NTFS       Fixed     Healthy      OK                    301.87 MB    350 MB
C                           NTFS       Fixed     Healthy      OK                    881.36 GB 931.17 GB
                            NTFS       Fixed     Healthy      OK                    931.31 GB 931.51 GB

 

Tags: hyper-v windows volume
评论(7) 阅读(3075)

hyper-v查看虚拟机启动顺序

2017年2月02日 21:56

PS C:\> get-vm 虚拟机名称 |get-vmbios
VMName            StartupOrder                            NumLockEnabled
------            ------------                            --------------
虚拟机名称        {CD, IDE, Floppy, LegacyNetworkAdapter} False

Tags: powershell
评论(40) 阅读(3500)

powershell如何ping

2017年2月02日 21:47

PS C:\Users\xxx> Test-NetConnection 192.168.1.13
ComputerName           : 192.168.1.13
RemoteAddress          : 192.168.1.13
InterfaceAlias         : 以太网
SourceAddress          : 192.168.1.100
PingSucceeded          : True
PingReplyDetails (RTT) : 0 ms



PS C:\Users\xxx> Test-NetConnection 192.168.1.13 -Port 8000
ComputerName           : 192.168.1.13
RemoteAddress          : 192.168.1.13
RemotePort             : 2179
InterfaceAlias         : 以太网
SourceAddress          : 192.168.1.100
PingSucceeded          : True
PingReplyDetails (RTT) : 0 ms
TcpTestSucceeded       : True

 

Tags: powershell
评论(38) 阅读(2286)