Hello.
I am running a PowerShell script that is designed to list the disk space usage of a given server, local or remote, and output the results to an html file. This file, in turn, is then emailed to its intended recipient. The URL for the script is the following:
https://sqlpowershell.wordpress.com/2013/10/01/powershell-script-to-monitor-disk-space-of-a-group-of-servers-html-formatted-email-output/comment-page-1/?unapproved=13115&moderation-hash=7c658a5dbe19bf2dda12f9506e3001df#comment-13115
Using the PowerShell ISE utility, I am able to run the following commands:
Powershell -executionpolicy bypass -File C:\Scripts\disk_space_check.ps1
C:\Scripts\disk_space_check.ps1
Get-DiskSpaceReport -ComputerList C:\Scripts\server.txt -To <email address> -From <email address> -SMTP <smtp server address>
The problem that I am encountering is the following: If I run the above commands in an elevated PowerShell terminal, only the first two commands successfully execute. The third command fails, and the following error message appears on-screen:
PS C:\Windows\system32> Get-DiskSpaceReport -ComputerList C:\Scripts\server.txt -To <email address> -From <email address> -SMTP <smtp server address>
Get-DiskSpaceReport : The term 'Get-DiskSpaceReport' is not recognized as the name of a cmdlet, function, 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 line:1 char:1
+ Get-DiskSpaceReport -ComputerList C:\Scripts\server.txt -To ahkaplan@ ...
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-DiskSpaceReport:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What do I need to do in order to correct this problem? The goal is to run the above commands in a PowerShell script that, in turn, can be scheduled to run at regular intervals using the Task Scheduler utility.