ArthurR
ArthurR

Reputation: 111

Compress a folder with powershell

I have a folder that I want automatically compress with a script to make space. For that, I use the following script for a folder called 'test':

$a = Get-Item "D:\Aither\Pca\Test"
$a.Attributes += "Compressed" 

After some tests, the attribute "hidden" works with the previous code but not with the attribute "Compressed"

enter image description here

Compress contents to save disk space should be checked. Even when turning off my computer, it's not working.

Did I make a mistake in my code or it's just a rights issue ?

Upvotes: 1

Views: 1334

Answers (2)

wallachia
wallachia

Reputation: 24

Additionally to your answer -- there is a native command

Enable-NtfsCompression [-Path] <String[]> [-Recurse] [-WhatIf] [-Confirm] [<CommonParameters>]

Upvotes: 0

ArthurR
ArthurR

Reputation: 111

I found a answer with the following code :

Invoke-WmiMethod -Path "Win32_Directory.Name='D:\Aither\Pca\Test'" -Name compress

Upvotes: 1

Related Questions