py -m pip install chromedriver_install
Requirement already satisfied: chromedriver_install in c:\users\bckelley\appdata\local\programs\python\python38-32\lib\site-packages (1.0.3)
有谁知道如何解决这个问题?
我有一个批处理文件,它查看 inf 文件并找到 open= Open= 或 OPEN= 并让程序运行。
@echo off
setlocal ENABLEDELAYEDEXPANSION
set _drive=W:
set _cmd=
cd /d !_drive!\
for /f "tokens=1,2* delims==" %%i in (autorun.inf) do (
if "%%i"=="open" set _cmd=%%j
if "%%i"=="Open" set _cmd=%%j
if "%%i"=="OPEN" set _cmd=%%j
)
if not defined _cmd (
echo Unable to parse autorun.inf and find 'open='
) else (
!_drive!\!_cmd!
START !_drive!
)
endlocal
我希望有人比我自己更擅长powershell,因为我一直在网上寻找一些东西。所以我应该提到这是这里的OP
所以我已经知道这个代码是
Set-VM -Name "localhost" -Notes "127.0.0.1"
使用
$ipAddress = get-vm | where { $_.state -eq 'running'} | get-vmnetworkadapter | Select @{Name="IP";Expression={$_.IPAddresses | where {$_ -match "^192\."}}} | Sort VMName
获取我的 IP 地址
IP
--
127.0.0.1
所以完整的代码是这样的
$ipAddress = get-vm | where { $_.state -eq 'running'} | get-vmnetworkadapter | Select @{Name="IP";Expression={$_.IPAddresses | where {$_ -match "^192\."}}} | Sort VMName
Set-VM -Name "server1" -Notes "$ipAddress"
但是当我添加 foreach 循环时
$vms = Get-VM
$ipAddress = get-vm | where { $_.state -eq 'running'} | get-vmnetworkadapter | Select @{Name="IP";Expression={$_.IPAddresses | where {$_ -match "^192\."}}} | Sort VMName
foreach ($vm in $vms) {
Set-VM -Name "$vm" -Notes "$ipAddress"
}
为每个虚拟机产生这样的错误
Set-VM : The specified wildcard character pattern is not valid: VirtualMachine (Name = 'server1') [Id = 'de0994fb-c19b-48a3-9389-fd595bd3dc43']
At line:2 char:5
+ Set-VM -Name "$vm" -Notes "$ipAddress"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VM], VirtualizationException
+ FullyQualifiedErrorId : Unspecified,Microsoft.HyperV.PowerShell.Commands.SetVM
我不明白为什么它可以在没有循环但不能使用的情况下工作
编辑:根据 Pimp Juice IT 的建议来回应
VirtualMachine (Name = 'server1') [Id = 'de0994fb-c19b-48a3-9389-fd595bd3dc43'] VirtualMachine (Name = 'server2') [Id = 'ecb80604-1f4a-4493-97cd-14d474baca30'] VirtualMachine (Name = 'server3') [Id = '71a01492-f70e
-420e-9db8-1718ac5d9b41'] VirtualMachine (Name = 'server4') [Id = '500387d7-95e0-44a6-9819-425d4b7af876'] VirtualMachine (Name = 'server5') [Id = '4eef3925-1ae5-4410-8fee-2f99bbfd7ec5'] VirtualMachine (Name = 'serv
er6') [Id = '337f1016-4001-457e-b231-b84173efd695'] = Get-VM
@{IP=192.168.0.39} = get-vm | where { .state -eq 'running'} | get-vmnetworkadapter | Select @{Name=
IP;Expression={.IPAddresses | where { -match ^192\.}}} | Sort VMName
foreach (VirtualMachine (Name = 'server6') [Id = '337f1016-4001-457e-b231-b84173efd695'] in VirtualMachine (Name = 'server1') [Id = 'de0994fb-c19b-48a3-9389-fd595bd3dc43'] VirtualMachine (Name = 'server2') [Id = 'e
cb80604-1f4a-4493-97cd-14d474baca30'] VirtualMachine (Name = 'server3') [Id = '71a01492-f70e-420e-9db8-1718ac5d9b41'] VirtualMachine (Name = 'server4') [Id = '500387d7-95e0-44a6-9819-425d4b7af876'] VirtualMachine (
Name = 'server5') [Id = '4eef3925-1ae5-4410-8fee-2f99bbfd7ec5'] VirtualMachine (Name = 'server6') [Id = '337f1016-4001-457e-b231-b84173efd695']) {
Set-VM -Name VirtualMachine (Name = 'server6') [Id = '337f1016-4001-457e-b231-b84173efd695'] -Notes @{IP=192.168.0.39}
}