PowerShell:命名参数值

时间:2016-02-19 07:54:05

标签: powershell

我可以定义参数,以便我可以做这样的事情吗?:

SomeFunction -Date Now
SomeFunction -Date Tomorrow

如果我提供"现在"而不是日期值,我希望SomeFunktion使用当前日期。

当然,我可以使用switch语句或类似的东西来检查date参数的值并应用实际值。但还有另一种方式,一种更清洁的方式吗?

2 个答案:

答案 0 :(得分:1)

使用ValidateSet。

try {
            File infile = new File("/home/bobo/test/a.txt");
            File infile1 = new File("/home/bobo/test/b.txt");

            //The third file
            File outfile = new File("/home/bobo/test/c.txt");

            FileInputStream instream = new FileInputStream(infile);
            FileInputStream instream1 = new FileInputStream(infile1);

            FileOutputStream outstream = new FileOutputStream(outfile);

            byte[] buffer = new byte[1024];

            int length;

            while ((length = instream.read(buffer)) > 0) {
                outstream.write(buffer, 0, length);
            }

            while ((length = instream1.read(buffer)) > 0) {
                outstream.write(buffer, 0, length);
            }

            instream.close();
            instream1.close();
            outstream.close();

            System.out.println("File Copied successfully");
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

答案 1 :(得分:0)

我认为你应该在powershell中使用枚举 Checkout this link