【发布时间】:2019-07-05 18:10:45
【问题描述】:
尝试创建一个 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”命令,但我不确定如何合并它。
【问题讨论】:
标签: powershell networking scripting drive