问题描述
我实际上正在使用System.Management.Automation来构建用作防火墙的程序,我想知道PowerShell 2中是否有特定的cmdlet来处理服务器的ipsec更改? (即重复了netsh ipsec功能)?
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)?
还是我必须写一个? :P
Or would I have to write one? :P
我希望有一个更清洁的解决方案,而不是在PowerShell代码中调用[diagnostics.process]处理netsh查询,并认为cmdlet会更好.
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.
任何人都有提示或技巧吗?还是我应该从以下位置开始浏览编写Windows PowerShell cmdlet"文档:
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
感谢任何想法!
推荐答案
不幸的是,目前没有任何本机Powershell cmdlet可以提供与netsh类似的功能.
Unfortunately at this time, there aren't any native powershell cmdlets that provide similar functionality to netsh.
话虽这么说,您不必启动新进程即可在PowerShell函数中运行netsh命令.您可以像运行cmdlet一样,以PS函数或脚本内联方式运行通常在CMD中运行的任何exe.您可以将输出保存到变量中,然后使用select-string或-match运算符处理文本.
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.
仅作为示例
Function Get-NetShIPInterface {
netsh int ip show int
}
$interface = Get-NetshIPinterface
$interface | select-string "Local Area Connection"
最终,我们将获得联网cmdlet,但现在,netsh可以完成工作.
Eventually we will get networking cmdlets, but for now, netsh can get the job done.
这篇关于PowerShell 2中是否有一个cmdlet可以处理ipsec更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!