通过powershell从文件夹创建cab文件

通过powershell从文件夹创建cab文件,powershell,Powershell,我想通过powershell创建文件夹及其文件的cab文件。 我尝试下面的脚本,但它给我的错误 Param( $filepath = "D:\Script", $path = "D:\Script\aCab.cab", [switch]$debug ) Function New-Cab($path,$files) { $makecab = "makecab.makecab" Write-Debug "Creating Cab path is: $path" $cab =

我想通过powershell创建文件夹及其文件的cab文件。 我尝试下面的脚本,但它给我的错误

Param(
  $filepath = "D:\Script", 
  $path = "D:\Script\aCab.cab",
  [switch]$debug
  )
Function New-Cab($path,$files)
{
 $makecab = "makecab.makecab"
 Write-Debug "Creating Cab path is: $path"
 $cab = New-Object -ComObject $makecab
 if(!$?) { $(Throw "unable to create $makecab object")}
 $cab.CreateCab($path,$false,$false,$false)
 ForEach ($file in $files)
 {
 $file = $file.fullname.tostring()
 $fileName = Split-Path -path $file -leaf
 Write-Debug "Adding from $file"
 Write-Debug "File name is $fileName"
 $cab.AddFile($file,$filename)
 }
 Write-Debug "Closing cab $path"
 $cab.CloseCab()
} #end New-Cab

# *** entry point to script ***
if($debug) {$DebugPreference = "continue"}
$files = Get-ChildItem -path $filePath | Where-Object { !$_.psiscontainer }
New-Cab -path $path -files $files
错误:

New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not 
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
unable to create makecab.makecab object

At D:\SCCM Script\Cabmaker.ps1:11 char:14
我试图从Micorosoft下载makecab.exe,但无法下载


有人能告诉我我做错了什么吗?

您可以检查此列表中是否存在comobject:

Get-ChildItem HKLM:\Software\Classes -ErrorAction SilentlyContinue | Where-Object {
    $_.PSChildName -match '^\w+\.\w+$' -and (Test-Path -Path "$($_.PSPath)\CLSID")
} | Select-Object -ExpandProperty PSChildName
你让我认为你犯的错误没有被记录


该命令似乎存在于windows 2000的
c:\windows\system32
文件夹中。从Windows Vista开始的操作系统中链接到文档

makecab.makecab com对象。

我检查了,在我的计算机上找到了makecab.exe。但是,当我运行上述代码时,它不会显示makecab.exe类。是否需要执行任何操作才能正确上载它。@404我不太确定,但comobject仅随sdk一起安装。微软结束了sdk的公开,我不知道为什么。为什么不在脚本中使用makecab.exe?我没有找到makecab.exe的任何相关代码或示例代码