如何将此PowerShell命令输出获取到iterable集合或数组中
显示如何输出域上的计算机名列表:如何将此PowerShell命令输出获取到iterable集合或数组中,powershell,powershell-remoting,.net-framework-version,Powershell,Powershell Remoting,.net Framework Version,显示如何输出域上的计算机名列表: (([adsi]"WinNT://$((Get-WMIObject Win32_ComputerSystem).Domain)").Children).Where({$_.schemaclassname -eq 'computer'}) 如果附加了路径属性 ... .Where({$_.schemaclassname -eq 'computer'}).Path 它以以下格式输出列表: WinNT://{domainn
(([adsi]"WinNT://$((Get-WMIObject Win32_ComputerSystem).Domain)").Children).Where({$_.schemaclassname -eq 'computer'})
如果附加了路径
属性
... .Where({$_.schemaclassname -eq 'computer'}).Path
它以以下格式输出列表:
WinNT://{domainname}.net/{machine-name}
如何将一系列完全限定的机器名生成一个数组或一个可由找到的脚本迭代的集合
该命令(即其输出)是否可以简单地分配给数组变量
[array]$ComputerNames = ... (([adsi]"WinNT://$((Get-WMIObject <snip> ).Path
我的最终目标是获得安装在域上所有PC上的.NET版本。问题不在于分配给
$ComputerNames
,而是字符串的格式-tryforeach($computerin$ComputerNames-replace'^.*(?=[^/]+$){…}
--replace
操作将从所有字符串中删除机器名称之前的所有内容(包括/
),此时可以删除这些内容used@MathiasR.Jessen:谢谢你的帮助!
$ComputerNames = ... (([adsi]"WinNT://$((Get-WMIObject <snip> ).Path
foreach($computer in $ComputerNames) {
if($regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)) {
Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found."
At C:\Users\{myusername}\Get-NetFrameworkVersion.ps1:40 char:8
+ if($regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('Lo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException