我想通過powershell創建文件夾及其文件的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但沒有得到下載。 MakeCab.exe Link
有人可以告訴我我做錯了什麼?
我檢查並在我的機器上找到makecab.exe。但是,當我運行上面的代碼時,它不顯示makecab.exe類。是否需要做任何事情才能正確上傳。 – Ironic
@ 404我不太確定,但comobject只與sdk一起安裝。微軟公佈了SDK,我不知道爲什麼。爲什麼你不在腳本中使用makecab.exe? –
我沒有找到任何相關或makecab.exe示例代碼 – Ironic