首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell -如何Ping DirectAccess IPSec隧道终结点?

PowerShell -如何Ping DirectAccess IPSec隧道终结点?
EN

Stack Overflow用户
提问于 2020-04-30 12:37:26
回答 1查看 134关注 0票数 0

问候各位收件人,

这是我在这里的第一个问题,在潜伏了很长时间之后。我是PowerShell新手,目前正在处理的一件事是创建一个脚本,该脚本将获取系统信息、映射的驱动器、网络配置等。我希望能够从DirectAccess IPSec隧道终结点获取IPv6地址并对其执行ping操作。我希望你能为我解释一下这件事

这是我到目前为止所得到的:

代码语言:javascript
复制
##----------------------------------------------------------
## Variables
##----------------------------------------------------------
$Command = {[PSCustomObject]@{
    'computerSystem' = get-wmiobject Win32_ComputerSystem
    'computerMappedDrives' = Get-WmiObject -Class Win32_MappedLogicalDisk | Select-Object name,providername
    'computerEventErrorsApp' = Get-EventLog -LogName Application -EntryType Error -Newest 10 | Select-Object timegenerated,source,message 
    'computerEventErrorsSys' = Get-EventLog -LogName System -EntryType Error -Newest 10 | Select-Object timegenerated,source,message
    'computerDAClient' = Get-DAClientExperienceConfiguration
    'computerDAStatus' = Get-DAConnectionStatus
    'computerOfflineFiles' = Get-WmiObject -Class win32_OfflineFilesCache
}}
$data = Invoke-Command -ScriptBlock $Command

Logging -Text ("HOSTNAME              : " + $env:COMPUTERNAME) -LogFile $logfile
Logging -Text ("USER LOGGED IN        : " + $data.computerSystem.UserName) -LogFile $logfile
Logging -Text ("DIRECT ACCESS NAME    : " + $data.computerDAClient.FriendlyName) -LogFile $logfile
Logging -Text ("DIRECT ACCESS STATUS  : " + $data.computerDAStatus.Status) -LogFile $logfile
Logging -Text ("OFFLINE FILES         : " + ($data.computerOfflineFiles | Select-Object Enabled)) -LogFile $logfile

##----------------------------------------------------------
## Network Drives
##----------------------------------------------------------
foreach ($mappeddrive in $data.computerMappedDrives)
{    
    Logging -Text ("NETWORK DRIVES MAPPED : " + $mappeddrive.name + " -> " + $mappeddrive.providername) -LogFile $logfile
}

Write-Host "-NETWORK DRIVES COLLECTED-" -ForegroundColor Green

这是执行此命令的结果

代码语言:javascript
复制
$data.computerdaclient



Description                      : DA Client Settings
CorporateResources               : {HTTP:http://directaccess-WebProbeHost.xxx, HTTP:http://directaccess-webprobehost.xxx/}
IPsecTunnelEndpoints             : {PING:fd51:3db1:xxxx:xxxx::1, PING:fd51:3db1:xxxx:xxxx::2, PING:fd45:4035:xxxx:xxxx::1, PING:fd45:4035:xxxx:xxxx::2}
CustomCommands                   : 
PreferLocalNamesAllowed          : True
UserInterface                    : True
PassiveMode                      : False
SupportEmail                     : DA_support@xxxx
FriendlyName                     : Direct Access
ManualEntryPointSelectionAllowed : True
GslbFqdn                         :
ForceTunneling                   : Default

关于如何从IPSecTunnelEndpoint中提取值并随后执行ping有什么想法吗?提前向您表示感谢!干杯,贡萨洛

EN

回答 1

Stack Overflow用户

发布于 2020-05-01 12:15:36

我想我现在已经让它工作了:

代码语言:javascript
复制
(Get-DAClientExperienceConfiguration).IPsecTunnelEndpoints | ForEach-Object{

    If($_ -like '*PING:*'){
        $ipsec= $_.replace('PING:','')
        Write-Host ("TEST CONNECTION TO: " + $ipsec)
        Test-Connection $ipsec
    }
}

结果是:

代码语言:javascript
复制
TEST CONNECTION TO: fd45:4035:xxxx:1000::2

Pinging fd45:4035:xxxx:1000::2 with 32 bytes of data:
Reply from fd45:4035:xxxx:1000::2: time=6ms 
Reply from fd45:4035:xxxx:1000::2: time=9ms 
Reply from fd45:4035:xxxx:1000::2: time=13ms 
Reply from fd45:4035:xxxx:1000::2: time=14ms 

Ping statistics for fd45:4035:xxxx:1000::2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 6ms, Maximum = 14ms, Average = 10ms
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61516012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档