用CSV自动删除边界-Remove-CMBoundary

时间:2018-07-16 09:08:37

标签: powershell sccm boundary

CSV.csv

Name,Type,Value,Name,Subnet
Manchester, IPSubnet,192.168.1.0,Manchester,192.168.1.0

我正在尝试自动从网站中删除边界(作为此过程的一部分,我将它们作为IPA地址范围边界添加到新的主数据库中。

Remove-CMBoundary cmdlet似乎需要一个ID,我的CSV中没有该ID,因此在删除过程中,我试图将其从SCCM中提取。

注意:现有组中有多个边界需要保留在原处,并且每个组仅需要删除3个边界,所以有些棘手。

$csv = Import-Csv "C:\NETS\csv.csv"
foreach ($line in $csv) {
    Write-Host -ForegroundColor Green "Removing boundary for $($line.Subnet)"
    Remove-CMBoundary -Name $line.$Name -Type IPSubnet -Value $line.Subnet
}

以上操作无效,因为您需要边界ID-不仅是子网信息。随后的挖掘使我来到这里:

$csv = Import-Csv "C:\csv.csv"
foreach ($line in $csv) {
    Get-CMBoundary -BoundaryName $csv.Name |
        select Value,BoundaryID |
        Export-Csv C:\Boundary.csv
    $boundaryids = Import-Csv C:\Boundary.csv
    foreach ($id in $boundaryids) {
        Where-Object -eq $line.'Subnet'
    } Remove-CMBoundary -Id $id.'boundaryID'
}

我敢打赌,这实际上是我要尝试做的事情。谁能看到我要去的地方?

3 个答案:

答案 0 :(得分:2)

我也不知道SCCM,但是

  • 根据Remove-CMBoundary,它接受​​管道输入
  • 并具有一个add_action( 'woocommerce_email', 'remove_email_order_downloads', 10, 1 ); function remove_email_order_downloads( $emails ){ remove_action( 'woocommerce_email_order_details', array( $emails, 'order_downloads' ), 10 ); add_action( 'woocommerce_email_order_details', 'custom_order_downloads', 9, 4 ); } function custom_order_downloads( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) { $show_downloads = $order->has_downloadable_item() && $order->is_download_permitted() && ! $sent_to_admin && $order->has_status('completed'); if ( ! $show_downloads ) { return; } $downloads = $order->get_downloadable_items(); $columns = apply_filters( 'woocommerce_email_downloads_columns', array( 'download-product' => __( 'Product', 'woocommerce' ), 'download-expires' => __( 'Expires', 'woocommerce' ), 'download-file' => __( 'Download', 'woocommerce' ), ) ); if ( $plain_text ) { wc_get_template( 'emails/plain/email-downloads.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email, 'downloads' => $downloads, 'columns' => $columns ) ); } else { wc_get_template( 'emails/email-downloads.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email, 'downloads' => $downloads, 'columns' => $columns ) ); } } 参数。

所以这应该做:

-WhatIf

如果输出看起来不错,请删除$csv = Import-Csv "C:\csv.csv" ForEach ($line in $csv) { Get-CMBoundary -BoundaryName $line.Name | Where-Object Value -eq $line.Subnet | Remove-CMBoundary -WhatIf } (或使用-WhatIf

以这种方式进行编辑,您的评论尝试可能会起作用

-Confirm

答案 1 :(得分:1)

我没有使用SCCM的经验,但是从您的代码示例来看,您可能正在尝试执行以下操作:

foreach ($line in $csv) {
    Get-CMBoundary -BoundaryName $line.Name | Where-Object {
        $_.Value -eq $line.Subnet
    } | ForEach-Object {
        Remove-CMBoundary -Id $_.BoundaryID
    }
}

答案 2 :(得分:0)

除了原始查询之外,要一次枚举一个站点,还可以这样做:

$Site = "ABC"
$csv = Import-Csv "C:\csv.csv"
foreach ($line in $csv) { 

                        Get-CMBoundary -BoundaryName $line.Name | Where-Object {
                        $_.Value -eq $line.Subnet -and $_.ShortCode -eq $line.$Site} | 
        ForEach-Object {
        Remove-CMBoundary -Id $_.BoundaryID 
} 
    }