我一直致力于为具有VPN访问权限的用户简化驱动器映射。
我有一些PS脚本给我一个表格,然后我想为每个列分配一个变量,并将这些变量用户映射到驱动器。
这是我的剧本:
$GPO = Get-GPO -All
foreach ($Policy in $GPO)
{
$GPOID = $Policy.Id
$GPODom = $Policy.DomainName
$GPODisp = $Policy.DisplayName
if (Test-Path "\\$($GPODom)\SYSVOL\$($GPODom)\Policies\{$($GPOID)}\User\Preferences\Drives\Drives.xml")
{
[xml]$DriveXML = Get-Content "\\$($GPODom)\SYSVOL\$($GPODom)\Policies\{$($GPOID)}\User\Preferences\Drives\Drives.xml"
foreach ( $drivemap in $DriveXML.Drives.Drive )
{New-Object PSObject -Property @{
Letter = $drivemap.Properties.Letter + ":"
Path = $drivemap.Properties.Path
Name = $drivemap.Properties.label
}}}}
以下是我的结果:
Letter Path Name
----------- --------- ----------
S: \\share\Share Share
X: \\share1\IT Private IT Private
I: \\share3\IT Department IT Department
F: \\sahre4\Public Public
W: \\share5\EmployeeReference Emplyee
R: \\sahre5\Reports Reports
此时我需要将每列设置为变量,以便我可以为用户映射这些驱动器。
$l = driveletter
$p = drivepath
$n = drivelabel
New-PSDrive -Name $l -root $p
不确定我是否在正确的轨道上。这是几个嵌套的foreach语句吗?
答案 0 :(得分:1)
foreach ($row in $results) {
New-PSDrive -Name $row.Letter -root $row.Path -Description $row.name
}