解析输出以验证列值

时间:2019-02-12 07:04:37

标签: powershell powershell-v4.0

我从std::string命令获得以下输出:

CONTAINER ID   IMAGE COMMAND CREATED STATUS  PORTS     NAMES
e1d52c0adee7        share-platform:6000/share-platform:1.0.96-windowsservercore      "powershell -Command…"   3 months ago        Up 2 weeks              share-platform
ad6a8e2c7fd0        prism:6000/prism-platform:1.0.1078-windowsservercore   "powershell -Command…"   3 months ago        Up 2 months                    9080/tcp                                  prism-platform
efd847643e86        mongo:6000/mongo:3.2-windowsservercore             "mongod --smallfiles…"   3 months ago        **Restarting (100) 2 weeks ago**   27017/tcp                                  mongo
3d8ab9b5c36e        share:6000/share-app:1.0.153-windowsservercore     "powershell -Command…"   3 months ago        Up 2 months             share-app
dc4b1053d9da        prism-app:6000/prism-app:1.0.4183.1-windowsservercore      "powershell -Command¦"   3 months ago        Up 2 months                                                               prism-app
2a38e006f85f        core:6000/welcome:1.0.241.1-windowsservercore         "powershell -Command¦"   3 months ago        Up 2 months

我试图遍历输出中的状态栏,如果存在除docker ps以外的其他状态,我想回显它。

我尝试将其导出到csv,然后使用UP。可以预期的是,由于MongoDB的状态不是Import-Csv,因此我希望它像“ Mongo尚未启动”(从Up列获取名称)一样将其回显到屏幕。

脚本的实际结果为空白。

NAMES

1 个答案:

答案 0 :(得分:0)

您不需要导出和导入要使用的数据。

一个简短的伪代码示例:

docker ps | ForEach-Object {
    if ($_.STATUS -ne "UP") {
        Echo "The process $($_.NAMES) is not up"
    }
}