【问题标题】:Powershell - Can you Remove-Item based on CompanyPowershell - 你能根据公司删除项目吗
【发布时间】:2018-10-20 12:10:40
【问题描述】:

您能否使用命令 Remove-Item 根据“公司”字段进行删除 - 它是 windows 拥有的字段之一,我想基本上删除具有以下值之一的所有内容

$company = "Sage (UK) Limited","Sage (UK) Ltd","Sage","The Sage Group plc","SAGE Software Ltd"

这可能吗?

【问题讨论】:

  • 不清楚您要删除的什么。但总的来说,对于 PowerShell,简短的回答是:是的,这是可能的。
  • 在文件资源管理器中,当您右键单击列并选择更多时,您可以选择“公司”,它会显示更多详细信息 - 这是否有意义。 link
  • Remove-Item 将删除您输入或表达为参数的内容。删除来自 Sage 的 .exe.dll 不会完全删除已安装的软件,并且会留下很多包含其他信息的文件夹。我建议你先看看安装了什么get-wmiobject -Class Win32_Product|? Vendor -match 'Sage'|select Name,Version,Vendor|ft -auto

标签: powershell


【解决方案1】:
$path = 'C:\'
$company = 'Sage (UK) Limited','Sage (UK) Ltd','Sage','The Sage Group plc','SAGE Software Ltd'

Remove-Item (Get-ChildItem $path | Where-Object {$company.Contains($_.VersionInfo.CompanyName)}).FullName

这个灵魂的工作。 将$path 替换为您要检查的文件夹路径

【讨论】:

  • 甚至没有 -WhatIf-Confirm 参数来首先检查一切是否正常?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-11
  • 2019-06-23
  • 2016-03-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多