qq70191 发表于 2018-9-3 07:27:02

04 使用PowerShell管理组策略02-Cantgis

function Map-Drive  
{
  
param(
  
    $DriveLetter,
  
    $Share,
  
    $Domain,
  
    $GroupName
  
)
  
Write-Host "Writing Drive Mapping: $DriveLetter"
  
$gpo = Get-SDMGPObject "gpo://qq.414141.com/Drive Mapping Policy" -OpenbyName
  
$path ='User Configuration/Preferences/Windows Settings/Drive Maps'
  
$drives = $gpo.GetObject($path)
  
$map = $drives.Settings.AddNew($DriveLetter)
  
$map.Put('Action','Create')
  
$map.Put('Drive Letter',$DriveLetter)
  
$map.Put('Location',$Share)
  
$map.put('Reconnect', $true)
  
$map.Put('Label as', $DriveLetter)
  
# now do ILT
  
$objUser = New-Object System.Security.Principal.NTAccount $Domain, $GroupName
  
$strSID = $objUser.Translate()
  
$iilt = $GPO.CreateILTargetingList()
  
$itm = $iilt.CreateIILTargeting('FilterGroup')
  
$itm.put('Group',$groupName)
  
$itm.put('UserInGroup',$true)
  
$itm.put('SID',$strSID.Value)
  
$iilt.Add($itm)
  
# now add ILT to drive mapping and save the setting
  
$map.Put('Item-level targeting',$iilt)
  
$map.Save()
  
}
  
$driveInfo = Import-Csv -Path c:\data\drivemaps.csv
  
foreach ($drive in $driveInfo)
  
{
  
Map-Drive -DriveLetter $drive.DriveLetter -Share $drive.Share `
  
            -Domain $drive.Domain -GroupName $drive.GroupName
  
}


页: [1]
查看完整版本: 04 使用PowerShell管理组策略02-Cantgis