powershell笔记

Add-Content    追加内容到文件       echo "sss"  | Add-Content  C:\Program Files\wmi_exporter\a.log
get-content    查看文件内容 ....
Set-Content    覆盖内容到文件 Set-Content D:\temp\test\test.txt 'Welcome to TutorialsPoint'
Test-Path        判断目录或文件是否存在 Test-Path -Path "${SERVICE_HOME}/WATCHDOG_PID"
Remove-Item  递归删除目录或文件  Remove-Item 'D:\temp\Test Folder' -Recurse
 $变量名字规则  注意$watchdog-log,这样会报错,不允许这样命名
 -ErrorAction SilentlyContinue防止报错

 Get-Process -name $process_name -ErrorAction SilentlyContinue

remove-item ${SERVICE_HOME} -Recurse -Force -ErrorAction SilentlyContinue

if ($?){...}#通过返回值判断是否报错

 .   /path/test.ps1

 载入函数,只能载入ps1结尾的文件。类似这种 .  /path/test.conf   ,会识别不到 

 sc.exe delete删除服务  sc.exe delete $ServiceName
 sc.exe create 添加服务  sc.exe create "Consul" binPath= 空格 "consul.exe arg1 arg2"
 sc.exe  start   启动服务  sc.exe  start “服务名”
 cmd /c 执行cmd命令,如bat文件  cmd /c start_wmi.bat
 curl的注意地方

 curl -XPUT "localhost:9200/mycompany/employee/1" -d "{"""first_name""":"""John""",","""interests""":["""sports""","""music"""]}"

三个""",三个""",三个"""括住内容,代表是字符串,   整数是一个""

 cmd下查看service启动参数

 ps下查看service启动参数

 wmic process where caption="consul.exe" get commandline /value

gwmi win32_process -Filter "name = 'consul.exe'"| select commandline | format-list

 系统默认变量

$pid

$args 

 暂停  cmd /c Pause | Out-Null
 执行ps1文件  powershell.exe -file "uninstall.ps1" 
 执行exe文件  Start-Process -FilePath "${CONSUL_HOME}/consul.exe" -ArgumentList "leave -http-addr=${CURRENT_IP}:${CONSUL_PORT}" -NoNewWindow 

 不输出内容

类似linux的  2>/dev/null

 echo "lalallala"| Out-Null
   
   
   
   
   
   
   
   
   
   
   
posted @ 2018-12-20 16:29  凯文队长  阅读(277)  评论(0编辑  收藏  举报