header image

Archive for May, 2013

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                LastWriteTime     Length Name —-                ————-     —— —- d—-        19/11/2012     20:19            Delivery d—-        26/02/2013     19:24            Demo d—-        05/05/2013     11:26            ScriptingGames 2013 d-r–        07/05/2013     18:17            […]

under: PowerShell V3, Scripting Games

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 Win32_ComputerSystem -ComputerName $ip).TotalPhysicalMemory / 1MB) $Ver = (Get-WMIObject Win32_OperatingSystem -ComputerName $ip).Caption [Array]$Cpus = (Get-WMIObject Win32_Processor -ComputerName $ip) […]

under: PowerShell and WMI, PowerShell original, Scripting Games

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     $procs = @(Get-WMIObject -class win32_processor -ComputerName $wrk)     $psok=($procs.SocketDesignation).count     $pcors=(($procs.numberofcores[0])*$psok) […]

under: PowerShell and WMI, PowerShell original, 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 […]

under: PowerShell original, 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 (get-date).AddDays(-$OlderThan) } Spreading out one parameter per line like this doesn’t add anything to the script and makes […]

under: PowerShell original, 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 } |          ? { $logFile = $_ ; $logFile.LastWriteTime […]

under: PowerShell original, Scripting Games

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

under: PowerShell original, 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 = ‘C:\Application\Log’,         [Parameter(Mandatory=$false,                ValueFromPipeline=$False,                Position=1)]     [ValidateScript({Test-Path $_ })]     [String]$ArchivePath = ‘\\NASServer\Archives’,         […]

under: PowerShell original, Scripting Games

I don’t have the numbers to back this up but my feeling is that the Scripting Community is marking the entries for this years Games in a harsher manner than the judges did over the last few games. What will be very interesting is the level, type and usefulness of the comments that come through. […]

under: PowerShell original, Scripting Games

At the moment it isn’t necessary to run your script to give a vote. Probably the quickest way to lose points is have an obvious and glaring error in your script such as   . . . | where {$_.LastWriteTime –lt (date).ADDdays(-90)} | . . . or . . . | where {$_.LastWriteTime –lt (get-date).ADDseconds(-90)} […]

under: PowerShell original, Scripting Games

« Newer Posts - Older Posts »

Categories