Is there a cmdlet in PowerShell 2 to handle ipsec changes?

不打扰是莪最后的温柔 提交于 2019-12-02 10:39:45

问题


I am using System.Management.Automation to build a program that serves as a firewall, essentially, and I was wondering if there is a specific cmdlet in PowerShell 2 to handle ipsec changes for a server? (i.e., that duplicates netsh ipsec functionality)?

Or would I have to write one? :P

I am hoping for a cleaner solution than calling a [diagnostics.process] within the PowerShell code to handle the netsh queries, and figured a cmdlet would be better.

Anyone have any tips or tricks? Or should I just start digging through the 'Writing a Windows PowerShell cmdlet' documentation at:

http://msdn.microsoft.com/en-us/library/dd878294%28VS.85%29.aspx

Thanks for any ideas!


回答1:


Unfortunately at this time, there aren't any native powershell cmdlets that provide similar functionality to netsh.

That being said, You wouldn't have to fire up a new process to run netsh commands in a PowerShell function. You can run any exe you normally run in CMD in a PS function or script inline just as you would a cmdlet. You can save the output to a variable and process the text with select-string or the -match operator.

Just as an example

Function Get-NetShIPInterface {
netsh int ip show int
}
$interface = Get-NetshIPinterface
$interface | select-string "Local Area Connection"

Eventually we will get networking cmdlets, but for now, netsh can get the job done.



来源:https://stackoverflow.com/questions/1703205/is-there-a-cmdlet-in-powershell-2-to-handle-ipsec-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!