I often need to create file names that include the date & time the file was created in the name. I"™ve come up with all sorts of ways to do but this I think is the simplest.
I want the date in this format: year-month-day-hour-minute-second. In other words a format that is easily sortable. I discovered that if you convert a data to a string there is a formatter that does most of the work for you. That"™s a lower case s.
Our Competitor Guide is now online - you can download it here: 2013 Competitor Guide We’re doing things a bit differently this year. We’ll be engaging the overall PowerShell community for numeric grades - and those doing the grading have an awesome chance to win some great prizes! Our expert Judges will be focused on commentary, making this even more of a learning event. Download the Guide and see what’s in store - the Games are scheduled to start the week of April 22nd. As a note, you should get used to checking our Scripting Games Announcements thread (https://powershell.org/category/announcements/scripting-games/) so that you don’t miss any goodies.
PowerShell provides the Stop-Computer cmdlet for closing down a remote machine. I find this especially useful in my virtual test environment. I"™ll have several machines running but won"™t necessarily have logged onto them. Using Stop-Computer means that I can shut them down cleanly without the hassle of logging onto them.
In modern Windows systems you have to explicitly enable remote WMI access through the Windows firewall. Stop-Computer uses WMI. If the WMI firewall ports aren"™t enabled you can"™t use Stop-Computer. I"™ve taken to use the CIM cmdlets rather than WMI so sometimes don"™t open the WMI firewall ports.
The CIM cmdlets are found in the CIMcmdlets module.
Get-Command -Module CimCmdlets produces this list of names. I"™ve added some information on the tasks they perform
Get-CimAssociatedInstance is for working with WMI associated classes Get-CimClass is for discovering the properties and methods of a WMI class Get-CimInstance is analogous to Get-WmiObject Get-CimSession Invoke-CimMethod is analogous to Invoke-WMIMethod New-CimInstance can be used for creating a new WMI instance in certain circumstances New-CimSession New-CimSessionOption Register-CimIndicationEvent is analogous to Register-WMIEvent Remove-CimInstance is analogous to Remove-WMIObject Remove-CimSession Set-CimInstance is analogous to Set-WMIInstance
An email debate yesterday regarding the use of the CIM cmdlets (new in PowerShell 3) vs the WMI cmdlets made me realise that other people are probably wondering the same thing,
The question is really part of a the semi-philosophical debate about when you should adopt new technology.
In the case of the WMI/CIM cmdlets the resolution is fairly straightforward.
If you are using PowerShell v2 you have to use the WMI cmdlets.