Sun*_*une 0 powershell arguments start-job
$Computers = Get-QADComputer -sizelimit 5
Run Code Online (Sandbox Code Playgroud)
返回五台计算机的列表.我循环
foreach($computer in $computers) {
echo "and then I can do this $computer.name"
Run Code Online (Sandbox Code Playgroud)
从$计算机中只获取计算机名称.但是当我试图将它传递给这样的开始工作时:
Start-Job -FilePath $ScriptFile -Name $Computer.Name -ArgumentList $Computer
Run Code Online (Sandbox Code Playgroud)
我无法在$ scriptfile中执行$ computer.name.我必须像$ computer.name一样传递它并将其称为$ args [0].但后来我松开了所有其他属性(我在$ scriptfile中使用了一堆.)
我没有到这里来的是什么?你会叫什么电脑?那你叫什么叫$ computer.name?
淑娜:)
您应该能够使用$ args [0] .Name获取Name属性.如果你想访问name参数,如下所示:$ computer.name,那么你需要在$ ScriptFile中定义一个参数:
param(
$Computer
)
$Computer.name
Run Code Online (Sandbox Code Playgroud)
顺便说一句'你不能这样做:
echo "and then I can do this $computer.name"
Run Code Online (Sandbox Code Playgroud)
PowerShell仅扩展$ computer的值.把它放在一个子表达式中:
echo "and then I can do this $($computer.name)"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1838 次 |
| 最近记录: |