-
I noticed code like this in quite a few entries in for Event 1 Get-ChildItem -path C:\Application\log -Recurse -Filter *.log | Where-Object{$_.LastWriteTime -lt [DateTime]::Now.Subtract([TimeSpan]::FromDays(90))} | ForEach-Object {…} From the title it...
-
Grading the scripts in Event 4 and the one thing that jumps out is the amount of unnecessary data being carried through the scripts You were asked for 7 properties off 20 random users Get-ADUser has a –properties parameter. USE it to restrict the properties...
-
I 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...
-
One 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...
-
In 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...
-
I’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...
-
I saw this in one of the submissions: $Properties = @{} $Properties['Computer'] = $SystemInfo.__SERVER $Properties['OperatingSystem'] = "$($OSInfo.Caption) - $($OSInfo.CSDVersion)" $Properties['PhysicalMemory'] = $SystemInfo...
-
One improvement that came with PowerShell v3 is the –File and –Directory parameters on Get-ChildItem If I run this Get-ChildItem -Path c:\mydata I will get a mixture of directories and files Mode ...
-
There 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...
-
I 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...
-
The 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...
-
I’ve already blogged about incorrect use of backticks. Here is another example of un-necessary use of backticks $Files= Get-ChildItem ` -Path $Path ` -include...
-
One of the things we were asked to blog about as Scripting Games judges was things we liked and disliked. This code is a major dislike Get-ChildItem $sourceDirectory | ? {$_.PsISContainer } | % { $subDirectory = $_ ; Get-ChildItem...
-
I keep seeing paramter constructs like this: [int]$age = '90' Why set the parameter to an integer and then set the default as a string. PowerShell will convert but it just doesn’t make sense. All you need is [int]$age = 90 Read More...
-
I am seeing an incredible number of scripts that have this sort of coding round parameters # Input from the user [Parameter(Mandatory=$false, ...