[英]How to map multiple network drives based on a users location using powershell?
试图创建一个Powershell脚本来做到这一点,但是我不知道如何对逻辑进行编码,以了解用户所在的位置以及要映射的网络驱动器。 这将用于旅行的人。
我一直在研究并进行反复试验超过一个星期。
$AustinShares = @(
"\\Austin-2016\Austin"
"\\Austin-2016\PowerCommon"
)
$RaleighShares = @(
"\\Raleigh-2016\PowerCommon"
"\\Raleigh-2016\Scans"
"\\Raleigh-2016\PowerProjectControls"
)
$AllShares = $AustinShares + $RaleighShares
$apiurl = "http://api.ipstack.com/check?access_key=b0639dfc83871399c5d4d122998f0347"
$apiresponse = Invoke-RestMethod -Method Get -URI $apiurl
$hash = @{
IP = $apiresponse.ip
Country = $apiresponse.country_name
RegionName = $apiresponse.region_name
City = $apiresponse.city
}
$result = New-Object PSObject -Property $hash
Write-Output $result
$TestPath = get-wmiobject win32_logicaldisk | Select-Object -expand DeviceID -Last 1 |
ForEach-Object { [char]([int][char]$_[0] + 1) + $_[1] }
If ($apiresponse.region_name -eq $Locations){
ForEach-Object
New-PSDrive -Name $TestPath -Root $DrivePath -Persist -PSProvider "FileSystem"
}
因此,位置API消失了,找到了计算机的位置。 我只需要使用它们所处的状态即可。根据它们所处的状态,为该状态下的办公室映射某些驱动器。 例如,如果他们在北卡罗莱纳州,则绘制Raleigh Shares。 我认为我需要使用“ foreach”命令,但不确定如何将其合并。
为了简单明了,我假设您可以成功确定办公室,并且要在$office
存储由此找到的办公室名称,并且您已经编写了一个函数Get-NextAvailableDrive
,该函数返回用于下一个要分配的驱动器:
Switch ($office) {
"Raleigh" {$sharelist = $RaleighShares}
"Austin" {$sharelist = $AustinShares}
# You can add additional office and their shares here as required
}
ForEach ($share in $sharelist) {
New-PSDrive -Name (Get-NextAvailableDrive) -Root $share -Persist -PSProvider "FileSystem"
}
如果添加新办公室,您所要做的就是将办公室位置添加到交换机中,并安排在上方的交换机中将该办公室的份额列出来分配给$ sharelist。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.