Good Morning Level 1ers!
I am pretty new in PowerShell scripting so if what I am asking is not possible by all means tell me that.
I would like to create a PowerShell script that would accept the send-to command.
The purpose of the script is to change the files to read-only and then compress those files. I’d like to be able to select multiple files in file explorer then right-click, send to (Script)
Is this something that is possible? Thanks!
Update 1
Read Only function is working, now I have to implement the compression
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
Multiselect = $true # Multiple files can be chosen
Filter = 'Images (*.jpg, *.png)|*.jpg;*.png' # Specified file types
}
[void]$FileBrowser.ShowDialog()
$path = $FileBrowser.FileNames;
If($FileBrowser.FileNames -like "*\*") {
# Do something before work on individual files commences
$FileBrowser.FileNames #Lists selected files (optional)
foreach($file in Get-ChildItem $path){
Get-ChildItem ($file) |
ForEach-Object {
Set-ItemProperty -Path $path -Name IsReadOnly -Value $true
}
}
# Do something when work on individual files is complete
}
else {
Write-Host "Cancelled by user"
}
Update 2 It’s finished and works like intended. Here is the code if anyone is interested!
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
Multiselect = $true # Multiple files can be chosen
}
[void]$FileBrowser.ShowDialog()
$path = $FileBrowser.FileNames;
If($FileBrowser.FileNames -like "*\*") {
# Do something before work on individual files commences
$FileBrowser.FileNames #Lists selected files (optional)
foreach($file in Get-ChildItem $path){
Get-ChildItem ($file) |
ForEach-Object {
Set-ItemProperty -Path $path -Name IsReadOnly -Value $true
compact /C $_.FullName
}
}
# Do something when work on individual files is complete
}
else {
Write-Host "Cancelled by user"
}