简体   繁体   English

PowerShell - 如何 ping DirectAccess IPSec 隧道端点?

[英]PowerShell - How to Ping DirectAccess IPSec Tunnel Endpoints?

Greetings fellow recipient,问候接收者,

This is my first question here, after a long time lurker.这是我在这里的第一个问题,经过很长时间的潜伏。 I'm new to PowerShell, and one of the things that I'm currently working on is to create a script that will get system information, mapped drives, network configuration, etc. I want to be able to get the IPv6 address from DirectAccess IPSec Tunnel Endpoint and ping it.我是 PowerShell 的新手,我目前正在做的一件事是创建一个脚本,该脚本将获取系统信息、映射驱动器、网络配置等。我希望能够从 DirectAccess 获取 IPv6 地址IPSec 隧道端点并 ping 它。 I'd like if you could shed light at this for me, please我想请你帮我解释一下

This is what I've got so far:这是我到目前为止所得到的:

##----------------------------------------------------------
## 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

This is the result of executing this command这是执行此命令的结果

$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

Any idea on how can I extract the value from IPSecTunnelEndpoint and execute ping afterwards?关于如何从IPSecTunnelEndpoint中提取值并在之后执行ping的任何想法? Thanking you in advance, Cheers, Gonzalo提前谢谢你,干杯,贡萨洛

I think that I've got it working now:我认为我现在已经开始工作了:

(Get-DAClientExperienceConfiguration).IPsecTunnelEndpoints | ForEach-Object{

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

The results are:结果是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM