操作系統windows 8,我手動調度腳本輸入自由diskspaces在一個CSV文件導入,使用Windows任務schedular.The腳本運行,但沒有輸出它給定當是任務程序器。使用的代碼如下PowerShell的調度Diskspaces導入
Set-ExecutionPolicy Unrestricted -Force
$filepath = "C:\Users\asdf\Downloads\Powershell\CheckFreeSpaceV3"
$servername = "abc"
#delete reports older than 7 days
$OldReports = (Get-Date).AddDays(-7)
#Removing Report older than 7 Days
Get-ChildItem $filepath\DiskReport*.* | `
Where-Object { $_.LastWriteTime -le $OldReports} | `
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
#Create variable for log date
$LogDate = get-date -f yyyyMMddhhmm
$DiskReport = Get-WmiObject win32_logicaldisk `
-ComputerName $servername -Filter "Drivetype=3" `
-ErrorAction SilentlyContinue |
#return only disks with free space less than or equal to 0.1 (40%)
Where-Object { ($_.freespace/$_.size) -le '0.4'}
#Create Reports
$DiskReport |
Select-Object @{Label = "Server Name";Expression = {$_.SystemName}},
@{Label = "Drive";Expression = {$_.DeviceID}},
@{Label = "Total Space(GB)";Expression = {"{0:N1}" -f($_.Size/1gb)}},
@{Label = "Free Space (GB)";Expression = {"{0:N1}" -f($_.Freespace/1gb) }},
@{Label = 'Free Space (%)'; Expression = {"{0:P0}" -f ($_.freespace/$_.size)}} |
I put the following arguments in taskschdular arguments
-NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File powershell_Script_path
感謝Ranadip,我已經安排在任務程序器腳本問題,儘管腳本運行正常,但定當它不工作。 –
@AhmadRaza:我正在粘貼另一個腳本,它將通過PowerShell創建計劃任務。 按照您的要求更改腳本路徑和其他詳細信息。 如果您對答案滿意,請喜歡它;這將增加看法,也會幫助其他人。 –