I have this powershell command to find the whitespace in each of my Exchange databases, however I cannot get it to run via batch.
Here is the shell command confirmed working:
get-mailboxdatabase -status |
select name,
@{Name="DataBaseSize";Expression={ "{0:N2} GB" -f (($_.DatabaseSize.ToBytes()) / 1gb) }},
@{Name="AvailableNewMailboxSpace";Expression={ "{0:N2} GB" -f(($_.AvailableNewMailboxSpace.ToBytes()) / 1gb) }},
@{Name="Difference";Expression={ "{0:N2} GB" -f (($_.DatabaseSize.ToBytes() - $_.AvailableNewMailboxSpace.ToBytes()) / 1gb) }}
Here is the batch to run the Shell command:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'D:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto;
I am thinking that the characters in the shell command are not cooperating with the batch and have tried "^"
them where they fail. Any help would be appreciated. I am fairly new to both batch and powershell, so please use small words :)
NEW INFO: Hi thanks for your help. To answer your first question of why I am trying to do this with a batch is because this is just one of the steps I am trying to accomplish. I want this powershell command to output to a .txt doc so I can then run a FOR loop against it and write the parameters to an html file which will then be blat'ed daily to my IT team to monitor the growth on the whitespace. Also the error codes I am receiving are not related to your assumptions and I apologize for not including them. The error code I get is: Unexpected token ':N2' in expression or statement. When I remove the ":N2" from the command it then complains about the 'GB', and finally when I remove the "GB" it then complains about the term 'DataBaseSize'. So I will be trying your solutions here in the next few hours, I just wanted to say thanks and to let you know the errors I am seeing.
NEW ERRORS:
After I run it using Beavels suggestion I receive these errors:
C:\temp2>Whitespace.bat The term 'get-mailboxdatabase' is not recognized as the name of a cmdlet, funct ion, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\temp2\Whitespace.ps1:1 char:20
+ get-mailboxdatabase <<<< -status |select name, @{Name="DataBaseSize";Express
ion={ "{0:N2} GB" -f (($_.DatabaseSize.ToBytes()) / 1gb) }}, @{Name="AvailableN
ewMailboxSpace";Expression={ "{0:N2} GB" -f(($_.AvailableNewMailboxSpace.ToByte
s()) / 1gb) }}, @{Name="Difference";Expression={ "{0:N2} GB" -f (($_.DatabaseSi
ze.ToBytes() - $_.AvailableNewMailboxSpace.ToBytes()) / 1gb) }}
+ CategoryInfo : ObjectNotFound: (get-mailboxdatabase:String) [],
CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
It is complaining about the term get-mailboxedatabase however this is a CDMLET. Ugh....
JOESPH
C:\temp2>. 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps 1' '.' is not recognized as an internal or external command, operable program or batch file.
C:\temp2>Connect-ExchangeServer -auto 'Connect-ExchangeServer' is not recognized as an internal or external command, operable program or batch file.
C:\temp2>$properties = @( '$properties' is not recognized as an internal or external command, operable program or batch file.
C:\temp2>"name" '"name"' is not recognized as an internal or external command, operable program or batch file. '{Name' is not recognized as an internal or external command, operable program or batch file. '{Name' is not recognized as an internal or external command, operable program or batch file. '{Name' is not recognized as an internal or external command, operable program or batch file.
C:\temp2># you might want to put this file on a file server somewhere '#' is not recognized as an internal or external command, operable program or batch file.
C:\temp2>$pathToFile = "\server\share\Some\Path\To\File.html" '$pathToFile' is not recognized as an internal or external command, operable program or batch file.
C:\temp2>$data = Get-mailboxdatabase -status | select $properties | sort-obj ect name | ConvertTo-Html | Set-Content $pathToFile - '$data' is not recognized as an internal or external command, operable program or batch file.
I may just take this Database offline and do a defrag to free up the space. Instead of trying to monitor it from this crazy idea.