May 20, 2013 3:50 PM
Posted by: Richard Siddaway
PowerShell,
Scripting Games,
WMII have heard some discussions recently regarding whether Win32_LogicalDisk or Win32_Volume should be used in the answer to event 3 in the Scripting Games.
The problem requires you pull the drive letter, drive size and freespace for local disks on the server. Notice the emphasis – that will be...
May 16, 2013 12:56 PM
Posted by: Richard Siddaway
PowerShell,
Scripting GamesOne of the principles of writing scripts (or any code) is the KISS principle – Keep It Simple Scripter.
That principle is being abused al lot in event 3
I am seeing numerous entries that define an advanced function as the solution and then inside the PROCESS block define one or more...
May 14, 2013 1:22 PM
Posted by: Richard Siddaway
PowerShell,
Scripting Games,
WMIIn event 3 you have to get information on hard disk capacity. I’ve only looked at the first couple of dozen scripts but seen this too many times
Get-WmiObject -Class Win32_LogicalDisk | where DriveType -eq 3
or if you prefer the version 2 way
Get-WmiObject -Class Win32_LogicalDisk |...
May 12, 2013 3:20 PM
Posted by: Richard Siddaway
PowerShell,
Scripting GamesI’ve seen a lot of this type of thing in events 1 and 2
$ErrorPref = $ErrorActionPreference
$ErrorActionPreference = "Stop"
Don’t
The default for $ErrorActionPreference is Continue. This means that the error message is shown and the cmdlet attempts to continue. The possible values...
May 9, 2013 1:43 PM
Posted by: Richard Siddaway
PowerShell,
Scripting GamesI saw this in one of the submissions:
$Properties = @{}
$Properties['Computer'] = $SystemInfo.__SERVER
$Properties['OperatingSystem'] = "$($OSInfo.Caption) - $($OSInfo.CSDVersion)"
$Properties['PhysicalMemory'] = $SystemInfo.TotalPhysicalMemory
My immediate thought was the entrant...
May 7, 2013 3:00 PM
Posted by: Richard Siddaway
PowerShell,
Scripting Games,
WMIThere are some good features to this script but what really hurts is the two trips to the server for the Win32_Computersystem class
Foreach ($IP in (Get-Content "C:\IPList.txt"))
{
$Name = (Get-WMIObject Win32_ComputerSystem -ComputerName $ip).Name
$Mem = [math]::truncate((Get-WMIObject...
May 7, 2013 2:15 PM
Posted by: Richard Siddaway
PowerShell,
Scripting Games,
WMII haven’t finished blogging about event 1 yet but this caught my eye.
Things aren’t too bad until we hit the bunch of write-host calls
$wrks = (Get-Content -path C:\IPList.txt)
foreach ($wrk in $wrks)
{
$osver = Get-WMIObject -class win32_operatingsystem -ComputerName $wrk
...
May 6, 2013 11:53 AM
Posted by: Richard Siddaway
PowerShell,
Scripting GamesThe object of the exercise in both the beginners and advanced sections of event 1 was to move a set of log files older than a give data to an archive folder.
A number of solutions were presented that used robocopy.
This is a workable solution that meets the lettter of the objective but it...
May 6, 2013 9:27 AM
Posted by: Richard Siddaway
PowerShell,
Scripting GamesI’ve already blogged about incorrect use of backticks. Here is another example of un-necessary use of backticks
$Files= Get-ChildItem `
-Path $Path `
-include $Type `
-Recurse `
-File |
Where-Object {$_.LastWriteTime -lt...