小编use*_*412的帖子

在PowerShell中使用变量创建表

我还在学习PowerShell脚本的方法,我正在编写一个脚本来计算文件服务器的可用空间百分比,并在驱动器剩余10%或更少的可用空间时发送电子邮件通知(发生这种情况)大概每月一次,在我收到客户的电子邮件之前我需要知道,没有更多的空间.截至目前,该脚本运行良好,并设置为每天早上通过Windows任务运行.但是我现有的输出格式是手动完成的.我想知道是否有办法从使用Get-WmiObject函数收集和计算的信息中传递变量.我已经尝试了格式表并尝试搞乱哈希表,但无济于事.任何想法都会有所帮助.谢谢.

# Set Parameters
$file = "c:\location\Lowdisk.txt"
Clear-Content $file

$emailTO = "Someone@SomeDomain.com"
$emailFrom = "Someone@SomeDomain.com"
$smtpServer = "smtpServer"

$diskspace = "3"
$computers = ("FSCN01","FSCN02","FSCN03","FSCN04")
echo "Server Name       Drive       Drive Size       Free Space       % Free" >> $file
$i = 0

# Get Drive Data
foreach($computer in $computers)
{
$drives = Get-WmiObject -ComputerName $computer Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}
foreach($drive in $drives)
{
    $ID = $drive.DeviceID
    $size1 = $drive.size / 1GB
    $size = "{0:N1}" -f $size1
    $free1 = $drive.freespace / 1GB …
Run Code Online (Sandbox Code Playgroud)

powershell formatting wmi

5
推荐指数
1
解决办法
4万
查看次数

标签 统计

formatting ×1

powershell ×1

wmi ×1