mirror of
https://github.com/Grace-Solutions/PSMinIO.git
synced 2026-07-26 14:58:13 +00:00
d887fd7f46
- Updated README.md with modern feature descriptions and comprehensive overview - Enhanced docs/USAGE.md with advanced object listing, directory management, and chunked operations - Created examples/ directory with 6 comprehensive example scripts: * 01-Basic-Operations.ps1 - Fundamental operations for beginners * 02-Advanced-Object-Listing.ps1 - Filtering, sorting, and pagination * 03-Directory-Management.ps1 - Nested directory structures and organization * 04-Chunked-Operations.ps1 - Large file handling with performance optimization * 05-Bulk-Operations.ps1 - Batch processing and automation workflows * 06-Enterprise-Automation.ps1 - Enterprise monitoring, reporting, and compliance - Added comprehensive examples/README.md with usage patterns and best practices - Fixed directory creation warnings (now clean verbose logging) - Implemented missing Get-MinIOObject cmdlet with full filtering/sorting capabilities - Added timing and performance metrics to all operations - Enhanced chunked operations with multi-layer progress tracking - Improved error handling and resource cleanup - Removed temporary test files and cleaned up repository structure - All examples use proper PowerShell output (no Write-Host usage) - Professional logging with timestamps and structured output
72 lines
2.7 KiB
PowerShell
72 lines
2.7 KiB
PowerShell
# PSMinIO Basic Operations Example
|
|
# This script demonstrates fundamental MinIO operations using PSMinIO
|
|
|
|
# Import the module
|
|
Import-Module ..\Module\PSMinIO\PSMinIO.psd1
|
|
|
|
# Example connection details (replace with your actual values)
|
|
$endpoint = "https://minio.example.com"
|
|
$accessKey = "your-access-key"
|
|
$secretKey = "your-secret-key"
|
|
|
|
try {
|
|
# Connect to MinIO server
|
|
$connection = Connect-MinIO -Endpoint $endpoint -AccessKey $accessKey -SecretKey $secretKey
|
|
"Connected to MinIO server: $endpoint"
|
|
|
|
# List all buckets
|
|
"Listing all buckets..."
|
|
$buckets = Get-MinIOBucket
|
|
$buckets | Format-Table Name, CreationDate, @{Name="Objects";Expression={"N/A"}}
|
|
|
|
# Create a new bucket
|
|
$bucketName = "example-bucket-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
|
|
"Creating bucket: $bucketName"
|
|
New-MinIOBucket -BucketName $bucketName
|
|
|
|
# Verify bucket creation
|
|
if (Test-MinIOBucketExists -BucketName $bucketName) {
|
|
"✅ Bucket '$bucketName' created successfully"
|
|
}
|
|
|
|
# Create a sample file for upload
|
|
$sampleFile = "sample-document.txt"
|
|
"This is a sample document created on $(Get-Date)" | Out-File -FilePath $sampleFile -Encoding UTF8
|
|
|
|
# Upload the file
|
|
"Uploading file: $sampleFile"
|
|
$uploadResult = New-MinIOObject -BucketName $bucketName -Files $sampleFile
|
|
$uploadResult | Format-Table Name, @{Name="Duration";Expression={$_.Duration}}, @{Name="Speed";Expression={$_.AverageSpeedFormatted}}
|
|
|
|
# List objects in the bucket
|
|
"Listing objects in bucket '$bucketName':"
|
|
$objects = Get-MinIOObject -BucketName $bucketName
|
|
$objects | Format-Table Name, @{Name="Size";Expression={"$($_.Size) bytes"}}, LastModified
|
|
|
|
# Download the file
|
|
$downloadPath = "downloaded-$sampleFile"
|
|
"Downloading file to: $downloadPath"
|
|
$downloadResult = Get-MinIOObjectContent -BucketName $bucketName -ObjectName $sampleFile -FilePath $downloadPath
|
|
$downloadResult | Format-Table @{Name="LocalFile";Expression={$_.FilePath.Name}}, @{Name="Duration";Expression={$_.Duration}}, @{Name="Speed";Expression={$_.AverageSpeedFormatted}}
|
|
|
|
# Verify download
|
|
if (Test-Path $downloadPath) {
|
|
"✅ File downloaded successfully"
|
|
"Content: $(Get-Content $downloadPath)"
|
|
}
|
|
|
|
# Clean up
|
|
"Cleaning up..."
|
|
Remove-MinIOObject -BucketName $bucketName -ObjectName $sampleFile -Force
|
|
Remove-MinIOBucket -BucketName $bucketName -Force
|
|
Remove-Item $sampleFile, $downloadPath -Force -ErrorAction SilentlyContinue
|
|
|
|
"✅ Basic operations completed successfully"
|
|
|
|
} catch {
|
|
"❌ Error: $($_.Exception.Message)"
|
|
} finally {
|
|
# Clean up any remaining files
|
|
Remove-Item "sample-document.txt", "downloaded-sample-document.txt" -Force -ErrorAction SilentlyContinue
|
|
}
|