Powershell foreach名称执行invoke-command

时间:2019-03-07 11:00:03

标签: powershell foreach invoke-command

我下面的代码比名字更糟:

foreach ($comp in $maschines.name) { $comp }

但是以下方法不起作用,为什么?

foreach ($comp in $maschines.name) { invoke-command -computer comp1 -ScriptBlock { get-vm –VMName $comp | Select-Object VMId | Get-VHD | ft path } }

1 个答案:

答案 0 :(得分:0)

尝试以下操作:

upstream nodejs {
    server 127.0.0.1:8081;
    keepalive 256;
}

server {
    listen 8080;

    if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; }

    location / {
        proxy_pass  http://nodejs;
        proxy_set_header   Connection "";
        proxy_http_version 1.1;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP   $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    gzip on;
    gzip_comp_level 4;
    gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

}

http://www.example.com/page-one -> http://example.com/page-one/ http://example.com/page-two -> https://www.example.com/page-two/ https://www.example.com/page-three?page=2 -> https://www.example.com/page-three/?page=2 添加到脚本块中,以利用要在另一台计算机上使用的本地变量。