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 […]
Archive for May, 2013
Scripting Games–new Get-ChildItem parameters
Posted by: richardsiddaway | May 7, 2013 | No Comment |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) […]
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) […]
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 […]
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 […]
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 […]
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
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’, […]
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. […]
Scripting Games–a word of advice for competitors
Posted by: richardsiddaway | May 1, 2013 | No Comment |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)} […]
Categories
- .NET
- Active Directory
- Architecture
- Azure
- Bash
- BITS
- Books
- CDXML
- CIM
- Cloud
- COM
- Containers
- Deep Dive
- Desired State Configuration
- DevOps
- DHCP
- DNS
- DSC
- European Summit
- Events
- Exchange
- File System
- Firewall
- General
- General IT Matters
- Hyper-V
- IIS
- Infrastructure
- IT Community
- IT Security
- Learning PowerShell
- Linux
- Math
- Microsoft
- Modules
- Nano Server
- Networking
- Office 2010
- Office 2013
- Open Source
- Opinion
- Outlook
- Philosophy
- PowerShell
- PowerShell 7
- PowerShell and .NET
- PowerShell and Active Directory
- PowerShell and CIM
- PowerShell and Exchange 2007
- PowerShell and IIS
- PowerShell and SQL Server
- PowerShell and WMI
- PowerShell Basics
- PowerShell original
- PowerShell Summit
- PowerShell User Group
- PowerShell User Group 2
- PowerShell v2
- PowerShell V3
- PowerShell v4
- PowerShell v5
- PowerShell v6
- PowerShell.org
- PowerShellGet
- PowerShellV2
- PSAM
- Rant
- Registry
- Scripting
- Scripting Games
- Scripting Games 2104
- Security
- SQL Server
- Storage
- Strings
- Summit
- Technology
- Uncategorized
- Virtualization
- Windows 10
- Windows 2012 R2
- Windows 7
- Windows 8
- Windows 8 Server
- Windows 8.1
- Windows Server
- Windows server 1709
- Windows Server 2008
- Windows Server 2008 R2
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016
- Windows Server 2019
- WMFv5
- WPF
- WSUS