Running the follow command to zip all txt file:
Compress-Archive -Path "$testfolder\*.txt\" -CompressionLevel Optimal -DestinationPath $textfolder\TESTZIP
I created a scheduled task that will run every 5 minutes for a period of 1 hour. Since this is a test, files get created every 5 minutes as well. But my zip folder does not get updated.
How could I update my zip folder based on my command on top?
After 1 hour, email alerts gets sent out. I have the email settings set up.
When in doubt, read the documentation.
-Update
Updates the specified archive by replacing older versions of files in the archive with newer versions of files that have the same names. You can also add this parameter to add files to an existing archive.
Add the parameter -Update to your commandline.
To overwrite an existing zip file use the -Force argument.
Related
On a Windows 10 machine, I have a backup folder where I have daily db.bak files coming from an automated SQL server backup job.
I am trying to figure out a way to create a duplicate zip file for every new .bak file that comes to the backup folder and move that zip file to a new location without deleting the original .bak file.
I am thinking this is possible with PowerShell, but have not figured out a way to do this as an automated process.
This is all you need to do:
Compress-Archive -Path "D:\Test.bak" -DestinationPath "F:\Backup\Test.zip"
Following this official Azure tutorial. When I run the following PowerShell command (mentioned in Create a project ZIP file section of the tutorial), it runs successfully but I don't know where the zip file created by the command is located.
Compress-Archive -Path * -DestinationPath myAppFiles.zip
I don't see the file in following location either: C:\Windows\System32\WindowsPowerShell\v1.0. What is the default output location for PS command?
The default output location in this case is your current working directory. Running that cmdlet as posted will copy everything in the current directory into $CurrentDirectory\myAppfiles.zip
Note that as you're not specifying the actual path, you'll want to Set-Location to the actual location of the items you're trying to compress. When you do that, the .zip file will end up in that directory.
I am trying to create a new folder on google drive and append the date and hour to the end of it to create a rolling 1 hour backup with old versions still accessible. I am not knowledgeable enough about PowerShell in order to automatically delete folders over 7 days old so I have to do it manually. The problem seems to be when PowerShell creates the new folders and copies the files, I no longer have access to delete them. I have checked permissions and added Everyone, Administrators, and the current user (the only user and admin) and it still will not allow me to delete the folders that PowerShell creates. I can delete files I manually put into Google drive. Here is my code:
$yest = (Get-Date).AddDays(-1).ToString(‘hhMMddyy’)
mkdir "C:\Users\admin\Google Drive\SpaceEngineersDedicated.$yest" -Force
Copy-Item C:\Users\admin\AppData\Roaming\SpaceEngineersDedicated -Destination "C:\Users\admin\Google Drive\SpaceEngineersDedicated.$yest" -Recurse -Force
If someone could help me with code that will just delete folders over 7 days, I would appreciate it but worst case scenario I'm fine with occasionally cleaning them up manually.
I am using the following expression to delete a folder from PowerShell. I need to delete a complete folder (including all the files and sub folders).
Remove-Item -Recurse -Force $DesFolder
But this gives me the exception "The directory is not empty"
I am not getting this exception every time when I run the program; it happens randomly. What would be the reason for this and how do I fix this? Because I was failing to reproduce this.
We cannot delete an non-empty directory using commands like rmdir or Remove-Item, this is to avoid accidental deletion of important system files by users during programming.
Therefore before trying to delete the directory, empty it. Clear the contents and then delete it. :)
Remove-Item -Recurse always deletes the directory and all its contents recursively. But it may still fail if directory is modified (i.e. new files are created) by some third-party activity in middle of remove process.
Also, if some of the files cannot be deleted (e.g. due to permission restrictions) Remove-Item will also fail.
So, I'd recommend you to check what exactly is laying inside the directory after exception.
Im writeing a backupscript useing powershell. I know that i could just use robocopy or rsync but i would like to do this in powershell. The problem i have has to do with the copy-item cmdlet. What my script does:
Read var's and fills them from a csv
Pings destination host
Checks if Outlook is open on source host and asks if it should close it
Then it should copy some folders onto the destination
My problem is that it always does a full copy of all files. I would like it to only copy the files that were changed or do not exist on the destination.
The second problem i have is that in Win7 there are hidden systemfolders in "Users/Documents" that link to "My Pictures" and "My Videos". I dont need to copy these but i didnt manage to exclude them useing the exclude agrument.
Just some quick and general suggestion...
I would like it to only copy the files that were changed
I would copy the files comparing the source and destination modified date
The second problem i have is that in Win7 there are hidden systemfolders in "Users/Documents" that link to "My Pictures" and "My Videos". I dont need to copy these but i didnt manage to exclude them useing the exclude agrument. :
Do not use copy-item directly, but use the output of get-childitem without force parameter. This will prevent to copy hidden or system files.