powershell获得更大的磁盘空间

时间:2015-08-04 17:56:46

标签: powershell drive

我可以使用此脚本获取所有逻辑驱动器和相应的自由空间:

public void addListenerOnButton()
    {

        btnClick = (Button) findViewById(R.id.checkipbutton);

        btnClick.setOnClickListener(new OnClickListener()
        {
            byte[] response = null;
            @Override
            public void onClick(View arg0)
            {

                text = (TextView) findViewById(R.id.textView2);


                Thread t = new Thread(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        for (int i = 0; i < ipaddresses.length; i++)

                        {

                                try
                                {
                                    response = Get(ipaddresses[i]);
                                }
                                catch (Exception e)
                                {
                                    String err = e.toString();
                                }

                                if (response!=null)
                                {



                                    try
                                    {
                                        final String a = new String(response,"UTF-8");




                                        text.post(new Runnable()
                                        {
                                            @Override
                                            public void run()
                                            {
                                                text.setText(a);
                                            }
                                        });

                                        Logger.getLogger("MainActivity(inside thread)").info(a);
                                    } catch (UnsupportedEncodingException e)
                                    {
                                        e.printStackTrace();
                                        Logger.getLogger("MainActivity(inside thread)").info("encoding exception");
                                    }

                                    Logger.getLogger("MainActivity(inside thread)").info("test1");
                                    break;

                                }

                                else
                                {

                                }

                            text.post(new Runnable()
                            {
                                @Override
                                public void run()
                                {
                                    text.setText("Connection Failed");
                                }
                            });



                        }

                    }
                });
                t.start();
            }
        });

    }

问题在于我无法弄清楚如何操纵我的package com.test.webservertest; /** * Created by bout0 on 8/4/2015. */ public class IpAddresses { private static String ipMain = "10.0.0."; private static int minIpRange = 0; private static int maxIpRange = 255; private static String[] ipAddresses = new String[maxIpRange]; public static void main(String[] args) { for (int i = minIpRange; i < maxIpRange; i++) { String ipRange = ipMain + i; //IP range in Array //ipAddresses[i] = ipRange; //if you need full IP range in Url, then unmark the following 2 lines and mark above line String UrlRange = "http://" + ipRange + ":8098/?cmd=nothing"; ipAddresses[i] = UrlRange; } //testing array results for (int i = minIpRange; i < maxIpRange; i++) System.out.println(ipAddresses[i]); } } 以返回具有更大自由空间的驱动器名称,例如$elements = get-WmiObject Win32_LogicalDisk $array=@() foreach ( $drive in $elements ) { $freespace = $drive.freespace / (1024*1024*1024) $freespace = [math]::round($freespace, 1) $name=$drive.Name $d=New-Object PSObject $d | Add-Member -Name Drive -MemberType NoteProperty -Value $name $d | Add-Member -Name Free_Space -MemberType NoteProperty -Value $freespace $array+=$d }

1 个答案:

答案 0 :(得分:0)

试试这个:

$LogicalDisks = get-WmiObject Win32_LogicalDisk

$MostSpace = 0
$MostName = "None"

foreach ( $drive in $LogicalDisks ) {

$FreeSpace = $drive.FreeSpace / (1024*1024*1024)

$FreeSpace = [math]::round($FreeSpace, 1)

if ($FreeSpace -gt $MostSpace) {
  $MostSpace = $FreeSpace
  $MostName = $Drive.Name
  }

}

Write-Host $MostName

它将驱动器号放入$ MostName,然后你可以用它做你想做的事。