• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1294
  • Last Modified:

Script to get the disk space percentage

Hi,
I have hot the below script from Chris Dent in one of the related articles.Need steps to run this script as i am novice in scripting.

$FromAddress = "someone@domain.com"
$ToAddress = "you@domain.com"
$Server = "SomeMailServer"
 
# Configure an HTML Style to use in the HTML Head
$Style = "<style type='text/css'>`r`n" + `
  "td { width: 200px; text-align: center }`r`n" + `
  "td.highlight { background-color: orange; }`r`n</style>"
 
# Get the volume information
$VolumeInformation = Get-WmiObject Win32_LogicalDisk -Filter "DriveType='3'" `
    -ComputerName (Get-Content "c:\Systems Administration\Scripts\Servers.txt") | `
  Select-Object `
    @{n="Server";e={$_.SystemName}}, `
    @{n="Volume";e={$_.DeviceID}}, `
    @{n="Free Space on Volume (GB)";e={"{0:n2}" -f ($_.FreeSpace/1gb)}}, `
    @{n="Total Space on Volume (GB)";e={"{0:n2}" -f ($_.Size/1gb)}}, `
    @{n="Percentage Free";e={ "{0:P2}" -f ([Int64]$_.FreeSpace / [Int64]$_.Size) }}
 
# Convert to HTML and highlight rows less than 20%
$HtmlBody = $VolumeInformation | ConvertTo-Html -Head $Style | %{
  # RegEx should match values of 0 to 9 or 10 to 19.
  If ($_ -Match ".*<td>([0-9]|1[0-9])\..*%</td>.*") {  
    $_ -Replace "<td>", "<td class='highlight'>"  
  } Else { $_ }
}
 
# Create a mail
$MailMessage = New-Object Net.Mail.MailMessage( `
  $FromAddress, `
  $ToAddress, `
  "Volume Usage", `
  $HtmlBody)
$MailMessage.IsBodyHtml = $True
 
# Send the mail
$SmtpClient = New-Object Net.Mail.SmtpClient($Server)
$SmtpClient.Send($MailMessage)
0
collaberait
Asked:
collaberait
  • 16
  • 15
2 Solutions
 
Meir RivkinFull stack Software EngineerCommented:
what exactly u need?
0
 
Chris DentPowerShell DeveloperCommented:

If you just want to run it right now:

1. Correct the values about mail at the top
2. Copy and paste the lot into PowerShell and hit return a couple of times

If you want to run it as a scheduled task:

1. Save the code above in a text file with a .ps1 extension (after fixing the SMTP addressing)
2. In PowerShell on the system run:

Set-ExecutionPolicy RemoteSigned

Otherwise it won't let you run the script. You can control this in Group Policy if you install the PowerShell template. See "Get-Help about_Execution_Policy"

3. Create a Scheduled Task to run:

PowerShell.exe FullPathAndNameOfScript.ps1

4. Make sure your AV software isn't blocking SMTP or the mail won't send!

HTH

Chris
0
 
collaberaitAuthor Commented:
I am getting the below error when i copy and run.


Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $FromAddress = "diskspace@xyz
ra.com"
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $ToAddress = "saimohan@xyzra
com"
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $Server = "testsrv"
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Configure an HTML Style to use
in the HTML Head
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $Style = "<style type='text/css'>
`r`n" + `
You must provide a value expression on the right-hand side of the '+' operator.
At line:1 char:41
+ $Style = "<style type='text/css'>`r`n" + <<<<  `
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
   ception
    + FullyQualifiedErrorId : ExpectedValueExpression

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>   "td { width: 200px; text-align:
 center }`r`n" + `
