powershell command in batch script

Welcome Forums General PowerShell Q&A powershell command in batch script

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
1 year, 8 months ago.

  • Author
    Posts
  • #63399

    Participant
    Points: 0
    Rank: Member

    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

    Moderator
    Points: 0
    Team Member
    Rank: Member

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

    • #63406

      Participant
      Points: 0
      Rank: Member

      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

The topic ‘powershell command in batch script’ is closed to new replies.