I have used PSScriptAnalyzer on a PowerShell script of mine and it throws this warning…
- User
I have used PSScriptAnalyzer on a PowerShell script of mine and it throws this warning on line 1578 and line 1583: "File 'ScanMedia - Testing.ps1' uses WMI cmdlet. For PowerShell 3.0 and above, use CIM cmdlet which perform the same tasks as the WMI cmdlets. The CIM cmdlets comply with WS-Management (WSMan) standards and with the Common Information Model (CIM) standard, which enablesthe cmdlets to use the same techniques to manage Windows computers and those running other operating systems."
This is an exempt of that specific part of the script: " # Get all the child items of the supplied directory and attempt to scan the files with the function CheckFile Get-ChildItem -LiteralPath global:Path -File -Recurse | Where-Object { include -contains $_.Extension } | ForEach-Object {
codeIf ($global:IdleScan) { $CPUAverage = Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select-Object Average While ($CPUAverage.Average -gt 25) { Write-Verbose "CPU usage above 25 percent. Pausing for 5 minutes" Write-Verbose "Current CPU Usage: $($CPUAverage.Average)" Start-Sleep -s 300 $CPUAverage = Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select-Object Average } }"The first line that has "Get-WmiObject" is line 1578 of the script and the second line that has "Get-WmiObject" in it is line 1583. How can I fix this so it doesn't give the warning anymore?
- Assistant