过滤器收集没有?

时间:2016-01-05 16:24:14

标签: powershell

我有一个包含这样数据的集合:

server : ExchangeServer
drive : C:

server : ExchangeServer
drive : R:

server : DomainController
drive : C:

server : AnOtherServer
drive : C:

我想要从集合中排除带有Drive R的ExchangeServer和服务器。

我试过了:

import numpy as np
import pandas as pd
import scipy
#from scipy import ndimage
df= pd.DataFrame({'x':np.array([1,1,1,0,0,1,1,1,1,0,0,1,0,0,0,1,1,1,0,1,1,1,1])})
df_alt = df.copy()
def filter_df(df, colname, window_size):
    rolling_func = lambda z: z.sum() >= window_size
    df[colname] = pd.rolling_apply(df[colname],
                                    window_size,
                                    rolling_func,
                                    min_periods=window_size/2,
                                    center = True) 

def filter_alt(df, colname, window_size):
    rolling_func = lambda z: z.sum() >= window_size
    return scipy.ndimage.filters.generic_filter(df[colname].values,
                                                rolling_func,
                                                size = window_size,                                       
                                                origin = 0)

window_size = 4
filter_df(df, 'x', window_size)
print df
filter_alt(df_alt, 'x', window_size)

但该集合最终只是一个带有R:驱动器的Exchange服务器列表?

$PerfCollection | Where-Object -FilterScript { $_.drive –eq "R:" -and $_.server -like "*ExchangeServer*" } 是否有“非”选项?

1 个答案:

答案 0 :(得分:2)

您当前的情况选择元素作为Exchange服务器并拥有驱动器R:。要排除具有驱动器R:的Exchange服务器,您需要反转该条件:

$PerfCollection | Where-Object -FilterScript {
  -not ($_.drive –eq "R:" -and $_.server -like "*ExchangeServer*")
}