ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

PowerShell使用教程

2020-05-21 19:57:35  阅读:350  来源: 互联网

标签:教程 exe get process notepad System read 使用 PowerShell


1、打开powershell 不说了   

2、 获取帮助:    get-help   (所有命令都是cmdlet格式,help也不例外)

3、查看有哪些命令:  get-command  (可看到命令类型有:Alias别名、Cmdlet命令、Function函数)

4、查看以 get开头的命令: get-command get-*

5、查看get-process命令的用法:  get-help get-process

6、用get-process查找进程notepad :get-process -name *notepad*  (当前,你得先打开一个记事本notepad.exe)

7、获取stop-process在线帮助: get-help stop-process -Online

8、用stop-process杀除进程notepad:Stop-Process -Name "notepad"

想想还能干什么

9、下载文件

$webRequest = [System.Net.HttpWebRequest]::Create("http://go.microsoft.com/fwlink/?LinkID=149156")
$webRequest.Method = "GET";
$webRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"

$response = $webRequest.GetResponse()
$stream = $response.GetResponseStream()

$reader = New-Object System.IO.BinaryReader($stream)
$bytes = New-Object System.Byte[] $response.ContentLength 

for ($read = 0; $read -ne $bytes.Length; $read += $reader.Read($bytes,$read,$bytes.Length - $read) ){ }
[System.IO.File]::WriteAllBytes("c:tempSilverLight.exe",$bytes);

将上述代码copy到powershell 后,下载到哪儿了?

执行pwd   显示c:\users\用户名   到这个目录下找到了tempSilverLight.exe   (原来在原代码中c:少了\,但容错能力很强,呵呵)

10、下载并安装MICROSOFT® REPORT VIEWER 2015 RUNTIME

#添加程序集
Add-Type -AssemblyName System.IO
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem

#下载地址
$DownloadUrl = "https://download.microsoft.com/download/A/1/2/A129F694-233C-4C7C-860F-F73139CF2E01/ENU/x86/ReportViewer.msi"
#下载到Temp目录
$TempPath = $env:TEMP
#下载的文件名
$FileName = "ReportViewer.msi"
#存储的完整文件路径
$FullPath = "$TempPath\$FileName"

#Download
$client = New-Object System.Net.WebClient
"Now is downloading MICROSOFT® REPORT VIEWER 2015 RUNTIME"
$client.DownloadFile($DownloadUrl, $FullPath)
"Download success"

#Install
msiexec.exe /i $FullPath /qr

"Press any key to exit"
Read-Host

11、卸载MICROSOFT® REPORT VIEWER 2015 RUNTIME

 msiexec.exe /x "{3ECE8FC7-7020-4756-A71C-C345D4725B77}" /qr

可以指定msi安装包,也可以指定ProductCode,可以访问从注册表以下位置查找ProductCode。

计算机\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

如果是压缩包式的安装包,如 Microsoft Visual C++ 2015 Redistributable,

可以直接使用 vc_redist.x86.exe /?查看自动化安装的参数。

也可以使用Winrar等压缩软件,解压出msi安装包,继续使用msiexec.exe执行自动化安装。

这样就可以自动安装软件运行环境了。

注意:msiexec要以管理员权限运行,否则会弹出UAC对话框。要么就关闭UAC功能。

 

 

参考:https://www.cnblogs.com/lsdb/p/9531338.html

https://www.cnblogs.com/dreamer-fish/p/5583145.html

https://www.cnblogs.com/zhaotianff/p/11558602.html

 

标签:教程,exe,get,process,notepad,System,read,使用,PowerShell
来源: https://www.cnblogs.com/pu369/p/12933242.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有