SMVI: Scripting issues with Powershell

by on ‎2012-08-20 07:34 AM

Hi folks,

i'm confused with the pre_backup interface in interaction with my powershell scripts. I try to give a short overview of the problem:

  • Calling a powershell script via batch file in PRE_BACKUP phase which remotely executes a process on the host i want to do a snapshot of.
    This script only contains of a few lines and the last line monitors the running process to keep the shell waiting for it to finish:
    Here's the code:

          $server = 'IP_OF_SERVER'

          $pass = ConvertTo-SecureString -string "PASSWORD" -AsPlainText –Force

          $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\USER", $pass

          $process = get-wmiobject -query "SELECT * FROM Meta_Class WHERE __Class = 'Win32_Process'" -namespace "root\cimv2" -computername $server -credential $cred

          $result = $process.Create("C:\scripts\cdb_dev_backup.exe")

          do {Start-Sleep -s 1} While ((Get-Process -ErrorAction SilentlyContinue -Name cdb_dev_backup -computername $server | Measure-Object).count -gt 0)

  • This is my batch file which calls my script:

          if %BACKUP_PHASE% == PRE_BACKUP goto PRE

          if %BACKUP_PHASE% == POST_BACKUP goto POST

          :PRE

          C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -File "c:\Program Files\NetApp\Virtual Storage Console\smvi\server\scripts\cdbdev_bstools.ps1"

          goto END

          :POST

          goto END

          :END

  • As long as i call it from the command line, everythings runs fine and the batch is kept open until the remote process finshes.
  • If i run it under the user account smvi was configured (default vcenter credentials) it runs, triggers the powershell script and ignores the last line of the code and continues the snapshot without waiting for the powershell script.
  • If i do the same using a scheduled backup (VSC 4.0) an additional error comes up:

2012-08-20 16:57:00,693 PROGRESS - Starting backup request

2012-08-20 16:57:00,756 INFO - Generating backupName for the scheduleJob 3481dbbd-dedc-42c0-9fc0-2dceb2fedd2d is backup_smvi_cdb_dev_0000_20120820165700

2012-08-20 16:57:02,303 PROGRESS - Backing up datastore(s) ([prod_3_clone_09Aug2012 (netfs://10.x.x.x//vol/prod_3_clone_09Aug2012)])

2012-08-20 16:57:02,303 PROGRESS - Backing up the following virtual machine(s) ([DEFFBSLOR12-DEV, DEFFBSWAP12-DEV])

2012-08-20 16:57:02,459 PROGRESS - Script cdbdev_backup.bat is starting in phase PRE_BACKUP

2012-08-20 16:57:03,912 INFO - Script cdbdev_backup.bat completed with output: C:\Program Files\NetApp\Virtual Storage Console\smvi\server\log\scripts>if PRE_BACKUP == PRE_BACKUP goto PRE C:\Program Files\NetApp\Virtual Storage Console\smvi\server\log\scripts>C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -File "c:\Program Files\NetApp\Virtual Storage Console\smvi\server\scripts\cdbdev_bstools.ps1" Get-Process : Couldn't connect to remote machine. At C:\Program Files\NetApp\Virtual Storage Console\smvi\server\scripts\cdbdev_b stools.ps1:6 char:42 + do {Start-Sleep -s 1} While ((Get-Process <<<< -ErrorAction SilentlyContinue -Name cdb_dev_backup -computername $server | Measure-Object).count -gt 0) + CategoryInfo : NotSpecified: (Smiley Happy [Get-Process], InvalidOperatio nException + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.Power Shell.Commands.GetProcessCommand C:\Program Files\NetApp\Virtual Storage Console\smvi\server\log\scripts>goto END

2012-08-20 16:57:03,912 PROGRESS - Script cdbdev_backup.bat completed successfully in phase PRE_BACKUP

2012-08-20 16:57:04,600 PROGRESS - Creating storage snapshots for all datastores/virtual machines that are being backed up.

2012-08-20 16:57:10,397 PROGRESS - Script cdbdev_backup.bat is starting in phase POST_BACKUP

2012-08-20 16:57:10,397 INFO - Script cdbdev_backup.bat completed with output: C:\Program Files\NetApp\Virtual Storage Console\smvi\server\log\scripts>if POST_BACKUP == PRE_BACKUP goto PRE C:\Program Files\NetApp\Virtual Storage Console\smvi\server\log\scripts>if POST_BACKUP == POST_BACKUP goto POST C:\Program Files\NetApp\Virtual Storage Console\smvi\server\log\scripts>goto END

2012-08-20 16:57:10,412 PROGRESS - Script cdbdev_backup.bat completed successfully in phase POST_BACKUP

2012-08-20 16:57:10,553 PROGRESS - Sent status notification message to [admin-messages@]

2012-08-20 16:57:10,569 PROGRESS - Storing logs for backup_smvi_cdb_dev_0000_20120820165700 in file C:\Program Files\NetApp\Virtual Storage Console\smvi\server\repository\logs\3481dbbd-dedc-42c0-9fc0-2dceb2fedd2d\backup_backup_smvi_cdb_dev_0000_20120820165700.xm

Any idea what the reason or problem could be? Again, if i start my powershell script from the command line it runs well.

Confused regards ....

Thomas

Comments

Meanwhile i fixed it by myself.

I changed the last line in my powershell script and activated PSRemoting on the vm's i want to backup:

do {Start-Sleep -s 1} While (( Invoke-Command -computername $server {Get-Process -ea SilentlyContinue -Name cdb_dev_backup} -Credential $cred | Measure-Object).count -gt 0)

I just appllied the credentials again and it works as excpected.

Hope this helps others too ;-)

Have a nice weekend!

Warning!

This NetApp Community is public and open website that is indexed by search engines such as Google. Participation in the NetApp Community is voluntary. All content posted on the NetApp Community is publicly viewable and available. This includes the rich text editor which is not encrypted for https.

In accordance to our Code of Conduct and Community Terms of Use DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information
  • Copyrighted materials without the permission of the copyright owner

Files and content that do not abide by the Community Terms of Use or Code of Conduct will be removed. Continued non-compliance may result in NetApp Community account restrictions or termination.