尝试创建一个脚本,该脚本将获取我过滤的Get-Adcomputer列表,然后在每个

时间:2016-10-27 16:59:07

标签: powershell powershell-v2.0 powershell-v3.0 powershell-v4.0 powershell-remoting

首先,  我对powershell很新。每次我认为我得到逻辑我去WTF ..如果这是bash它将是如此容易等..

我到底想做什么......

从AD获取符合Xiopwb*条件的所有计算机。一旦我有了列表,我需要将\\Xiopwb20\Nsiwebroot目录上的权限更改为仅包含域管理员和安全组" webadmins"

我的逻辑:

从AD获取满足Xio*PWB*的所有计算机 只取该列表中对象的名称 永远"名称"在该列表中Get-ACL \\Name from list\Nsiwebroot 去掉 * 添加用户/组。

我有什么:

PS C:\Windows\system32> Get-ADComputer -filter * | Where-Object {$_.Name -like "xiopwb*"} | Select Name |  ForEach-Object { Get-Acl \\$_.Name\nsiwebroot}

所有" ForEach"工作...我只得到我需要的PC的名称等。

尽可能简单,我不需要100行脚本。

由于

**更新**

它是双重\它只是没有显示它...不知道为什么

看起来它正在做我想要的程度。然而它随便吐出的格式很时髦。 @{Name=XIOPWB09}

PS C:\Windows\system32> Get-ADComputer -filter * | Where-Object {$_.Name -like "xiopwb*"} | Select Name | ForEach-Object {get-acl "\\$_\D$\nsiwebroot"} 
  

get-acl:无法找到路径' \ @ {Name = XIOPWB09} \ D $ \ nsiwebroot'因为它不存在   在行:1字符:99   + ... opwb *"} |选择名称| ForEach-Object {get-acl" \ $ _ \ D $ \ nsiwebroot"}   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:ObjectNotFound:(:) [Get-Acl],ItemNotFoundException       + FullyQualifiedErrorId:GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand

     

get-acl:无法找到路径' \ @ {Name = XIOPWB06} \ D $ \ nsiwebroot'因为它不存在   在行:1字符:99   + ... opwb *"} |选择名称| ForEach-Object {get-acl" \ $ _ \ D $ \ nsiwebroot"}   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:ObjectNotFound:(:) [Get-Acl],ItemNotFoundException       + FullyQualifiedErrorId:GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand

1 个答案:

答案 0 :(得分:1)

" Select Name"返回带有表头名称的Object。 " Select -ExpandProperty Name"这里需要什么,它将把它转换为String。

此致

kvprasoon