Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Windows Powershell | No Comment | 5,149 views | 27/06/2010 21:46
If you use Flashget, sometimes it downloads files with .html extension. You have to trim .html extensions from files but if you download so many files, you need to use script to save your time.
$files = dir
foreach ($file in $files)
{
$new=$file.name.replace(".html","")
ren $file $new
} |
$files = dir
foreach ($file in $files)
{
$new=$file.name.replace(".html","")
ren $file $new
}
Simply, I use basic dos command, ren to rename files. But you can use Rename-Item to make it 100% Powershell :)
Posted in Windows Powershell | 1 Comment | 4,689 views | 17/06/2010 12:32
One of my colleague asked me to make a script to write out server specifications of our new Dell servers using with their Service Tags. Recently, We rented more than 200 Dell servers and that is real mess to know which one has 4 gb ram and which one has SAS raid etc. The quickiest way to know this, using their Service Tags. Because you can see servers hardware from Dell web page with Service Tags. My script simply use service tags to get hardware and parse it for a more readable format.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
| $ServiceTags = Get-Content C:\ServiceTags.txt
$TagsDir = "C:\ServiceTags"
Foreach ($ServiceTag in $ServiceTags)
{
$SystemInfoURL = "http://support.dell.com/support/topics/global.aspx/support/my_systems_info/en/details?c=us&l=en&s=gen&servicetag=" + $ServiceTag + "&~tab=2&~wsf=tabs"
$Webclient = New-Object System.Net.WebClient
$Webpage = $Webclient.DownloadString($SystemInfoURL)
$Webpage > "$TagsDir\$ServiceTag.txt"
$HardDrive = Select-String "$TagsDir\$ServiceTag.txt" -Pattern 'Hard Drive'
$HardDrive = "$HardDrive" -match '<td class="([^"]+)" valign="top">([^"]+)</td><td class="([^"]+)" valign="top"></td><td class="([^"]+)" valign="top">Hard Drive,(.*?),([^"]+)</td>'
$HardDriveModel = $Matches[6]
$HardDriveModel = $HardDriveModel.Replace(" ","")
$HardDriveModel = $HardDriveModel.Replace("</td></tr></table>","")
$HardDriveCount = $Matches[2]
$HardDriveSize = $Matches[5]
$Processor = Select-String "$TagsDir\$ServiceTag.txt" -Pattern 'Processor'
$Processor = "$Processor" -match '<td class="([^"]+)" valign="top">([^"]+)</td><td class="([^"]+)" valign="top"></td><td class="([^"]+)" valign="top">Processor,(.*?),([^"]+)</td>'
$ProcessorModel = $Matches[6]
$ProcessorModel = $ProcessorModel.Replace(" ","")
$ProcessorModel = $ProcessorModel.Replace("</td></tr></table>","")
$ProcessorCount = $Matches[2]
$ProcessorSize = $Matches[5]
$Memory = Select-String "$TagsDir\$ServiceTag.txt" -Pattern 'Memory'
$Memory = "$Memory" -match '<td class="([^"]+)" valign="top">([^"]+)</td><td class="([^"]+)" valign="top"></td><td class="([^"]+)" valign="top">Dual In-line Memory Module,(.*?),([^"]+)</td>'
$MemoryModel = $Matches[6]
$MemoryModel = $MemoryModel.Replace(" ","")
$MemoryModel = $MemoryModel.Replace("</td></tr></table>","")
$MemoryCount = $Matches[2]
$MemorySize = $Matches[5]
$Raid = Select-String "$TagsDir\$ServiceTag.txt" -Pattern 'Assembly'
$Raid = "$Raid" -match '<td class="([^"]+)" valign="top">([^"]+)</td><td class="([^"]+)" valign="top"></td><td class="([^"]+)" valign="top">Assembly,Cable,(.*?),([^"]+)</td>'
$RaidModel = $Matches[5]
$RaidModel = $RaidModel.Replace(" ","")
$RaidModel = $RaidModel.Replace("</td></tr></table>","")
$RaidCount = $Matches[2]
$RaidType = $Matches[6]
Write-Host Service Tag: $ServiceTag -ForegroundColor Red
Write-Host Hard Drive: -ForegroundColor Green
write-host Adet: $HardDriveCount
write-host Kapasite: $HardDriveSize
write-host Model: $HardDriveModel
Write-Host Processor: -ForegroundColor Green
write-host Adet: $ProcessorCount
write-host Kapasite: $ProcessorSize
write-host Model: $ProcessorModel
Write-Host Memory: -ForegroundColor Green
write-host Adet: $MemoryCount
write-host Kapasite: $MemorySize
write-host Model: $MemoryModel
Write-Host Raid: -ForegroundColor Green
write-host Adet: $RaidCount
write-host Tip: $RaidType
write-host Model: $RaidModel
write-host
} |
$ServiceTags = Get-Content C:\ServiceTags.txt
$TagsDir = "C:\ServiceTags"
Foreach ($ServiceTag in $ServiceTags)
{
$SystemInfoURL = "http://support.dell.com/support/topics/global.aspx/support/my_systems_info/en/details?c=us&l=en&s=gen&servicetag=" + $ServiceTag + "&~tab=2&~wsf=tabs"
$Webclient = New-Object System.Net.WebClient
$Webpage = $Webclient.DownloadString($SystemInfoURL)
$Webpage > "$TagsDir\$ServiceTag.txt"
$HardDrive = Select-String "$TagsDir\$ServiceTag.txt" -Pattern 'Hard Drive'
$HardDrive = "$HardDrive" -match '<td class="([^"]+)" valign="top">([^"]+)</td><td class="([^"]+)" valign="top"></td><td class="([^"]+)" valign="top">Hard Drive,(.*?),([^"]+)</td>'
$HardDriveModel = $Matches[6]
$HardDriveModel = $HardDriveModel.Replace(" ","")
$HardDriveModel = $HardDriveModel.Replace("</td></tr></table>","")
$HardDriveCount = $Matches[2]
$HardDriveSize = $Matches[5]
$Processor = Select-String "$TagsDir\$ServiceTag.txt" -Pattern 'Processor'
$Processor = "$Processor" -match '<td class="([^"]+)" valign="top">([^"]+)</td><td class="([^"]+)" valign="top"></td><td class="([^"]+)" valign="top">Processor,(.*?),([^"]+)</td>'
$ProcessorModel = $Matches[6]
$ProcessorModel = $ProcessorModel.Replace(" ","")
$ProcessorModel = $ProcessorModel.Replace("</td></tr></table>","")
$ProcessorCount = $Matches[2]
$ProcessorSize = $Matches[5]
$Memory = Select-String "$TagsDir\$ServiceTag.txt" -Pattern 'Memory'
$Memory = "$Memory" -match '<td class="([^"]+)" valign="top">([^"]+)</td><td class="([^"]+)" valign="top"></td><td class="([^"]+)" valign="top">Dual In-line Memory Module,(.*?),([^"]+)</td>'
$MemoryModel = $Matches[6]
$MemoryModel = $MemoryModel.Replace(" ","")
$MemoryModel = $MemoryModel.Replace("</td></tr></table>","")
$MemoryCount = $Matches[2]
$MemorySize = $Matches[5]
$Raid = Select-String "$TagsDir\$ServiceTag.txt" -Pattern 'Assembly'
$Raid = "$Raid" -match '<td class="([^"]+)" valign="top">([^"]+)</td><td class="([^"]+)" valign="top"></td><td class="([^"]+)" valign="top">Assembly,Cable,(.*?),([^"]+)</td>'
$RaidModel = $Matches[5]
$RaidModel = $RaidModel.Replace(" ","")
$RaidModel = $RaidModel.Replace("</td></tr></table>","")
$RaidCount = $Matches[2]
$RaidType = $Matches[6]
Write-Host Service Tag: $ServiceTag -ForegroundColor Red
Write-Host Hard Drive: -ForegroundColor Green
write-host Adet: $HardDriveCount
write-host Kapasite: $HardDriveSize
write-host Model: $HardDriveModel
Write-Host Processor: -ForegroundColor Green
write-host Adet: $ProcessorCount
write-host Kapasite: $ProcessorSize
write-host Model: $ProcessorModel
Write-Host Memory: -ForegroundColor Green
write-host Adet: $MemoryCount
write-host Kapasite: $MemorySize
write-host Model: $MemoryModel
Write-Host Raid: -ForegroundColor Green
write-host Adet: $RaidCount
write-host Tip: $RaidType
write-host Model: $RaidModel
write-host
}
You can use Add-Content to print them to txt files.
Posted in Hayattan | No Comment | 4,139 views | 02/06/2010 13:42
Bitiyor galiba.. 4 yıllık öğrencilik hayatımın son günlerini yaşıyorum bu aralar. Bitirme tezimi yazdım ve bugün teslim etmek için okula götüreceğim. Güzel bir önsöz yazdım, buradan da yayınlayayım istedim :)
Sayısal görüntü analizi ile ısı transfer etkinliğinin hesaplanmaya çalışıldığı bu tezde, Matlab üzerindeki işlem basamaklarının ayrıntılı bir şekilde gösterilmesi amaçlanmıştır. Bu çalışmalar sırasında bana yardımlarını ve sevgilerini esirgemeyen aileme; çalışmalarım sırasında bana büyük yardımları dokunan sevgili arkadaşlarım Mehmet Salih Yıldırım ve Göktuğ İçöz’e; gerekli döküman ve yazılımlara erişebilmek için bana internet altyapısını kullandıran Radore Hosting firmasına; tez çalışmalarım sırasında gereken anlayışı gösterdikleri ve yardımcı oldukları için başta Kubilay Akyol olmak üzere tüm Radore Hosting çalışanlarına; yardımlarını esirgemeyen Arş. Gör. Cenk Onan’a ve tez danışmanım Yrd. Doç. Dr. Derya B. Tümer Özkan’a teşekkürü bir borç bilirim.
5 final sınavım daha kaldı, onları da çıkartırsam mezun olmam için kalan stajlarımı yapmam gerekiyor :)
|