我正在尝试为FSRM创建一个PowerShell脚本,该脚本将为每个驱动器创建报告。我试图询问最终用户他们希望监控多少驱动器然后跟进驱动器号,然后它将为每个驱动器号创建一个报告但是我坚持创建数组大小并将信息输入数组然后停止报告创建完成后
#Asks user for how many disks they want to have reports created for them
$Localdisks = $Null
#Sets Array size for local disk
$Localdiskarraynumber = @($localdiskarray)
#Counts how many items are in the array to how many have been applied
$localdiskarraysize = $Localdiskarray.count
#Set Size of array
$Localdiskarray = Read-Host -Prompt 'Input the amount of local disks you want to run reports on'
#Set report Name (report per disk)
$Reportname = "$env:computername-$localdisk-Report"
#Ask users for storage report email address
$EmailReport = Read-Host -Prompt 'Input your Email address for Reports:'
#Sets time for report
$d = get-date "08:30am"
#Sets day for report / weekly
$task = New-FsrmScheduledTask -Time $d -Weekly @("Monday")
Do
{
$localdisks = Read-Host -Prompt 'Disk Letter'
#report created per letter entered
New-FsrmStorageReport -Name $Reportname -Namespace "$Localdisks:\" -Schedule $task -ReportType @("LargeFiles", "DuplicateFiles", "FilesByFileGroup", "FilesByOwner", "LeastRecentlyAccessed", "MostRecentlyAccessed") -LargeFileMinimum 500MB -FileGroupIncluded @("Virus FileTypes", "3D FileTypes", "Archive File Types", "Audio FileTypes", "Database FileTypes", "Disk FileTypes", "Executables FileTypes", "Font FileTypes", "Image FileTypes", "MS Office FileTypes", "Office FileTypes", "Suspicious FileTypes", "Video FileTypes") -LeastAccessedMinimum 90 -MostAccessedMaximum 91 -MailTo $EmailReport
}
#Stops Do when full cycle through of the array is complete
until ($localdiskarraysize = $Localdisks)
答案 0 :(得分:1)
我试图询问最终用户他们希望监控多少个驱动器,然后跟进驱动器号,然后每个驱动器号创建一个报告但是我坚持创建数组大小并将信息输入到数组中通过在完成报告时停止创建报告
这是非PowerShelly设计。而不是问多少,请询问用户驱动器,直到他们停止输入更多。创建一个特定大小的数组并没有真正的概念(我猜你可以强迫这样做,但这里不常见或真正相关)。
像
这样的东西# Keep prompting for another drive until they just press enter
$drives = do
{
$drive = Read-Host "Enter another drive, or blank to finish"
$drive
} while ($drive -ne '')
# Loop over the drives and generate a report for each one
foreach ($drive in $drives)
{
# process drive here
}
然后你也不需要计算它们来使用它们。
NB。在这里你试图通过它们来计算:
until ($localdiskarraysize = $Localdisks)
PowerShell中的=
仅用于分配值($a = 1
),以测试您需要使用-eq
两件事情。