powershell command in batch script

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  Venkata Kalyan 6 months, 2 weeks ago.

  • Author
    Posts
  • #63399

    Venkata Kalyan
    Participant

    Hi,
    I have a batch script, I am trying to call powershell command. It is giving me an error.

    Below is the script:

    set targetDBSize=
    for /f %%G in ('powershell "{0:N2}MB" -f ((gci -path \\kalyantest\c$\Progra~1\Micros~1\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\%targetSite%.mdf | Measure-Object length -Sum).Sum/ 1mb') do set /A targetDBSize=%%~zG

    Can someone help me where I am doing wrong.

    -Kalyan

  • #63400

    Daniel Krebs
    Moderator

    Why do you want to use a batch script instead of a proper PowerShell script in the first place?

    • #63406

      Venkata Kalyan
      Participant

      Hi,
      The complete code was written in batch code. Trying to modify some part in that. While doing this, found an issue, I am not able get the file size which is having more than 2GB.

      If I try to modify the entire code to powershell, it could create a mess.

      So, wanted to use powershell command & then out the result to a file:

      set targetDBSize=

      do set /A targetDBSize=%%~zG

      -Kalyan

You must be logged in to reply to this topic.