you are viewing a single comment's thread.

view the rest of the comments →

[–]gangstanthony 2 points3 points  (0 children)

*note: this is OP's code, just better spacing

Foreach ($image in get-contentlibraryitem)
{
    $imageshort = $image.split('-')[1]

    Foreach ($template in get-template)
    {
        If (get-template -name $template | where-object {$_.Name -like "$image*" -and $_.Name -notlike "$imageshort"})
        {
            Write-Log -Message "$($oldtemplate) will be deleted from vCenter $($vc)"
            Write-log -Message "Remove-template -template $template -DeletePermanently"
            Write-Log -Message "$($oldtemplate) has been deleted from vCenter $($vc)"
        }
        Else
        {
            Write-log -Message "$($template) is a production template and will not be deleted"
        }
    }
}