powershell command in batch script

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Venkata Kalyan Venkata Kalyan 4 months, 3 weeks ago.

  • Author
    Posts
  • #63399
    Profile photo of Venkata Kalyan
    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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

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

    • #63406
      Profile photo of Venkata Kalyan
      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.