PowerShell:将逗号分隔的IPstring转换为IPAddress对象
我正在使用Get-DhcpServerv4Scope cmdlet,并且正在寻找使用-scopeid开关将多个作用域拉入variables。 Get-DhcpServerv4Scope -scopeid 10.1.0.0,10.1.1.0 但是,如果我这样做: $IP = "10.2.0.0,10.1.0.0" Get-DhcpServerv4Scope -scopeid $IP 我得到的错误: Get-DhcpServerv4Scope:无法处理参数'ScopeId'的参数转换。 无法将值“10.2.0.0,10.1.0.0”转换为键入“System.Net.IPAddress []”。 错误:“无法转换值”10.2.0.0,10.1.0.0“键入”System.Net.IPAddress“错误:”指定了无效的IP地址“ 任何人有一个想法如何得到这个转换? 编辑:这是我试图适应这个脚本的脚本。 我想有一个方法将这个脚本指向一个服务器,它重build所有范围。 现在我在一个制表符分隔的文件中输出范围,然后将它们复制并粘贴到Get-dhcpv4scope以将所有范围存储在一个variables中。 我打开任何build议: #GetScopes $ScopeExclusions = Get-DhcpServerv4ExclusionRange [string]$ScopesCSV=Get-DhcpServerv4Scope | Select ScopeID | convertto- csv -notypeinformation $ScopesCSV.replace('" ', ',').replace('"', '').replace('ScopeId,', '') | out-file c:\users\aturner\desktop\csv.txt **Copy contents from file to clipboard** $Scopes=Get-DhcpServerv4Scope -scopeid *PasteScopeCSVListHere* | select ScopeId,Name,Description,SubnetMask,StartRange,EndRange,LeaseDuration #Delete […]