作者:278787061w | 来源:互联网 | 2023-06-21 07:12
Ivegotascriptwhichindexesinformationfromourequipment.Tostoreandanalyzetheinformation
I've got a script which indexes information from our equipment. To store and analyze the information I've created a class:
我有一个脚本来索引我们设备的信息。存储和分析我创建的类的信息:
Add-Type @'
public class CPObject
{
public int id;
public string name;
public string displayname;
public string classname;
public string ip;
public string netmask;
public string ManagementServer;
}
'@
Then when I run the script I've been planning to go through the object class to translate name to IP with the following function:
然后当我运行脚本时,我一直计划通过以下函数通过对象类将名称转换为IP:
Function NameToIP {
Param([int]$id=0, [string]$name="")
$CPObject = $CPNetworkObjects | Where-Object { $_.id -eq $id -and $_.name -eq $name }
If($CPObject.count -eq 1){
$CPObject.ip
} else {
""
}
}
It works, but it's terribly slow as the $CPNetworkObjects contains over 12 000 elements of the type CPObject.
它有效,但它非常慢,因为$ CPNetworkObjects包含超过12 000个CPObject类型的元素。
I want to speed this up. Is there any way to index an array to make the search more efficient or is the only solution to try to lessen the number of objects used?
我想加快速度。有没有办法索引数组以使搜索更有效,或者是尝试减少使用的对象数量的唯一解决方案?
Kind regards, Patrik
亲切的问候,Patrik
3 个解决方案