脚本删除打印作业的时间超过一小时"时间生活"

时间:2017-12-19 16:50:15

标签: powershell

我制作了一个脚本来管理服务器的所有打印作业,到目前为止我只设法擦除状态为"完成"的作业,我添加了一个if,以防万一printjob的时间超过1小时,脚本应删除该作业。

我不确定这是否正常工作,它似乎抹去了所有,所以我不知道我在哪里失败,而且脚本总是会进入其他条件。

$nombre = hostname

$old = (Get-Date).AddHours(-1)

Write-Host $nombre
if (Get-Printer -ComputerName $nombre  | Get-Printjob | where {$_.timesubmitted -lt $old -and $_.JobStatus -match "Complete" -and $_.JobStatus -notmatch "Spooling"} | Remove-PrintJob){ 
      Write-Host "Eliminados los trabajos completados mas antiguos de una hora" } 
else { 
      Write-Host "No se han encontrado trabajos que coincidan con los parametros"
}

2 个答案:

答案 0 :(得分:0)

我认为您需要格式化createElement条件。试试这个 -

<?php
// Add new custom font to Font Family selection in icon box module
function zeckart_add_new_icon_set_to_iconbox( ) {
    $param = WPBMap::getParam( 'vc_icon', 'type' );
    $param['value'][__( 'IcoMoon', 'total' )] = 'icomoon';
    vc_update_shortcode_param( 'vc_icon', $param );
}
add_filter( 'init', 'zeckart_add_new_icon_set_to_iconbox', 40 );
// Add font picker setting to icon box module when you select your font family from the dropdown
function zeckart_add_font_picker() {
    vc_add_param( 'vc_icon', array(
            'type' => 'iconpicker',
            'heading' => esc_html__( 'Icon', 'total' ),
            'param_name' => 'icon_icomoon',
            'settings' => array(
                'emptyIcon' => true,
                'type' => 'icomoon',
                'iconsPerPage' => 200,
            ),
            'dependency' => array(
                'element' => 'type',
                'value' => 'icomoon',
            ),
        )
    );
}
add_filter( 'vc_after_init', 'zeckart_add_font_picker', 40 );
// Add array of your fonts so they can be displayed in the font selector
function zeckart_icon_array() {
    return array(
        array('icomoon icon-food-light' => 'food'),
        array('icomoon icon-sport161' => 'sport'),
        array('icomoon icon-massage4' => 'massage'),
        array('icomoon icon-chairs16' => 'chair'),
        array('icomoon icon-relax43' => 'relax'),
        array('icomoon icon-excercise14' => 'excercise')
    );
}
add_filter( 'vc_iconpicker-type-icomoon', 'zeckart_icon_array' );
/**
 * Register Backend and Frontend CSS Styles
 */
add_action( 'vc_base_register_front_css', 'zeckart_vc_iconpicker_base_register_css' );
add_action( 'vc_base_register_admin_css', 'zeckart_vc_iconpicker_base_register_css' );
function zeckart_vc_iconpicker_base_register_css(){
    wp_register_style('icomoon', get_stylesheet_directory_uri() . '/assets/icomoon/style.css');
}
/**
 * Enqueue Backend and Frontend CSS Styles
 */
add_action( 'vc_backend_editor_enqueue_js_css', 'zeckart_vc_iconpicker_editor_jscss' );
add_action( 'vc_frontend_editor_enqueue_js_css', 'zeckart_vc_iconpicker_editor_jscss' );
function zeckart_vc_iconpicker_editor_jscss(){
    wp_enqueue_style( 'icomoon' );
}
/**
 * Enqueue CSS in Frontend when it's used
 */
add_action('vc_enqueue_font_icon_element', 'zeckart_enqueue_font_icomoon');
function zeckart_enqueue_font_icomoon($font){
    switch ( $font ) {
        case 'icomoon': wp_enqueue_style( 'icomoon' );
    }
}

答案 1 :(得分:0)

我认为它看起来应该更像这样:

$nombre = hostname

$old = (Get-Date).AddHours(-1)

Write-Host $nombre

$Printjobs = Get-Printer -ComputerName $nombre  | Get-Printjob | where {$_.timesubmitted -lt $old -and $_.JobStatus -match "Complete" -and $_.JobStatus -notmatch "Spooling"}

if($Printjobs){
  foreach($job in $PrintJob)
  {
    Remove-PrintJob $job
    Write-Host "Eliminados los trabajos completados mas antiguos de una hora"
  } 
  else{ 
      Write-Host "No se han encontrado trabajos que coincidan con los parametros"
  }
}

这样您首先检查是否有旧打印作业,然后停止每个旧作业。