我有PowerShell脚本,它将打开网页(Selenium)并将焦点设置在"消息"框中.现在,我想模拟Ctrl+ V从剪贴板粘贴我的数据.有没有办法在纯PowerShell中做到这一点?可以在powershell函数中使用的C#代码也很棒.
我无法获得完全相同对象的多个元素的当前元素的索引:
$b = "A","D","B","D","C","E","D","F"
$b | ? { $_ -contains "D" }
Run Code Online (Sandbox Code Playgroud)
替代版本:
$b = "A","D","B","D","C","E","D","F"
[Array]::FindAll($b, [Predicate[String]]{ $args[0] -contains "D" })
Run Code Online (Sandbox Code Playgroud)
这将返回:D D D.
但是这段代码:
$b | % { $b.IndexOf("D") }
Run Code Online (Sandbox Code Playgroud)
替代版本:
[Array]::FindAll($b, [Predicate[String]]{ $args[0] -contains "D" }) | % { $b.IndexOf($_) }
Run Code Online (Sandbox Code Playgroud)
返回:
1 1 1
所以它指向第一个元素的索引.如何获取其他元素的索引?
我正在使用此代码来获取Path,VolumeLabel,TotalSize,FreeSpace:
gwmi -ComputerName $ComputerName -namespace root\MSCluster MSCluster_DiskPartition -Credential $cred -Authentication PacketPrivacy | Format-Table Path, VolumeLabel, TotalSize, FreeSpace -AutoSize
Run Code Online (Sandbox Code Playgroud)
输出:
Path VolumeLabel TotalSize FreeSpace
---- ----------- --------- ---------
U: Archive1 4194184 379651
\\?\Volume{76795fb2-254e-454d-a95a-739018690cf4} Archive3 4194184 524883
X: Archive2 4194184 735366
\\?\Volume{57e93910-60f9-44b9-8d9d-29d506e1e3d7} Archive4 4194184 1483274
Run Code Online (Sandbox Code Playgroud)
如何从Volume GUID获取安装点的真实路径(或驱动器名称)?

我尝试使用.GetRelated类,但没有成功.有人可以帮我这个吗?
如果要使用以下命令从网络UNC共享添加程序集:
$scriptPath = Split-Path ($MyInvocation.MyCommand.Path)
Add-Type -path "$scriptPath\selenium-dotnet\net40\WebDriver.dll"
Run Code Online (Sandbox Code Playgroud)
你可能会遇到这样的错误:
Add-Type: Could not load file or assembly 'file:///Z:\A-Backup\Users\Administr
ator\Desktop\MAXIMO Automatic\selenium-dotnet\net40\WebDriver.dll' or one of it
s dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515
)
At Z:\A-Backup\Users\Administrator\Desktop\MAXIMO Automatic\MAXIMO Automatic.ps
1:14 char:1
+ Add-Type -path "$scriptPath\selenium-dotnet\net40\WebDriver.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell
.Commands.AddTypeCommand
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?