0

我希望下面的代码在多台计算机上工作 - 知道如何做到这一点吗?我有以下内容,但它失败了,因为我目前没有调用我认为有问题的服务器。

谢谢,

代码:

Write-Host "Script to check Storage Write, Read and Delete Times"
Write-Host "`n"

$computer = Get-Content -path d:\temp\servers.txt
$path = "f:\temp\test.txt"

Foreach ($storage in $computer)
{

$date = Get-Date
Write-Host "Script being run on $date"

$write = Measure-Command { new-item -Path $path -ItemType File -Force } | select TotalMilliseconds 

Write-Host "Writing file on $storage took $write"

$read = Measure-Command { Get-Content -Path $path } | select TotalMilliseconds 

Write-Host "Reading file on $storage took $read"

$delete = Measure-Command {Remove-Item -Path $path -Force } | select TotalMilliseconds 

Write-Host "Deleting file on $storage took $delete"
Write-Host "`n"
}
4

1 回答 1

1

您需要退后一步,重新考虑该方法。您每次都向本地系统上的 f:\temp 发出文件系统命令。

有两种方法可以让远程计算机执行文件系统任务。最简单的方法是使用 UNC 路径。也就是\\server\share格式。假设您具有本地管理员访问权限:

Foreach ($storage in $computer) {
$uncpath = $("\\{0}\f`$\temp\text.txt" -f $storage)
$write = Measure-Command { new-item -Path $uncpath -ItemType #...
# rest of code uses $uncpath for access
}

请注意,使用 UNC 路径会给 LAN 带来一些压力,因此这种类型的测试可能不够准确,也可能不够准确。

第二种方法是使用 Powershell 远程连接远程系统并在那里发出命令。查看New-PSSessionEnter-PSSessionExit-PSSession cmdlet。

于 2012-11-12T11:12:47.967 回答