PoshBoard : PowerShell into a DashBoard
Voici un projet très très prometteur.
PoshBoard 0.4 Techdays 2009 edition from Antoine Habert on Vimeo.
Voici un projet très très prometteur.
Voici trois méthodes permettant de sauver une page web ou plus simplement du code html
# Internetexplorer.application
$obj=New-Object -ComObject internetexplorer.application
$obj.visible=$true
$obj.navigate2("http://www.google.com")
while($obj.ReadyState -ne 4){start-sleep -m 100}
$obj.Document.documentElement.outerHTML
# xml http
$url = "http://www.cnn.com"
$xHTTP = new-object -com msxml2.xmlhttp;
$xHTTP.open("GET",$url,$false);
$xHTTP.send();
$xHTTP.ResponseText; # returns the html doc
# net.webclient $url="http://www.cnn.com" $wc = new-object net.webclient $html = $wc.DownloadString($url)
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
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()
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()