Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Command line help for PowerShell

$
0
0

I'm working on a maintenance task to monitor drive space usage of in-memory checkpoint files which requires getting the drive spaces into SQL Server. Works fine when I run the script via PowerShell. Unfortunately, not from a SQL Server agent job because SQL Server uses an older version of PowerShell. The common solution in the SQL Server world is to use a CmdExec job step and call PowerShell.exe.

This is the PowerShell script that works in the PowerShell command window:

Powershell
$Files=gwmiwin32_volume|selectlabel,@{LABEL='CapacityGB';EXPRESSION={`"{0:F2}`"-f($_.capacity/1GB)}},caption|Where{$_.label-ne$null}ForEach($Filein$Files){$FileLabel=$File.Label$FileCapacityGB=$File.CapacityGB$FileCaption=$File.Caption$Query=@`"ExecdbaMgMT.CheckDriveSpace@Label='$FileLabel',@CapacityGB='$FileCapacityGB',...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>