Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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
从cmd中的powershell命令获取输出_Powershell_Batch File_Cmd - Fatal编程技术网

从cmd中的powershell命令获取输出

从cmd中的powershell命令获取输出,powershell,batch-file,cmd,Powershell,Batch File,Cmd,我有一个.bat文件,它运行各种cmd命令,还运行以下命令 powershell -c "Get-Acl -Path HKLM:\SOFTWARE\ESRI\License10.0 | Format-List" 该命令的输出是 Path : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\ESRI\License10.0 Owner : BUILTIN\Administrators Group : CORP

我有一个.bat文件,它运行各种cmd命令,还运行以下命令

powershell -c "Get-Acl -Path HKLM:\SOFTWARE\ESRI\License10.0 | Format-List"
该命令的输出是

Path   : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\ESRI\License10.0
Owner  : BUILTIN\Administrators
Group  : CORPOFLONDON\Domain Users
Access : CREATOR OWNER Allow  FullControl
         NT AUTHORITY\SYSTEM Allow  FullControl
         BUILTIN\Administrators Allow  FullControl
         BUILTIN\Users Allow  FullControl
Audit  :
Sddl   : O:BAG:DUD:PAI(A;CIIO;KA;;;CO)(A;CI;KA;;;SY)(A;CI;KA;;;BA)(A;CI;KA;;;BU)
我想通过循环访问值来查找特定的用户和权限级别


做这件事最好的方法是什么?

不太清楚你想做什么。 在powershell中,您可以使用类似以下内容搜索管理员fullcontrol:


Get Acl XXX | select-expand access |?{$.identityreference-match“admin”和$.fileSystemRights-eq“FullControl”}

IMHO您应该直接使用PowerShell,而不是与cmd混合使用

以下是一个例子:

$keyPath = "HKLM:\SOFTWARE\ESRI\License10.0"
$target = "SYSTEM"

"ACL check on $keyPath :"

Get-Acl -Path $keyPath |
    Select-Object -ExpandProperty Access |
    ForEach-Object {    
        if($_.IdentityReference -match $target) {
            "$($_.IdentityReference) : $($_.AccessControlType) $($_.RegistryRights)"
        }    
    }

最好的方法是在PowerShell中执行此操作,而不是在CMD中。我应该添加(现在)它是更大的批处理脚本的一部分我应该添加(现在)它是更大的批处理脚本的一部分。在调用PowerShell脚本时,能否将用户名和需要检查的权限作为参数传递?您能详细介绍一下批处理文件的一般用途吗?它是安装包的一部分,因此安装完成后,批处理文件会检查是否已将适当的文件复制到正确的位置,安装的一部分是将权限应用到注册表,我只想检查注册表权限是否正确应用。这需要在cmd中完成,因为它是更大安装脚本的一部分。