PowerShell script exchange
Post Reply
icedcougar
Lurker
Posts: 1
Liked: never
Joined: Nov 14, 2017 9:37 pm
Full Name: Luke
Contact:

Sureback powershell testing

Post by icedcougar »

Hi all,

trying to use a script to test a backup to see if it works but im getting a false-positive (everything passes).
If i change one of the services to be something that doesn't exist (such as service name being "FakeNews") or to a process that should be off - it still gets a success.
I altered a script i saw on the veeam website. The scripts seems to work when ran manually on the server but provide a false positive once ran by veeam.

Any clue?

In sure backup i have Path as:
C:\veeam\test.bat

Arguments: (actual server name and services changed)
"Server01" "service1" "service2" "service3"

Batch script:

Code: Select all

REM 
@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
powershell.exe -noninteractive -noprofile -command "& {C:check.ps1 \"%1\" \"%2\" \"%3\" \"%4\" }"
EXIT /B %errorlevel%

Powershell:

Code: Select all

param(
[string] $ip, #passed as a DNS name, application group has a DC+DNS launch before this server comes up
[string] $service_one,
[string] $service_two,
[string] $service_three )

#Service name
$result_one = (get-Service -ComputerName $ip -Name $service_one -ErrorAction SilentlyContinue)
$result_two = (get-Service -ComputerName $ip -Name $service_two -ErrorAction SilentlyContinue)
$result_three = (get-Service -ComputerName $ip -Name $service_three -ErrorAction SilentlyContinue)

if($result_one.status -eq "Running")
{
    if($result_two.status -eq "Running")
    {
        if($result_three.status -eq "Running")
        {
            exit
        }
        else
        {
            write-host ("Error 3, Service '" + $service + "' not running or not found.")
            $host.SetShouldExit(1)
            exit
        }
    }
    else
    {
        write-host ("Error 2, Service '" + $service + "' not running or not found.")
        $host.SetShouldExit(1)
        exit
    }
}
else
{
    write-host ("Error 1, Service '" + $service + "' not running or not found.")
    $host.SetShouldExit(1)
    exit
}
MichaelCade
Veeam Software
Posts: 314
Liked: 74 times
Joined: Mar 23, 2015 11:55 am
Full Name: Michael Cade
Location: Cambridge, United Kingdom
Contact:

Re: Sureback powershell testing

Post by MichaelCade »

if you run the batch file what happens? does it trigger the Powershell script?

I am presuming when you are on the server, you run the PS script rather than batch file?
Regards,

Michael Cade
Global Technologist
Veeam Software
Email: Michael.Cade@Veeam.com
Twitter: @MichaelCade1
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 23 guests