zoukankan      html  css  js  c++  java
  • 扩展 xp_fixeddrives

     

    xp_fixeddrvies提供磁盘分区的信息太少,如下的脚本提供磁盘分区的使用情况,运行需要管理员权限!
    if not exists( select * from sys.configurations(nolock) cc 
     where cc.name='xp_cmdshell' 
     and cc.value_in_use=1)
     begin
        exec sp_configure 'show advanced options',1
        reconfigure
    
        exec sp_configure 'xp_cmdshell',1
        reconfigure
     end
    
    if OBJECT_ID('tempdb..#fixeddrives_temp') is not null
    drop table #fixeddrives_temp;
    Go
    
    
    if OBJECT_ID('tempdb..#totaldrives_temp') is not null
    drop table #totaldrives_temp;
    Go
    
    create table tempdb..#fixeddrives_temp(drive char(1),freesize bigint)
    create table tempdb..#totaldrives_temp(size varchar(100));
    insert into  #totaldrives_temp exec xp_cmdshell 'wmic LogicalDisk get deviceid,size'
    insert into  #fixeddrives_temp exec xp_fixeddrives
    
    select    f.drive,
            t.[totalsizeMB] as [总空间MB],
            (t.[totalsizeMB]-cast(f.freesize as decimal(20,0))) as [已用空间MB],
            f.freesize as [未用空间MB],
    cast(((t.[totalsizeMB]-cast(f.freesize as bigint))*100.0/t.[totalsizeMB]) as decimal(5,1)) as [已使用%],
    cast((cast(f.freesize as bigint)*100.0/t.[totalsizeMB]) as decimal(5,1)) as [未使用%]
    from 
    (
    
    select rtrim(left(LTRIM(size),1)) as drive,
    cast(replace(replace(replace(ltrim(RIGHT(rtrim(size),LEN(size)-2)),char(9),''),char(10),''),CHAR(13),'') as bigint)/1024/1024 as [totalsizeMB]
    
    from  #totaldrives_temp 
    where size not like '%DeviceID  Size%' and LEN(size) not IN (0,1)
    ) AS t
    inner join #fixeddrives_temp f
    on t.drive=f.drive


     

  • 相关阅读:
    Robot Framework (二)---测试数据
    Robot Framework(一)---Robot Framework 简介
    软件测试---产品需求文档测试
    浅谈Python 中的闭包
    浅析 Python中__init__.py
    PEP8---Python命名规则
    软件产品测试经验(一)---产品专项测试
    Microsoft Office Excel 不能访问文件。。。 可能的原因有。。。
    记HttpListener调用exe程序界面无法打开
    简单搞懂逆变与协变
  • 原文地址:https://www.cnblogs.com/fly_zj/p/2485876.html
Copyright © 2011-2022 走看看