
from The Universal Machine http://universal-machine.blogspot.com/

Put the internet to work for you.
|
Recommended for you |
Put the internet to work for you.
Turn off or edit this Recipe
|
Recommended for you |
Put the internet to work for you.
Turn off or edit this Recipe
|
Recommended for you |
![]() |
Can I reference the switch name from within its block?The script relies on a set of date ranges defined in a hashtable.
# Store volumenames (key) and dateranges (values -as [Array])
$volumedateranges = @{
Vol1 = @([DateTime] 2001-01-01, [DateTime] 2001-12-31);
Vol2 = @([DateTime] 2002-01-01, [DateTime] 2002-12-31);
}
When the script runs I dynamically reference a hashtable member by searching through the hashtable to get its key (or name depending on what you call it). Once I have this value I pass to a Where clause (highlighted in the red below).
# Get logical disks
Get-WmiObject -Class Win32_LogicalDisk | % {
switch($_.VolumeName)
{
Vol1
{
# Set dates
$startdate = ($volumedateranges.GetEnumerator() | Where {$_.key -match $_.VolumeName}).Value[0]
$enddate = ($volumedateranges.GetEnumerator() | Where {$_.key -match $_.VolumeName}).Value[1]
# Get directories from switched drive
Get-ChildItem -Path "$($_.DeviceID)*Data*" | `
Where {($_.PSIsContainer) -and (Get-FolderDate $_.fullname -lt $startdate) -and (Get-FolderDate -gt $enddate)} | `
Select $_.fullname
}
Vol2
{
# Set dates
$startdate = ($volumedateranges.GetEnumerator() | Where {$_.key -match $_.VolumeName}).Value[0]
$enddate = ($volumedateranges.GetEnumerator() | Where {$_.key -match $_.VolumeName}).Value[1]
# Get directories from switched drive
Get-ChildItem -Path "$($_.DeviceID)*Data*" | `
Where {($_.PSIsContainer) -and (Get-FolderDate $_.fullname -lt $startdate) -and (Get-FolderDate -gt $enddate)} | `
Select $_.fullname
}
}
}
mjolinor pointed out I can bypass the enumeration and use the key (name) directly within my hashtable reference with this syntax:$startdate = $volumedateranges[$_.VolumeName][0]
$enddate = $volumedateranges[$_.VolumeName][1]
Why enumerate when I can just call directly. Much less work, more direct, and, cleaner for sure. Thanks again hammer man.will output this:$a=1;Get-Command-CommandType cmdlet|ForEach-Object{"$($a): $($_.name)"; $a++}
1:Add-BitsFile2:Add-Computer3:Add-Content4:Add-History5:Add-JobTrigger6:Add-Member7:Add-PSSnapin8:Add-RoleMember9:Add-SqlAvailabilityDatabase10:Add-SqlAvailabilityGroupListenerStaticIp11:Add-Type12:Backup-ASDatabase13:Backup-SqlDatabase14:Checkpoint-Computer15:Clear-Content16:Clear-EventLog17:Clear-History18:Clear-Item19:Clear-ItemProperty20:Clear-Variable21:Compare-Object22:Complete-BitsTransfer23:Complete-Transaction24:Connect-PSSession25:Connect-WSMan26:ConvertFrom-Csv27:ConvertFrom-Json28:ConvertFrom-SecureString29:ConvertFrom-StringData30:Convert-Path31:ConvertTo-Csv32:ConvertTo-Html33:ConvertTo-Json34:ConvertTo-SecureString35:ConvertTo-Xml36:Convert-UrnToPath37:Copy-Item38:Copy-ItemProperty39:Debug-Process40:Decode-SqlName41:Disable-ComputerRestore42:Disable-JobTrigger43:Disable-PSBreakpoint44:Disable-PSRemoting45:Disable-PSSessionConfiguration46:Disable-ScheduledJob47:Disable-SqlAlwaysOn48:Disable-WSManCredSSP49:Disconnect-PSSession50:Disconnect-WSMan51:Enable-ComputerRestore52:Enable-JobTrigger53:Enable-PSBreakpoint54:Enable-PSRemoting55:Enable-PSSessionConfiguration56:Enable-ScheduledJob57:Enable-SqlAlwaysOn58:Enable-WSManCredSSP59:Encode-SqlName60:Enter-PSSession61:Exit-PSSession62:Export-Alias63:Export-Clixml64:Export-Console65:Export-Counter66:Export-Csv67:Export-FormatData68: Read More..
Company | Drivers page |
APS Tech | APS Tech hard drive drivers |
Conner | Conner hard drive drivers |
Fujitsu | Fujitsu hard drive drivers |
Hitachi | Hitachi hard drive drivers |
IBM | IBM hard drive drivers |
Maxtor | Maxtor hard drive drivers |
Quantum | Quantum hard drive drivers |
Seagate | Seagate hard drive drivers |
Western Digital | Western Digital hard drive drivers |
![]() |
Writing Hello in Chinese, German, and Tamil. |
![]() |
Automatically captioned: Two pizzas sitting on top of a stove top oven |
![]() |
The model combines a vision CNN with a language-generating RNN so it can take in an image and generate a fitting natural-language caption. |
![]() |
A selection of evaluation results, grouped by human rating. |