我上周发布了与此类似的内容,但这已演变成更复杂的东西。这应该是双重操作。首先,在PrintServer上,然后部署在100-200台机器上。我正在制作一个PSise脚本(几乎是我的第一次),它应该能够以第3个八位字节的形式传播和分组所有子网地址。然后它应该确定连接的打印机及其端口是否满足第4个八位字节在50-60范围内的新架构要求。如果没有,请确定正确子网和范围内的下一个可用地址,并将端口重新分配给下一个可用的端口。我将需要跟踪每个子网的更改,以便用户计算机将与打印服务器所做的更改对齐。因此,如果PrintServer有192.168.1.23>> 192.168.2.50&& 192.168.3.105>> 192.168.3.52,需要分别对子网1和3中的所有机器进行相同的更改。
我知道这个功能可能设置不正确,所以如果我有不合适的地方,请随时告诉我。我感觉所有应该执行更改的代码应该放在处理-begin,-process,-end段的末尾。
这是我到目前为止的代码,我得到了一些我期望的价值观。我只是没有让他们进入正确的阵列并将它们管道输送以供进一步使用。我有一种感觉,我可能需要一个-join,但就像我说的,我没有任何Powershell的经验。
function verify-printerport
{
[CmdletBinding()]
[OutputType([int])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$third = @{},
$fourth = @{},
$thirds = @{},
$fourths = @{},
# Param2 Gets WMI Object -Class -ExtendedProperty -Sorts
$set1 = ( Get-WmiObject -Class Win32_TCPIPPrinterPort | select -ExpandProperty HostAddress | sort )
)
Begin
{
$set1
$thirds = @{0=100, 202, 203, 204, 209, 211, 212, 213, 214, 215, 216, 217, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230}
$fourths = @{49=50..60}
}
Process
{
foreach ($ips in $set1)
{
Where
{
(($ips.HostAddress -Split '\.')[2] -contains $thirds)
} |
ForEach ($getThird)
{
$third.Add($getThird.IndexOf($ips.HostAddress),$getThird.ToArray)
where
{
$getThird.ForEach($ips.HostAddress[2] -eq $thirds)
}
}
}
foreach ($ips2 in $set1) {
where
{
(($ips2.HostAddress -split '\.')[3] -notcontains $fourths)
} |
foreach ($getFourth)
{
$fourth.Add($getFourth,$inRange.Length)
if ( $getFourth.foreach($set1.HostAddress -split '\.'[3] -lt 50) -or
$getFourth.foreach($set1.HostAddress -split '\.'[3] -gt 60))
{
where
{
($set1.ForEach($inRange.HostAddress -split '\.')[3] -contains $fourths)
}
set $inRange.StartsWith($set1.Length)
$inRange.Length ++
}
foreach ($inRange in $getFourth)
{
if ($inRange.ForEach($setRange.HostAddress -split '\.'[3] -contains $fourths))
{
$inRange.GetLength($setRange.GetValue($setRange.Length))
}
}
$inRange += $set1.Length
}
}
}
End
{
}
}
$ thirds和$ 4ths指的是第3/4个八位位组。三分之二是我们拥有的所有子网。 $ fourths是所有打印机应该的范围。
非常感谢您提供的任何帮助。我花了好几天很长时间才来到这里,我知道结束了。其中一些来自搜索,其他来自我的其他帖子,一些来自我试图应用我的其他编程经验(fyi,我还在学校)以及很多只是简单的猜测工作。提前感谢您抽出宝贵时间!