代码改变世界

电脑操作 powershell

2020-05-19 18:41  qgbo  阅读(219)  评论(0编辑  收藏  举报

1. Dos 设置剪切板内容  echo helloworld |clip

    powershell:                Set-Clipboard "helllo"

 

2. mstsc C:\Users\bb\Documents\Default.rdp  /console /v:  203.23.43.244。

3  想把一个global.json 复制到各个文件夹下,执行下面的脚本    ls | ? {$_.PSIsContainer -eq "False"} | foreach-object { Copy-Item -Path global.json   -Destination $_.FullName -Force }

4  遍历组的邮箱

$g="group1","group2""group3";

$g | foreach-object { echo $_; Get-ADGroupMember -identity $_ -Recursive | Get-ADUser -Property * | select mail;echo ------------------ }

 5. WCF 更新服务,写了一些脚本,核心如下:

 

1. 字符串和var 拼接,最好带上()

$out= ("dotnet dotnet-svcutil.dll http://localhost/aaawebservices/"+$d+" --outputDir "+ $p+ " --namespace *," + $ser)
echo $out

 Invoke-Expression  $out

2. 遍历

$service="D:\FSO\aaaa\Connected Services\"
$folder= (ls $service).Name

foreach ($ser in $folder)
{
}

3.  split
$data = Get-Content -Path $Path -Raw | ConvertFrom-Json
$data = $data.ExtendedData.inputs -split 'ac----swebservices/'

4. replace
$t="namespace "+$ser

$c=Get-Content -Path $Path -Raw

$c=$c -replace "namespace [a-z.]*",$t  // 没有最后一个参数就是delete,  注意如果有 ? 的需要转义
set-Content $Path $c

 

3.在我的电脑上 :

PS C:\Users\bb>  Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PS...

而在VS 中的PM中是这样:

PM>  Get-Module 

ModuleType Version    Name                                ExportedCommands                                                                     
---------- -------    ----                                ----------------                                                                     
Script     2.2.4      EntityFrameworkCore                 {Add-Migration, Drop-Database, Enable-Migrations, Get-DbContext...}                  
Script     2.0.0.0    NuGet                               {Add-BindingRedirect, Find-Package, Get-Package, Get-Project...}                     
Script     0.0        profile                                                                                                                  

PM启动的时候 加入了这些模块。