找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
楼主: 5i365

[问题求助] PowerShell提取命令帮助文件中的示例

[复制链接]
发表于 2022-4-26 23:01:36 | 显示全部楼层
回复 15# 5i365


    不会
发表于 2022-4-26 23:49:47 | 显示全部楼层
  1. cls
  2. $r = Invoke-WebRequest -Uri ((gcm sc).HelpUri)
  3. $r.ParsedHtml.getElementsByTagName('h3') | Where-Object { $_.id -match '^example' } | foreach {
  4.     '------{0}------' -f $_.innerText
  5.     $_.nextSibling.nextSibling.innerText
  6. }
复制代码

评分

参与人数 1技术 +1 收起 理由
idwma + 1 学到了

查看全部评分

 楼主| 发表于 2022-4-27 06:53:44 | 显示全部楼层
本帖最后由 5i365 于 2022-4-27 07:02 编辑

回复 17# went


   感谢大侠帮忙, 测试了一下, 最后取的示例错了
链接
http://go.microsoft.com/fwlink/?LinkID=113392

取到的结果:
------Example 4: Use Filters with Set-Content------
The following command set the content all *.txt files in the C:\Temp directory to the Value empty.


应该取:
Set-Content -Path C:\Temp\* -Filter *.txt -Value "Empty"

规律是:如果一行开头包含 powershell  结尾包含复制,它的下一行就是要取的内容

发表于 2022-4-27 12:34:25 | 显示全部楼层
  1. cls
  2. $r = Invoke-WebRequest -Uri ((gcm sc).HelpUri)
  3. $r.ParsedHtml.getElementsByTagName('h3') | Where-Object { $_.id -match '^example' } | foreach {
  4.     '------{0}------' -f $_.innerText
  5.     $ele = $_
  6.     while($ele.tagName -ne 'PRE'){ $ele = $ele.nextSibling }
  7.     $ele.innerText
  8. }
复制代码

评分

参与人数 1技术 +1 收起 理由
5i365 + 1 乐于分享, 技术牛X

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 05:02 , Processed in 0.017495 second(s), 7 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表