Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将此PowerShell命令输出获取到iterable集合或数组中_Powershell_Powershell Remoting_.net Framework Version - Fatal编程技术网

如何将此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
,而是字符串的格式-try
foreach($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