OS Windows 8では、Windowsタスクschedularを使用して、csvファイルにインポートする空きディスク領域をインポートするスクリプトをスケジュールしています。スクリプトは手動で実行されますが、スケジュールされているとタスクスケジュールです。使用されるコードは次のとおりですPowershell Scheduling 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は、私は、タスクschedularでスクリプトをスケジュールに問題があります。 –
@AhmadRaza:私はpowershellを介してスケジュールされたタスクを作成する別のスクリプトを貼り付けています。 必要に応じて、スクリプトのパスと追加の詳細を変更します。 Answersに満足していれば、それを好きにしてください。それは見方を高め、他人を助けるでしょう。 –