Warning message when running remove veeam cmdlets

PowerShell script exchange

Warning message when running remove veeam cmdlets

Veeam Logoby masber » Tue Jun 10, 2014 12:58 am

Both of my servers (remote and local) have Powershell 3.0 installed, however running the script below on it is giving me a warning message asking to update to version 2.0 when I run Add-PSSnapin. My ps script is running fine but the remote server is returning a JSON str and I can't use it if the warning message is in there.

Code: Select all
PS C:\Users\administrator> $PSVersionTable.PsVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
3      0      -1     -1 


this is my powershell script:

Code: Select all
$Uri = "http://" + $ExternalHost + ":5985"
$username = $Domain + "\********"

# Setup and start remote session
$pw = convertto-securestring -AsPlainText -Force -String "********"
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $pw
$session = new-pssession -ConnectionUri $Uri -credential $cred

$report = Invoke-Command -Session $session -ScriptBlock {
    Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
    $sessionVMSummary = @()
    get-vbrjob | foreach{   
        $session = $_.findlastsession();
        if (($session -ne $NULL) -and ($_.isScheduleEnabled -eq $TRUE)) {
            $Info = [Veeam.Backup.Core.CBackupTaskSession]::GetByJobSession($session.id) | select -Property ObjectName, Reason, QueuedTime, Status
            $sessionDocument = New-Object PSObject -Property @{
                "Name" = $session.Name
                "Result" = $session.Result
                "CreationTime" = $session.CreationTime
                "EndTime" = $session.EndTime
                "JobType" = $session.JobType
                "ObjectStatus" = $Info
            }
            $sessionVMSummary +=  $sessionDocument
        }
    }

    return $sessionVMSummary
}

and this is what $ExternalHost is returning:

Code: Select all
"WARNING: You should update your PowerShell to PowerShell 2.0 version. <== I NEED TO GET RID OF THIS WARNING MESSAGE
[
{
    "Name":  ********,
    "CreationTime":  "\/Date(1402290392717)\/",
    "ObjectStatus":  {
                         "ObjectName":  ********,
                         "Reason":  "",
                         "QueuedTime":  "\/Date(1402290405917)\/",
                         "Status":  {
                                        "value":  0,
                                        "Value":  "Success"
                                    }
                     },
    "Result":  {
                   "value":  0,
                   "Value":  "Success"
               },
    "EndTime":  "\/Date(1402291286497)\/",
    "JobType":  {
                    "value":  0,
                    "Value":  "Backup"
                },
    "PSComputerName":  ********,
    "RunspaceId":  "ad3ea82d-48dd-4135-9648-8bf3bba75e46",
    "PSShowComputerName":  true
}
]
"


QUESTION: How can I remove the Warning message?

thanks
masber
Novice
 
Posts: 5
Liked: never
Joined: Tue Jun 10, 2014 12:15 am
Full Name: masber

Re: Warning message when running remove veeam cmdlets

Veeam Logoby v.Eremin » Wed Jun 11, 2014 10:13 am

It seems that $host is just not reliable, as it reflects version of the host, not of the engine, which almost always is equal to 1. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Warning message when running remove veeam cmdlets

Veeam Logoby tsightler » Wed Jun 11, 2014 1:22 pm

My first thought, which is a little lame I guess, is to just pipe the output via "Select-String -NotMatch" to filter out the line.

That being said, there's probably a smarter way, I just haven't played enough with Invoke-Command to no how to handle it. I'm working on some stuff that uses Invoke-Command right now so if I guess a chance I'll dig into it.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Warning message when running remove veeam cmdlets

Veeam Logoby masber » Wed Jun 11, 2014 11:23 pm

Hi,

just to give you an update I tried to start powershell engine 2.0 remotely as shown http://technet.microsoft.com/en-us/library/hh847899.aspx.

so basically I register a new psremote configuration session on powershell 3.0 on the remote server:
Register-PSSessionConfiguration -Name PS3 -PSVersion 3.0

and then I connect to that session from my local server:
Invoke-Command -Session $session -ScriptBlock -ConfigurationName PS3

but I still have same issue. I am just wondering how can I remove this message as it is driving me crazy...

thanks a lot for your help
masber
Novice
 
Posts: 5
Liked: never
Joined: Tue Jun 10, 2014 12:15 am
Full Name: masber

Re: Warning message when running remove veeam cmdlets

Veeam Logoby tsightler » Thu Jun 12, 2014 3:34 am

The message with the Veeam powershell plugin returning this message has been around for quite some time. My point was that you can just filter it out after you receive the output using traditional line filtering which should be available to you in any language. Heck, you don't even have to really need to even match anything since the warning is always the first line, just cut the first line from the output. Also, you mention that the $ExternalHost variable has that output, but I don't see where that's even being set. Are you calling this from something else and just capturing the standard output?

However, I did discover a way to suppress the warning. The warning is issued on the first VBR command run after the snapin is loaded, so I believe you can just add the "-WarningAction SilentlyContinue", which you're already using on the Add-PSSnapin line, to the Get-VBRjob cmdlet like the following:

Code: Select all
$Uri = "http://" + $ExternalHost + ":5985"
$username = $Domain + "\********"

# Setup and start remote session
$pw = convertto-securestring -AsPlainText -Force -String "********"
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $pw
$session = new-pssession -ConnectionUri $Uri -credential $cred

$report = Invoke-Command -Session $session -ScriptBlock {
    Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
    $sessionVMSummary = @()
    get-vbrjob -WarningAction SilentlyContinue | foreach{   
        $session = $_.findlastsession();
        if (($session -ne $NULL) -and ($_.isScheduleEnabled -eq $TRUE)) {
            $Info = [Veeam.Backup.Core.CBackupTaskSession]::GetByJobSession($session.id) | select -Property ObjectName, Reason, QueuedTime, Status
            $sessionDocument = New-Object PSObject -Property @{
                "Name" = $session.Name
                "Result" = $session.Result
                "CreationTime" = $session.CreationTime
                "EndTime" = $session.EndTime
                "JobType" = $session.JobType
                "ObjectStatus" = $Info
            }
            $sessionVMSummary +=  $sessionDocument
        }
    }

    return $sessionVMSummary
}


After doing that I don't get the warning anymore. Hope that helps.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 2 guests