Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # http://stackoverflow.com/questions/36776415/powershell-script-to-copy-files-if-drive-free-space-is-greater-than-threshold-va
- # get drives starting with C that have at least 5GB of free space, then select the first one on the list
- $drive = ([System.IO.DriveInfo]::GetDrives() | ? {$_.totalfreespace / 1gb -gt 5}).name | ? {[int][char]$_[0] -ge 67} | select -f 1
- if (!$drive) {
- Write-Warning 'No drives have more than 5GB of free space. Exiting script.'
- return
- }
- Write-Host "Selected drive: $drive"
- # get list of servers
- $serversfile = 'c:\servers.txt'
- $servers = Get-Content $serversfile
- foreach ($server in $servers) {
- # specify folder to copy on current server
- $source = "\\$server\share\Softwares"
- # specify destination folder
- $destination = Join-Path $drive $server
- # if destination does not exist, create the folder
- if (!(Test-Path $destination)) {
- md $destination | Out-Null
- }
- # copy shared Softwares folder to the root of the selected drive
- Write-Host "Copying '$source' folder to '$destination'"
- copy $source $destination -Recurse -WhatIf
- }
Add Comment
Please, Sign In to add comment