LeVeilleur.net

Subscribe

Archive for the ‘powershell’

PowerShell : List Cluster’s Resources

mars 30, 2009 By: Christopher Keyaert Category: Windows, powershell No Comments →

Voici un petit script PowerShell permettant de lister toutes les ressources disks des clusters.

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
$logFilePath = "D:\DashBoard\Inventory\source\Cluster\mylog.log"
$listFile = "D:\DashBoard\Inventory\source\Cluster\list.txt"
Start-Transcript -Path $logFilePath -Append >$null
$list = Get-Content $listFile
foreach($srv in $list)
    {
    $SrvName = $srv
    $c = new-object -comobject MSCLuster.Cluster
    $c.open($SrvName)
    #Cluster Name
    Write-Host "Cluster Name : " $c.name "`r"
    #Cluster Nodes
    foreach($node in $c.nodes)
        {
        Write-Host "Cluster Nodes : " $node.name "`r"
        }

    Write-Host "-----"  "`r"
    #Resources Groups

    foreach($resourceG in $c.resourceGroups)
        {
        Write-Host "Resource Group : " $resourceG.name "`r"
        foreach($r in $resourceG.Resources)
            {
            if($r.TypeName -like "*Physical Disk*")
                {Write-Host "Resource Name Disk Name : " $r.name "`r"}
            if($r.TypeName -like "*Network Name*")
                {Write-Host "Resource Name NetWork Name : " $r.name "`r"}
            }
        Write-Host "-----" "`r"
        }

    Write-Host "" "`r"
    Write-Host "***************************" "`r"
    Write-Host "" "`r"
    }

Stop-Transcript

PoshBoard : PowerShell into a DashBoard

février 20, 2009 By: Christopher Keyaert Category: powershell No Comments →

Voici un projet très très prometteur.



PoshBoard 0.4 Techdays 2009 edition from Antoine Habert on Vimeo.

PowerShell : Merge files with a particular extension

février 05, 2009 By: Christopher Keyaert Category: powershell No Comments →

Hello,

Voici une fonction powershell vous permettant de regrouper/merge de tous les fichiers portant une extension particulière.

$source="C:\"
$extenstion ="*.csv"
$outputFile = "MyMergeFile.csv"
$blockTerminator = "ENDOFFILE"

function mergeFile ($source, $extenstion, $outputFile, $blockTerminator)
{

[System.IO.DirectoryInfo]$directoryInfo = New-Object System.IO.DirectoryInfo($source);
$rgFiles = $directoryInfo.GetFiles($extenstion);
$builder = New-Object System.Text.StringBuilder;

foreach ($fileInfo in $rgFiles)
	{
	[System.IO.FileStream]$fReader = $fileInfo.OpenRead();
	if (-not ($fileInfo -eq $null))
		{
		write $fileInfo.Name;
		$reader = New-Object System.IO.StreamReader($fReader);
		$builder.AppendLine($reader.ReadToEnd());
		$builder.AppendLine($blockTerminator);
		}
	}
if (-NOT $source.EndsWith('\'))
	{
 	$source = $source + '\';
	}

$outputFile = $source + $outputFile;
[System.IO.FileStream]$fWriter = New-Object System.IO.FileStream($outputFile, [System.IO.FileMode]::OpenOrCreate);
$writer = New-Object System.IO.StreamWriter($fWriter);
$writer.Write($builder.ToString());
$writer.Flush();
$writer.Close();
}

mergeFile $source $extenstion $outputFile $blockTerminator

PowerShell : Control Excel

février 03, 2009 By: Christopher Keyaert Category: powershell No Comments →

Voici quelques bouts de code pour controler Microsoft Excel à partir de PowerShell

#Creation of the xls Sheet

$a = New-Object -comobject Excel.Application
$a.visible = $True

$MyWorkBook = $a.Workbooks.Add()
$MyWorksheets = $MyWorkBook.Worksheets.Item(1)
$i=1;

$MyWorksheets.Cells.Item(1,$i++) = "Server Name"
$MyWorksheets.Cells.Item(1,$i++) = "Host"
$MyWorksheets.Cells.Item(1,$i++) = "Cluster"

#Excel Sheet Format
$d = $MyWorksheets.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$MyWorksheets.Cells.Item($intRow,$i++) = "OK"
$MyWorksheets.Cells.Item($intRow,$i-1).Interior.ColorIndex = 4

#Save the XLS page in CSV
$FileFormat=[Microsoft.Office.Interop.Excel.xlFileFormat]::xlCsv
if(test-path "$FileLocation\BocadaExport.csv"){Remove-Item "$FileLocation\BocadaExport.csv"}
$MyWorksheets.SaveAs("$FileLocation\BocadaExport.csv",$FileFormat)

#Quit XLS
$excel.displayalerts = $False
$excel.quit()

PowerShell : Control IE

février 03, 2009 By: Christopher Keyaert Category: powershell No Comments →

Voici quelques bouts de code PowerShell permettant le control d’Internet Explorer

#Rune IE
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate('http://mypage.com')

#Authentication on the web page
while($ie.busy) {start-sleep 1}
if ($ie.document.getElementByID("FormUsername") -ne $null)
    {
    $ie.document.getElementByID("FormUsername").value = "myLogin"
    $ie.document.getElementByID("FormPassword").value = "MyPwd"

    #Click on the button for logon
    $forms = @($ie.Document.forms | where {$_.action -match "VerifPwd.htm"})
    $forms[0].submit()
    while($ie.busy) {start-sleep 1}
    }

$ie.navigate('http://mypage.com/page2.html')
while($ie.busy) {start-sleep 1} 

#Exit IE
$ie.quit()