pu369com

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

 

posted on 2020-05-21 19:42  pu369com  阅读(618)  评论(0编辑  收藏  举报

导航