PowerShell for Windows Admins:

PowerShell


May 14, 2013  1:22 PM

Scripting Games–filtering on remote server



Posted by: Richard Siddaway
PowerShell, Scripting Games, WMI

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-WmiObject -Class Win32_LogicalDisk |...

May 12, 2013  3:20 PM

Scripting games–ErrorActionPreference



Posted by: Richard Siddaway
PowerShell, Scripting Games

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 the cmdlet attempts to continue. The possible values...


May 9, 2013  1:43 PM

Scripting Games–making work



Posted by: Richard Siddaway
PowerShell, Scripting Games

I 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

Scripting Games-don’t repeat the work



Posted by: Richard Siddaway
PowerShell, Scripting Games, WMI

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).Name $Mem = [math]::truncate((Get-WMIObject...


May 7, 2013  2:15 PM

Scripting Games–how not to output data



Posted by: Richard Siddaway
PowerShell, Scripting Games, WMI

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 -class win32_operatingsystem -ComputerName $wrk ...


May 6, 2013  11:53 AM

Scripting Games: event 1–use of robocopy



Posted by: Richard Siddaway
PowerShell, Scripting Games

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 the lettter of the objective but it...


May 6, 2013  9:27 AM

Scripting Games–major dislike #2



Posted by: Richard Siddaway
PowerShell, Scripting Games

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 $Type ` -Recurse ` -File | Where-Object {$_.LastWriteTime -lt...


May 6, 2013  7:53 AM

Scripting games-major dislike



Posted by: Richard Siddaway
PowerShell, Scripting Games

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 ("$sourceDirectory\$subDirectory") -Include *.LOG -Recurse...


May 6, 2013  4:20 AM

Scripting Games–integer parameters



Posted by: Richard Siddaway
PowerShell, Scripting Games

I keep seeing parameter 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


May 5, 2013  4:30 PM

Scripting games–using parameters



Posted by: Richard Siddaway
PowerShell, Scripting Games

I am seeing an incredible number of scripts that have this sort of coding round parameters # Input from the user [Parameter(Mandatory=$false, ValueFromPipeline=$False, Position=0)] [ValidateScript({Test-Path $_ })] [String]$SourcePath =...


Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: