Set-Annotation的2个输入

时间:2016-02-09 19:29:13

标签: powershell

我希望使用此命令在VMware虚拟机上设置注释。

events_statements_summary_by_digest

我需要脚本在同一个循环中读取2个输入文件。实体名称的一个输入和值的一个输入。

如果我们制作2个文本文件,

Set-Annotation -entity $vm -CustomAttribute "Owner" -Value "$owner"

我需要脚本来执行:

file 1 = 
vm1
vm2
vm3

file 2 = 
john
bob
ken

然后

Set-Annotation -entity vm1 -CustomAttribute "Owner" -Value "john"

我已经能够运行不同的循环,但没有正确的。

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

public class Base64EncodingDecodingRoundTripTest {

    public static void main(String[] args) throws IOException {
        String test1 = " ~!@#$%^& *()_+=`| }{[]\\;: \"?><,./ ";
        String test2 = test1 + test1;

        encodeDecode(test1);
        encodeDecode(test2);
    }

    static void encodeDecode(final String testInputString) throws IOException {
        sun.misc.BASE64Encoder unsupportedEncoder = new sun.misc.BASE64Encoder();
        sun.misc.BASE64Decoder unsupportedDecoder = new sun.misc.BASE64Decoder();

        Base64.Encoder mimeEncoder = java.util.Base64.getMimeEncoder();
        Base64.Decoder mimeDecoder = java.util.Base64.getMimeDecoder();

        String sunEncoded = unsupportedEncoder.encode(testInputString.getBytes());
        System.out.println("sun.misc encoded: " + sunEncoded);

        String mimeEncoded = mimeEncoder.encodeToString(testInputString.getBytes());
        System.out.println("Java 8 Base64 MIME encoded: " + mimeEncoded);

        byte[] mimeDecoded = mimeDecoder.decode(sunEncoded);
        String mimeDecodedString = new String(mimeDecoded, Charset.forName("UTF-8"));

        byte[] sunDecoded = unsupportedDecoder.decodeBuffer(mimeEncoded); // throws IOException
        String sunDecodedString = new String(sunDecoded, Charset.forName("UTF-8"));

        System.out.println(String.format("sun.misc decoded: %s | Java 8 Base64 decoded:  %s", sunDecodedString, mimeDecodedString));

        System.out.println("Decoded results are both equal: " + Objects.equals(sunDecodedString, mimeDecodedString));
        System.out.println("Mime decoded result is equal to test input string: " + Objects.equals(testInputString, mimeDecodedString));
        System.out.println("\n");
    }
}

您可以直接使用# Read VM names and owners into parallel arrays. $vmNames = Get-Content 'file 1' $owners = Get-Content 'file 2' # Loop over the VM names with a pipeline and assign the corresponding owner # by array index, maintained in variable $i. $vmNames | % { $i = 0 } ` { Set-Annotation -entity $_ -CustomAttribute "Owner" -Value $owners[$i++] } 作为管道的开头来简化此操作,而无需先收集数组变量Get-Content 'file 1'中的所有行。