main
[Powershell] 네트워크 드라이브 용량 체크 본문
추가되어 있는 네트워크 드라이브 확인용
'DeviceId = "H:"' 에 사용중인 네트워크 드라이브의 드라이브명을 넣어준다.
$text = ""
$Disk = Get-WmiObject Win32_LogicalDisk -Filter 'DeviceId = "H:"'
if($Disk.Size -eq $Null){
$text = $text +
"`n`경로 " + $Disk.ProviderName +
"`n`드라이브 크기: " + "{0:0}" -f ($Disk.Size/1024/1024/1024)+" GB" +
"`n`드라이브 남은용량: " + "{0:0}" -f ($Disk.Freespace/1024/1024/1024)+ " GB" +
"`n`드라이브 남은퍼센트: 100%" + "`n` "
}
else
{
$PercentFree = [int](([int64]$Disk.Freespace/$Disk.Size)*100)
$text = $text +
"`n`경로 " + $Disk.ProviderName +
"`n`드라이브 크기: " + "{0:0}" -f ($Disk.Size/1024/1024/1024)+" GB" +
"`n`드라이브 남은용량: " + "{0:0}" -f ($Disk.Freespace/1024/1024/1024)+ " GB" +
"`n`드라이브 남은퍼센트: " +$PercentFree + "%" + "`n` "
}
$text
추가되어 있지 않은 다수 경로 확인용
$NAS_PATH 에 용량 체크할 경로들을 추가하여 사용한다. 콤마(,)로 구분
DeviceId 에 사용하지 않는 드라이브명을 설정하고 네트워크 드라이브를 추가/삭제 하며 확인하는 방식
$NAS_PATH = "\경로\경로, \경로2\경로2"
$text = ""
Foreach ($item in $NAS_PATH)
{
net use H: $item
Start-Sleep -Seconds 0.5
$Disk = Get-WmiObject Win32_LogicalDisk -Filter 'DeviceId = "H:"'
if($Disk.Size -eq $Null){
$text = $text +
"`n`경로 " + $Disk.ProviderName +
"`n`드라이브 크기: " + "{0:0}" -f ($Disk.Size/1024/1024/1024)+" GB" +
"`n`드라이브 남은용량: " + "{0:0}" -f ($Disk.Freespace/1024/1024/1024)+ " GB" +
"`n`드라이브 남은퍼센트: 100%" + "`n` "
}
else
{
$PercentFree = [int](([int64]$Disk.Freespace/$Disk.Size)*100)
$text = $text +
"`n`경로 " + $Disk.ProviderName +
"`n`드라이브 크기: " + "{0:0}" -f ($Disk.Size/1024/1024/1024)+" GB" +
"`n`드라이브 남은용량: " + "{0:0}" -f ($Disk.Freespace/1024/1024/1024)+ " GB" +
"`n`드라이브 남은퍼센트: " +$PercentFree + "%" + "`n` "
}
net use H: /delete
}
$text
728x90
'ETC' 카테고리의 다른 글
[Git] SSL certificate problem: self signed certificate (0) | 2022.09.23 |
---|---|
[Ubuntu] python 버전별 설치 (0) | 2022.09.12 |
[Docker] 도커 설치 - Ubuntu 18.04 (0) | 2022.09.08 |
[Linux/Ubuntu] 서버 접속 IP list 추가하기(중복 체크) - /etc/hosts.allow (0) | 2022.09.07 |
[Linux] quota 용량 변경 command (username) (0) | 2022.09.03 |
Comments