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 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()
Hello tout le monde,
Voici un petit bout de code PowerShell vous permettant de crypter les mots de passes que vous utilisez dans vos scripts.
read-host -prompt "Enter password to be encrypted in file.pwdt " -assecurestring | convertfrom-securestring | out-file file.pwd $pass = cat file.pwd | convertto-securestring $ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass) $pass_back = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($ptr) write-output "password decrpyted is: $pass_back"
Hello tout le monde,
En tant qu’utilisateur de Microsoft System Center Operations Manager 2007, vous avez déjà certainement été confronté au problème ci-dessous
A computer agent unexpectedly generates heartbeat alerts after you put it into Maintenance mode in System Center Operations Manager 2007
La description détaillée de cela se trouve sur le site de Microsoft : http://support.microsoft.com/kb/942866
En fait, pour mettre un serveur en Maintenance Mode, il faut mettre en réalité trois objets en Maintenance :
Plutot que de faire cela à la main à chaque fois que vous souhaitez mettre un odirnateur completement en Maintenance Mode, voici deux scripts que j’ai écris.
# ============================================================================================== # # Microsoft PowerShell Source File # # NAME: StartMaintenanceMode.ps1 # # AUTHOR: Christopher Keyaert # EMAIL: christopher.keyaert@ucb-group.com # # DATE : 11/19/2008 # VERSION : 1.0 # # COMMENT: This script will start the maintenance mode for the specified computer # # PARAMETERS: rootMS, computerPrincipalName, minutes, comment, reason # # # # ============================================================================================== param($rootMS,$computerPrincipalName,$minutes,$comment,$reason) Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin; Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin; new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin; set-location $rootMS -ErrorVariable errSnapin; $computerClass = get-monitoringclass -name:Microsoft.Windows.Computer $healthServiceClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthService $healthServiceWatcherClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthServiceWatcher $computerCriteria = "PrincipalName='" + $computerPrincipalName + "'" $computer = get-monitoringobject -monitoringclass:$computerClass -criteria:$computerCriteria $healthServices = $computer.GetRelatedMonitoringObjects($healthServiceClass) $healthService = $healthServices[0] $healthServiceCriteria = "HealthServiceName='" + $computerPrincipalName + "'" $healthServiceWatcher = get-monitoringobject -monitoringclass:$healthServiceWatcherClass -criteria:$healthServiceCriteria $startTime = [System.DateTime]::Now $endTime = $startTime.AddMinutes($minutes) "Putting " + $computerPrincipalName + " into maintenance mode" New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$computer -comment:$comment -Reason:$reason "Putting the associated health service into maintenance mode" New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$healthService -comment:$comment -Reason:$reason "Putting the associated health service watcher into maintenance mode" New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$healthServiceWatcher -comment:$comment -Reason:$reason
Le second, pour arrêter le Maintenance Mode
# ============================================================================================== # # Microsoft PowerShell Source File # # NAME: StopMaintenanceMode.ps1 # # AUTHOR: Christopher Keyaert # EMAIL: christopher.keyaert@ucb-group.com # # DATE : 11/19/2008 # VERSION : 1.0 # # COMMENT: This script will stop the maintenance mode for the specified computer # # PARAMETERS: rootMS, computerPrincipalName # # # # ============================================================================================== param($rootMS,$computerPrincipalName) Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin; Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin; new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin; set-location $rootMS -ErrorVariable errSnapin; $computerClass = get-monitoringclass -name:Microsoft.Windows.Computer $healthServiceClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthService $healthServiceWatcherClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthServiceWatcher $computerCriteria = "PrincipalName='" + $computerPrincipalName + "'" $computer = get-monitoringobject -monitoringclass:$computerClass -criteria:$computerCriteria $healthServices = $computer.GetRelatedMonitoringObjects($healthServiceClass) $healthService = $healthServices[0] $healthServiceCriteria = "HealthServiceName='" + $computerPrincipalName + "'" $healthServiceWatcher = get-monitoringobject -monitoringclass:$healthServiceWatcherClass -criteria:$healthServiceCriteria $endTime = [System.DateTime]::Now "Stopping " + $computerPrincipalName + " maintenance mode" Set-MaintenanceWindow -endTime:$endTime -monitoringObject:$computer "Stopping the associated health service maintenance mode" Set-MaintenanceWindow -endTime:$endTime -monitoringObject:$healthService "Stopping the associated health service watcher maintenance mode" Set-MaintenanceWindow -endTime:$endTime -monitoringObject:$healthServiceWatcher
Et voici comment appeller ces deux scripts
Start maintenance mode C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe C:\MaintenanceMode\StartMaintenanceMode.ps1 –rootMS: ‘localhost’ -computerPrincipalName: 'SERVERNAME' -minutes:30 -comment: 'Maintenance Mode' -reason: 'PlannedOther'
Stop maintenance mode C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe C:\MaintenanceMode\StopMaintenanceMode.ps1 –rootMS: ‘localhost’ -computerPrincipalName: 'SERVERNAME'
Voilà, si vous avez des questions, ne pas hésiter à les poser dans les commentaires.