PowerShell 2 中是否有 cmdlet 可以处理 ipsec 更改?

发布于 2024-08-10 19:36:16 字数 508 浏览 1 评论 0原文

我正在使用 System.Management.Automation 构建一个本质上充当防火墙的程序,我想知道 PowerShell 2 中是否有特定的 cmdlet 来处理服务器的 ipsec 更改? (即,重复 netsh ipsec 功能)?

或者我必须写一篇? :P

我希望有一个比在 PowerShell 代码中调用 [diagnostics.process] 来处理 netsh 查询更干净的解决方案,并且认为 cmdlet 会更好。

有人有任何提示或技巧吗?或者我应该开始深入研究“编写 Windows PowerShell cmdlet”文档:

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

感谢您的任何想法!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁我热情 2024-08-17 19:36:16

不幸的是,目前还没有任何本机 powershell cmdlet 可以提供与 netsh 类似的功能。

话虽这么说,您不必启动新进程即可在 PowerShell 函数中运行 netsh 命令。您可以在 PS 函数或内联脚本中运行通常在 CMD 中运行的任何 exe,就像运行 cmdlet 一样。您可以将输出保存到变量并使用 select-string 或 -match 运算符处理文本。

举个例子,

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

最终我们将获得网络 cmdlet,但现在,netsh 可以完成这项工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文