You must provide a value expression on the right-hand side of the '+' operator.
At line:1 char:50
+   "td { width: 200px; text-align: center }`r`n" + <<<<  `
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
   ception
    + FullyQualifiedErrorId : ExpectedValueExpression

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>   "td.highlight { background-colo
r: orange; }`r`n</style>"
td.highlight { background-color: orange; }
</style>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Get the volume information
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $VolumeInformation = Get-WmiObjec
t Win32_LogicalDisk -Filter "DriveType='3'" `
Get-WmiObject : Invalid query
At line:1 char:35
+ $VolumeInformation = Get-WmiObject <<<<  Win32_LogicalDisk -Filter "DriveType
='3'" `
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], Managemen
   tException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.C
   ommands.GetWmiObjectCommand

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>     -ComputerName (Get-Content "c
:\Systems Administration\Scripts\Servers.txt") | `
Missing expression after unary operator '-'.
At line:1 char:6
+     - <<<< ComputerName (Get-Content "c:\Systems Administration\Scripts\Serve
rs.txt") | `
    + CategoryInfo          : ParserError: (-:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>   Select-Object `
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>     @{n="Server";e={$_.SystemName
}}, `
Missing expression after ','.
At line:1 char:37
+     @{n="Server";e={$_.SystemName}}, <<<<  `
    + CategoryInfo          : ParserError: (,:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterToken

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>     @{n="Volume";e={$_.DeviceID}}
, `
Missing expression after ','.
At line:1 char:35
+     @{n="Volume";e={$_.DeviceID}}, <<<<  `
    + CategoryInfo          : ParserError: (,:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterToken

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>     @{n="Free Space on Volume (GB
)";e={"{0:n2}" -f ($_.FreeSpace/1gb)}}, `
Missing expression after ','.
At line:1 char:73
+     @{n="Free Space on Volume (GB)";e={"{0:n2}" -f ($_.FreeSpace/1gb)}}, <<<<
  `
    + CategoryInfo          : ParserError: (,:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterToken

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>     @{n="Total Space on Volume (G
B)";e={"{0:n2}" -f ($_.Size/1gb)}}, `
Missing expression after ','.
At line:1 char:69
+     @{n="Total Space on Volume (GB)";e={"{0:n2}" -f ($_.Size/1gb)}}, <<<<  `
    + CategoryInfo          : ParserError: (,:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterToken

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>     @{n="Percentage Free";e={ "{0
:P2}" -f ([Int64]$_.FreeSpace / [Int64]$_.Size) }}

Name                           Value
----                           -----
n                              Percentage Free
e                               "{0:P2}" -f ([Int64]$_.FreeSpace / [Int64]$_...


PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Convert to HTML and highlight r
ows less than 20%
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $HtmlBody = $VolumeInformation |
ConvertTo-Html -Head $Style | %{
>>   # RegEx should match values of 0 to 9 or 10 to 19.
>>   If ($_ -Match ".*<td>([0-9]|1[0-9])\..*%</td>.*") {
>>     $_ -Replace "<td>", "<td class='highlight'>"
>>   } Else { $_ }
>> }
>>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Create a mail
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $MailMessage = New-Object Net.Mai
l.MailMessage( `
>>   $FromAddress, `
>>   $ToAddress, `
>>   "Volume Usage", `
>>   $HtmlBody)
>> $MailMessage.IsBodyHtml = $True
>>
Missing closing ')' in expression.
At line:2 char:3
+    <<<< $FromAddress, `
    + CategoryInfo          : ParserError: (CloseParenToken:TokenId) [], Paren
   tContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndParenthesisInExpression

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Send the mail
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $SmtpClient = New-Object Net.Mail
.SmtpClient($Server)
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $SmtpClient.Send($MailMessage)
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
Chris DentPowerShell DeveloperCommented:

I suspect it's managed to inert some spaces for you, it's very sensitive about trailing spaces. I've put it into a text file, rename that to .ps1 and try again please.

I did forget one thing. This is how it determines which systems it should run for:

...
    -ComputerName (Get-Content "c:\Systems Administration\Scripts\Servers.txt") | `
...

That file must exist, otherwise you'll need to change the path. If you'd like it to find systems to check in a different way then please let me know.

Chris
WMI-CheckDisk.txt
0
 
collaberaitAuthor Commented:
I created the path & ran the file given to me ,it still thows the same error.Basically , the servers.txt contains the list of servers with disk partitions which it needs to get the percentage details.Please let me know if i am missing something here..

$FromAddress = "diskspace@xyz.com"
$ToAddress = "saimohan@xyz.com"
$Server = "testsrv"
 
# Configure an HTML Style to use in the HTML Head
$Style = "<style type='text/css'>`r`n" + `
  "td { width: 200px; text-align: center }`r`n" + `
  "td.highlight { background-color: orange; }`r`n</style>"
 
# Get the volume information
$VolumeInformation = Get-WmiObject Win32_LogicalDisk -Filter "DriveType='3'" `
    -ComputerName (Get-Content "c:\Systems Administration\Scripts\Servers.txt") | `
  Select-Object `
    @{n="Server";e={$_.SystemName}}, `
    @{n="Volume";e={$_.DeviceID}}, `
    @{n="Free Space on Volume (GB)";e={"{0:n2}" -f ($_.FreeSpace/1gb)}}, `
    @{n="Total Space on Volume (GB)";e={"{0:n2}" -f ($_.Size/1gb)}}, `
    @{n="Percentage Free";e={ "{0:P2}" -f ([Int64]$_.FreeSpace / [Int64]$_.Size) }}
 
# Convert to HTML and highlight rows less than 20%
$HtmlBody = $VolumeInformation | ConvertTo-Html -Head $Style | %{
  # RegEx should match values of 0 to 9 or 10 to 19.
  If ($_ -Match ".*<td>([0-9]|1[0-9])\..*%</td>.*") {  
    $_ -Replace "<td>", "<td class='highlight'>"  
  } Else { $_ }
}
 
# Create a mail
$MailMessage = New-Object Net.Mail.MailMessage( `
  $FromAddress, `
  $ToAddress, `
  "Volume Usage", `
  $HtmlBody)
$MailMessage.IsBodyHtml = $True
 
# Send the mail
$SmtpClient = New-Object Net.Mail.SmtpClient($Server)
$SmtpClient.Send($MailMessage)
0
 
Chris DentPowerShell DeveloperCommented:

Exactly the same set of errors as above?

Otherwise can you repost them please?

Chris
0
 
collaberaitAuthor Commented:
ok.PF below,

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $FromAddress = "diskspace@xyz.com"
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $ToAddress = "saimohan@xyz.com"
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $Server = "testsrv"
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Configure an HTML Style to use
in the HTML Head
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $Style = "<style type='text/css'>
`r`n" + `
>>   "td { width: 200px; text-align: center }`r`n" + `
>>   "td.highlight { background-color: orange; }`r`n</style>"
>>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Get the volume information
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $VolumeInformation = Get-WmiObjec
t Win32_LogicalDisk -Filter "DriveType='3'" `
>>     -ComputerName (Get-Content "c:\Systems Administration\Scripts\Servers.txt
") | `
>>   Select-Object `
>>     @{n="Server";e={$_.SystemName}}, `
>>     @{n="Volume";e={$_.DeviceID}}, `
>>     @{n="Free Space on Volume (GB)";e={"{0:n2}" -f ($_.FreeSpace/1gb)}}, `
>>     @{n="Total Space on Volume (GB)";e={"{0:n2}" -f ($_.Size/1gb)}}, `
>>     @{n="Percentage Free";e={ "{0:P2}" -f ([Int64]$_.FreeSpace / [Int64]$_.Si
ze) }}
>>
Get-Content : Cannot find path 'C:\Systems Administration\Scripts\Servers.txt'
because it does not exist.
At line:2 char:31
+     -ComputerName (Get-Content <<<<  "c:\Systems Administration\Scripts\Serve
rs.txt") | `
    + CategoryInfo          : ObjectNotFound: (C:\Systems Admi...pts\Servers.t
   xt:String) [Get-Content], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetCo
   ntentCommand

Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum
ent is null or empty. Supply an argument that is not null or empty and then try
 the command again.
At line:2 char:18
+     -ComputerName <<<<  (Get-Content "c:\Systems Administration\Scripts\Serve
rs.txt") | `
    + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindi
   ngValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
   Shell.Commands.GetWmiObjectCommand

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Convert to HTML and highlight r
ows less than 20%
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $HtmlBody = $VolumeInformation |
ConvertTo-Html -Head $Style | %{
>>   # RegEx should match values of 0 to 9 or 10 to 19.
>>   If ($_ -Match ".*<td>([0-9]|1[0-9])\..*%</td>.*") {
>>     $_ -Replace "<td>", "<td class='highlight'>"
>>   } Else { $_ }
>> }
>>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Create a mail
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $MailMessage = New-Object Net.Mai
l.MailMessage( `
>>   $FromAddress, `
>>   $ToAddress, `
>>   "Volume Usage", `
>>   $HtmlBody)
>> $MailMessage.IsBodyHtml = $True
>>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Send the mail
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $SmtpClient = New-Object Net.Mail
.SmtpClient($Server)
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $SmtpClient.Send($MailMessage)
0
 
Chris DentPowerShell DeveloperCommented:

Hey that's a bit better :)

So we're just stuck here:

> Get-Content : Cannot find path 'C:\Systems Administration\Scripts\Servers.txt' because it does not exist.

Once that exists we should be good to go. The path can be changed, it doesn't have to be C:\ etc, we can use whatever you please.

Chris
0
 
collaberaitAuthor Commented:
Path exists but it is still throwing the same error.Can i change the path?Please mention the steps

Regards,
Sai
0
 
Chris DentPowerShell DeveloperCommented:

Yes, you need to change this line:

    -ComputerName (Get-Content "c:\Systems Administration\Scripts\Servers.txt")  | `

If you wanted to read it from servers.txt in the current directory that becomes:

    -ComputerName (Get-Content "Servers.txt")  | `

If you wanted to read it from C:\Servers.txt it becomes:

    -ComputerName (Get-Content "c:\Servers.txt")  | `

And so on.

Chris
0
 
collaberaitAuthor Commented:
It gives the below error now...

Get-WmiObject : Cannot validate argument on parameter 'ComputerName'. The argum
ent is null or empty. Supply an argument that is not null or empty and then try
 the command again.
At line:2 char:18
+     -ComputerName <<<<  (Get-Content "c:\Servers.txt") | `
    + CategoryInfo          : InvalidData: (:) [Get-WmiObject], ParameterBindi
   ngValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
   Shell.Commands.GetWmiObjectCommand
0
 
Chris DentPowerShell DeveloperCommented:

Run this on its own if you could please:

Get-Content "C:\Servers.txt"

It should return everything in your text file.

Chris
0
 
collaberaitAuthor Commented:
NOthing is coming to the txt fiie.

Please note that i am doing the following steps to run the script:
servers.txt list the servers with drive information to extract the details.

1.Open powershell.exe
2.Copy the code in powershell.

Please let me know if i am doing right?

0
 
Chris DentPowerShell DeveloperCommented:

Then your text file is empty. For this to work it must contain a list of server names. e.g.

server1
server2
server3
etc

Chris
0
 
collaberaitAuthor Commented:
Chris,

I had listed around 80+ servers in the txt file.
eg:TESTSRV\\C$.

0
 
Chris DentPowerShell DeveloperCommented:

They must be Server Names only. "TESTSRV\\C$" will not work.

However, that doesn't get around Get-Content failing to read anything from the text file. It's difficult to check that for you, all I can encourage you to do is check the path and file content.

Chris
0
 
collaberaitAuthor Commented:
I have only put the server names & also i am not getting any email as well.

Sai
0
 
Chris DentPowerShell DeveloperCommented:

Does it get the content of the file now? Or is it still complaining?

And do you get an error after this line:

$SmtpClient.Send($MailMessage)

Chris
0
 
collaberaitAuthor Commented:

Here you go..


Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $FromAddress = "diskspace@xyz.com"
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $ToAddress = "saimohan@xyz.
com.com"
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $Server = "testsrv2"
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Configure an HTML Style to use
in the HTML Head
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $Style = "<style type='text/css'>
`r`n" + `
>>   "td { width: 200px; text-align: center }`r`n" + `
>>   "td.highlight { background-color: orange; }`r`n</style>"
>>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Get the volume information
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $VolumeInformation = Get-WmiObjec
t Win32_LogicalDisk -Filter "DriveType='3'" `
>>     -testfilesrv (Get-Content "c:\Servers.txt") | `
>>   Select-Object `
>>     @{n="Server";e={$_.SystemName}}, `
>>     @{n="Volume";e={$_.DeviceID}}, `
>>     @{n="Free Space on Volume (GB)";e={"{0:n2}" -f ($_.FreeSpace/1gb)}}, `
>>     @{n="Total Space on Volume (GB)";e={"{0:n2}" -f ($_.Size/1gb)}}, `
>>     @{n="Percentage Free";e={ "{0:P2}" -f ([Int64]$_.FreeSpace / [Int64]$_.Si
ze) }}
>>
Get-WmiObject : A parameter cannot be found that matches parameter name 'testfi
lesrv'.
At line:2 char:17
+     -testfilesrv <<<<  (Get-Content "c:\Servers.txt") | `
    + CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ParameterB
   indingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm
   ands.GetWmiObjectCommand

PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Convert to HTML and highlight r
ows less than 20%
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $HtmlBody = $VolumeInformation |
ConvertTo-Html -Head $Style | %{
>>   # RegEx should match values of 0 to 9 or 10 to 19.
>>   If ($_ -Match ".*<td>([0-9]|1[0-9])\..*%</td>.*") {
>>     $_ -Replace "<td>", "<td class='highlight'>"
>>   } Else { $_ }
>> }
>>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Create a mail
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $MailMessage = New-Object Net.Mai
l.MailMessage( `
>>   $FromAddress, `
>>   $ToAddress, `
>>   "Volume Usage", `
>>   $HtmlBody)
>> $MailMessage.IsBodyHtml = $True
>>
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> # Send the mail
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $SmtpClient = New-Object Net.Mail
.SmtpClient($Server)
PS C:\WINDOWS\system32\WindowsPowerShell\v1.0> $SmtpClient.Send($MailMessage)
0
 
Chris DentPowerShell DeveloperCommented:
You changed the parameter name...

Nevermind, please use the attached version as follows.

1. Save the attachment as CheckDiskSpace.ps1
2. Open PowerShell and change to the same directory as the attachment
3. Run:

.\CheckDiskSpace.ps1 -From "you@yourdomain.com" -To "you@yourdomain.com" -SmtpServer "MailServer" -File "c:\servers.txt"

Chris
CheckDiskSpace.txt
0
 
collaberaitAuthor Commented:
I am working on it & will revert. Just to confirm ,please correct if the below command is ok.


.\CheckDiskSpace.ps1 -From "diskspacei@xyz.com" -To "sai@xyz.com" -SmtpServer "MailServer01" -File "c:\servers.txt"

Sai
0
 
collaberaitAuthor Commented:
Chris,

I am getting the below error.

PS C:\> .\CheckDiskSpace.ps1 -From "diskspace@xyz.com" -To "sai@xyz.com" -SmtpServer "mail02" -File "c:\servers.txt"
File C:\CheckDiskSpace.ps1 cannot be loaded because the execution of scripts is
 disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:21
+ .\CheckDiskSpace.ps1 <<<<  -From "diskspacei@collabera.com" -To "saimohan@col
labera.com" -SmtpServer "gciblrmb02" -File "c:\servers.txt"
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException
0
 
Chris DentPowerShell DeveloperCommented:

Please run:

Set-ExecutionPolicy RemoteSigned

Then retry the command above.

Your email address is in the error message above, do you want that removed?

Chris
0
 
collaberaitAuthor Commented:
Chris,

One good news is that i am getting the email but does not give disk space report.Below is the error

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Documents and Settings\saimohan> cd\
PS C:\> .\CheckDiskSpace.ps1 -From "diskspace@xyz.com" -To "sai@xyz.com" -SmtpServer "ms0123" -File
 "c:\servers.txt"
Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At C:\CheckDiskSpace.ps1:32 char:35
+ $VolumeInformation = Get-WmiObject <<<<  Win32_LogicalDisk -Filter "DriveType='3'" `
    + CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

PS C:\>
0
 
Chris DentPowerShell DeveloperCommented:

That's a good step forward, even if it's an error message.

The script uses WMI to grab the information you're after, you must execute the script as an administrator account or you'll get this error message (Access Denied).

There are two choices here, either you run PowerShell as an administrator account, or we have the script ask you for credentials to use. Which do you prefer?

Chris
0
 
collaberaitAuthor Commented:
I am using a domain admin account but still it fails???

please also edit the script to ask for credentails.

Sai
0
 
Chris DentPowerShell DeveloperCommented:

You're not running it on Windows Vista / 7 / 2008 / 2008 R2 are you? If you are, you should run the PowerShell prompt as Administrator (Run As Administrator). Even if it's an admin account it will still limit your rights unless you explicitly enable them again by doing that.

Otherwise, this version will prompt for credentials, a logon box will pop up.

Chris
CheckDiskSpace.txt
0
 
collaberaitAuthor Commented:
Now its working.what i did is removed linux systems from the server list & it is sending the email with %..can you also edit the code that it can also take linux?
0
 
Chris DentPowerShell DeveloperCommented:

No, sorry, this one is only able to deal with Windows. Linux / Unix is likely to require something like SSH (which PowerShell can't do on its own).

It is possible to get SSH for PowerShell, it's included in this module for example:

http://www.nsoftware.com/PowerShell/

Perhaps worth considering that if you have an ongoing requirement to do this.

Chris
0
 
collaberaitAuthor Commented:
Thanks Chris. YOu get the full points.

Also ,Do you have any script which will push softwares on all xp,vista,win2k3.Please let me know ?
0
 
Chris DentPowerShell DeveloperCommented:

Afraid not, I've always used Group Policy for that kind of thing.

Chris
0
 
collaberaitAuthor Commented:
can you please refer any article for the same.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 16
  • 15
Tackle projects and never again get stuck behind a technical roadblock.
Join Now