I am trying to get at some data in an Autodesk Revit file, which is just a ZIP under the skin. I can use 7zip to extract but I am hoping to automate things with all native PS or Windows. I tried Expand-Archive after I renamed the RVT file to ZIP, but Expand-Archive has an odd error. The code is
Expand-Archive -path:'C:\RevitVersionTest\22-PLUMB-CLR-RECTANGULAR.zip' -destinationPath:'C:\Revit Fam'
And the error is
New-Object : Exception calling ".ctor" with "3" argument(s): "End of Central Directory record could not be found."
The file is corrupt. Re-download (or obtain) the ZIP file.
Background: I landed here having experienced the same error downloading a ZIP from Google Drive through a private link:
Invoke-WebRequest -Uri $zipFile -OutFile "$destPath\myZip.zip"
...then using the command:
Expand-Archive c:\a.zip -DestinationPath c:\a`
The file downloaded but it wouldn't extract. I downloaded through the browser using the UI, and then compared the download file sizes. Sure enough, the downloaded ZIP was corrupted. When I updated the URL to a Google Docs link directly to the file (that's public with permission), the ZIP then downloaded and extracted correctly.
Hence, comments under the question alluding to the file being corrupt are correct.
Related
I am facing a strange error in powershell. I am currently trying to copy files from a serveur (say Z:) to a folder in my laptop.
I want to perform some check on each file that is why I do not want to use a robotcopy.
When i run the command
Get-ChildItem -Path Y:\ -Recurse | Select-Object FullNameLength
I get an error (in french) telling that the path is too long for some items (260 caracters). But I checked and the item path are not that long. For example
Y:\00.P1.2020.211-MEP 2020-11-01-RENOM\06 - Chantier
My Y:\ is a sharepoint online linked as a network drive.
Do you know where it could come from
Thanks in advance
Well it comes from the fact that a smart guy had put a file with a name of 308 characters in the folder. So I wasn't even able to see it in the explorer but it was still there (in the sharepoint) to raise the error.
I let it there if it can help someone else
I'm creating a Powershell script to download the latest version of a bunch of utilities. For some I know the URL and file name so this works:
$url = "https://download.sysinternals.com/files/SysinternalsSuite.zip"
$file = "SysinternalsSuite.zip"
$webclient.DownloadFile("$url","$storageDir\$file")
For some I just know the URL. For these I just know how to open it in the browser and file file is downloaded to the browsers download location.
$url = "https://toolslib.net/downloads/finish/1-adwcleaner/"
Start-Process "chrome.exe" "$url"
Is there any way to find the name of the file that was downloaded so it can be moved to $storageDir?
Alternately, is there a way to temporarily change a browsers default download location from inside the script and change it back at the end of the script? I'm not locked to any specific browser?
Good morning friends,
I've been writing a script in PowerShell to replace our current manual process to deploy our application to Azure Blob Storage in a ZIP folder during the Build Process in VS. I'm about done, but I've run into this issue:
When the ZIP that I upload to Azure is downloaded by anyone, the ZIP cannot be manipulated without having to extract the files first. This is something the current process is able to accomplish and I don't know how (The current process was written in C# and is done through a GUI). It needs to be editable via the ZIP because the current Updater is set to manipulate the ZIP without the extraction first.
So the initial question is: How do I set permissions on a ZIP archive that will follow it to Azure Blob Storage and then when it's downloaded on a client's machine that allow it's contents to be manipulated (The error itself at this time is that it cannot delete a file in a child folder) without extraction?
Currently, to ZIP my folder up, I use this process:
$src = "$TEMPFOL\$testBuildDrop"
$dst = "$TEMPFOL\LobbyGuard.zip"
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
[System.IO.Compression.ZipFile]::CreateFromDirectory($src, $dst)
and then push it to blob with:
set-azurestorageblobcontent -Container test -blob "LobbyGuard.zip" -file "$TEMPFOL\LobbyGuard.zip" -context $storageCreds -force
I've tried to set permissions on the folder prior to upload using
$getTEMPFOLACL = Get-ACL $TEMPFOL
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("Everyone", "FullControl", "Allow")
$getTEMPFOLACL.SetAccessRule($accessRule)
Which works on the current local file, but once downloaded, the permissions on the file are set as
Owner: BUILTIN\Adminstrators Access: NT AUTHORITY\SYSTEM Allow FullControl
Which is exactly the same permissions as the file that's downloaded from the current process. I'm not understanding what I'm missing here to make this work.
If necessary I can provide the DL link to our blob to show the current manual processes folder that can be manipulated IN the ZIP vs. My Scripts ZIP that cannot.
Try unblocking the file after downloading, ie
Unblock-File C:\path\yourDownloaded.zip
Ok, I am trying to download a file off of a web link that we use with powershell. I am downloading a zip file where the begining of the name is always the same, but the the middle part will change based off of the version number of the zip. I have been able to get the file to download when I use the fully qualified web address and have the file name hard coded into the script. I have tried every version of using the wild cards to get all the most common version of the zip, but it errors out saying that it can't find the file on there server. This is the code that I have already, and any help would be greatly appreciated since I feel like I am at a wall with it.
$url = 'http://blah/blah/blah/My File Name 11.1111.11.zip'
$localFileName = 'C:\temp\MYzip.zip'
Invoke-WebRequest $url -UseDefaultCredentials -OutFile $localFileName
If the site has directory browsing enabled (unlikely unless you have control of the site and can turn it on), you can do this:
$url = 'http://blah/blah/blah/'
$wr = iwr $url
$filename = $wr.Links.href | Where {$_ -match 'My File Name.*?\.zip'}
$wr = iwr "$url/$filename"
If the site doesn't have directory browsing enabled then surely it has a page with a link to the ZIP file on it. Download that page and use the same $wr.Links.href trick to get all the links and look for the one that matches "My File Name.*?.zip".
I want to use PowerShell with WebDAV (https) to download multiple files from a folder. The name from the download files is unknown. So my plan is to download all files from this folder and create a cleaning job at the server.
At the moment I´m searching for a good PowerShell with WebDAV example. Does anybody know a good example?
I don't try it but do you just test WebClient class?
PS > $source = "http://www.unsite.fr/untruc.zip"
PS > $destination = "c:\temp\untruc.zip"
PS >
PS >$wc = New-Object System.Net.WebClient
PS >$wc.DownloadFile($source, $destination)
----Edited------
Do you try to dig into ADODB.stream com object as you cansee in : "PowerShell : Upload file to WebDav Server"
Take a look at: http://amarchuk.blogspot.com/2011/10/heres-c-webdav-client-that-works-with.html
You can store it as cs file, then call add-type to add it to powershell and from there on client.GetListItems to get names and then download all files recursively.