Thursday, April 7, 2011

Get/ Set informations on multiple HP Onboard Administrator / Virtual Connect - Example with setting password and show all

When you need to get informations (like "SHOW ALL") on more than 400 Onboard Administrator or Virtual Connect, production team is always happy when you can give them an automatic solution.

Before give you main script for that, let's explain some details:
HP Onboard Administrator or Virtual Connect can be connect by SSH using tools like putty (Alternative Download). When you are connect on your OA or VC you can use some command line.

For more information about OA command line go to Onboard Administrator dedicated HP site and specifically to OA download manual on Manual OA site to download HP BladeSystem Onboard Administrator Command Line Interface User Guide(Alternative Download)

For more information about VC command line go to Manual VC site where you could find HP Virtual Connect Manager Command Line Interface (Alternative Download)

To use plink.exe (tool to do putty link), on OA or VC, I give you some examples below

To create a new OA administrator user named admin with password pass

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAadduser.txt

with OAadduser.txt

ADD USER "admin" "pass"
SET USER ACCESS "admin" ADMINISTRATOR
SET USER FULLNAME "admin" "Backup Administrator"
ASSIGN SERVER ALL "admin"
ASSIGN INTERCONNECT ALL "admin"
ASSIGN OA "admin"


To change admin OA user password to newpass

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAchangepassword.txt

with OAchangepassword.txt

SET USER PASSWORD "admin" "newpass"


To delete admin OA user

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAremoveuser.txt

with OAremoveuser.txt

REMOVE USER "admin"


To show all OA informations

plink -ssh -l Administrator -pw password -batch 192.168.1.254 -m OAshowall.txt

with OAremoveuser.txt

SHOW ALL




To create a new VC administrator user named admin with password pass

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCadduser.txt

with VCadduser.txt

add user admin Password=pass Privileges="domain,server,network,storage" FullName="Backup Administrator" Enabled=true


To change admin VC user password to newpass

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCchangepassword.txt

with VCchangepassword.txt

set user admin Password=newpass


To delete admin VC user

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCremoveuser.txt

with VCremoveuser.txt

remove user admin


To show all VC informations

plink -ssh -l Administrator -pw password -batch 192.168.1.250 -m VCshowall.txt

with VCshowall.txt

SHOW ALL



Now the best part: do all these actions on multiple Onboard Administrator or Virtual Connect. If you do not want to do copy/paste for each part, I encourage you to download GetSetHPOAVCInfos.zip file file.

First, you must create putty ssh keys. For this, execute plink_reg.cmd which will create these key then will export registry to plink.reg file
Why create ssh keys before ? That permit to avoid to answer yes to each OA or VC

@Echo OFF
Rem
Rem Generate plink reg
Rem
Rem F.RICHARD
Rem Initial Version: 2010 August
Rem modification 2011 March : add filename parameter
Rem

SET CURDIR=%~d0%~p0
SET FILENAME=%~n0%~x0
If "%1"=="" goto :ERRORNOFILE

cd /d %CURDIR%
set inputfile=%1
If NOT EXIST %inputfile% GOTO :ERRORFILE

SET LOGFILE="%CURDIR%plink_reg.log"

If NOT EXIST plink.exe GOTO :ERRFILEPLINK
echo Begin %date% %time% > %LOGFILE%




For /F "tokens=1,2,3 delims=;" %%i in (%inputfile%) do call :doit %%i %%j %%k


echo End %date% %time% >> %LOGFILE%
regedit /E plink.reg "HKEY_CURRENT_USER\Software\SimonTatham"
goto :EOF




:doit
rem echo %1 %2 %3
IF {%1}=={} GOTO :ERRORLINE
IF {%2}=={} GOTO :ERRORLINE
IF {%3}=={} GOTO :ERRORLINE


Echo Reg plink %1 (%date% %time%)
Echo ----------------------------- >> %LOGFILE% 2>>&1
Echo Reg plink %1 (%date% %time%) >> %LOGFILE% 2>>&1
plink.exe -ssh -l %2 -pw %3 -batch %1 "exit" >> %LOGFILE% 2>>&1
goto :EOF



:ERRORLINE
Echo ERROR next line (something missing)
Echo %1;%2;%3
goto :EOF

:ERRORFILE
Echo ERROR file %inputfile% does not exist in %CURDIR% directory
goto :EOF

:ERRFILEPLINK
Echo ERROR: file plink.exe does not exist in %CURDIR% directory
Echo Execute plink.exe before executing this file
goto :EOF

:ERRORNOFILE
Echo ERROR You must specify a filename containing line with these informations
Echo ip_or_name;login;password
Echo Ex: run
Echo %FILENAME% myOA.txt
Echo with myOAVC.txt containing
Echo 192.168.1.251;Administrator;password
Echo 192.168.1.252;Administrator;password
echo.
goto :EOF



To use script GetSetHPOAVCInfos.cmd, which permit to execute command line on all VC or OA use for example

GetHPOAVCInfos.cmd testOAVC.txt testOAVCcmdline.txt

with file testOAVC.txt containing for example these lines

192.168.1.220;administrator;password
192.168.1.224;administrator;password

and file testOAVCcmdline.txt with these lines

show all


All informations are return in oa_or_vc.log file
If you want to separate each log (ex: oa_or_vc_192.168.1.220.log, oa_or_vc_192.168.1.224.log) add SEPARATELOG like this

GetHPOAVCInfos.cmd testOAVC.txt testOAVCcmdline.txt SEPARATELOG


GetSetHPOAVCInfos.cmd file

@Echo OFF
Rem
Rem Get Information in HP Onboard Administrator or Virtual Connect
Rem
Rem F.RICHARD
Rem August 2010
Rem modification 2011 March : add filename parameter
Rem

SET CURDIR=%~d0%~p0
SET FILENAME=%~n0%~x0
If "%1"=="" goto :ERRORNOFILE
If "%2"=="" goto :ERRORNOFILE
SET SEPARATELOG=NO
If "%3"=="SEPARATELOG" SET SEPARATELOG=YES

cd /d %CURDIR%
set inputfile=%1
If NOT EXIST "%inputfile%" GOTO :ERRORFILE

set actionfile=%2
If NOT EXIST "%actionfile%" GOTO :ERRORFILE2

SET separate=.log
SET LOGFILE=%CURDIR%oa_or_vc

If NOT EXIST plink.exe GOTO :ERRFILEPLINK
echo Begin %date% %time%
echo Begin %date% %time% > "%LOGFILE%%separate%"

If NOT EXIST plink.reg GOTO :ERRFILEPLINKREG
regedit /s plink.reg

For /F "tokens=1,2,3 delims=;" %%i in (%inputfile%) do call :doit %%i %%j %%k

SET separate=.log
echo End %date% %time%
echo End %date% %time% >> "%LOGFILE%%separate%"
goto :EOF





:doit
IF {%1}=={} GOTO :ERRORLINE
IF {%2}=={} GOTO :ERRORLINE
IF {%3}=={} GOTO :ERRORLINE


Echo Use %actionfile% file on %1 (%date% %time%)
If "%SEPARATELOG%"=="YES" SET separate=_%1.log
If "%SEPARATELOG%"=="YES" echo.> "%LOGFILE%%separate%"
plink.exe -ssh -l %2 -pw %3 -batch "%1" -m "%actionfile%" >> "%LOGFILE%%separate%"
cscript //NOLOGO convertunix2dos.vbs "%LOGFILE%%separate%"
goto :EOF


:ERRORLINE
Echo ERROR: next line (something missing)
Echo %1;%2;%3
goto :EOF

:ERRORFILE
Echo ERROR: file %inputfile% does not exist in %CURDIR% directory
goto :EOF

:ERRORFILE2
Echo ERROR: file %actionfile% does not exist in %CURDIR% directory
goto :EOF

:ERRFILEPLINK
Echo ERROR: file plink.exe does not exist in %CURDIR% directory
Echo Execute plink.exe before executing this file
goto :EOF

:ERRFILEPLINKREG
Echo ERROR: file plink.reg does not exist in %CURDIR% directory
Echo Execute plink_reg.cmd before executing this file
goto :EOF

:ERRORNOFILE
Echo ERROR You must specify a filename containing line with these informations
Echo ip_or_name;login;password
Echo Ex: run
Echo %FILENAME% myOA.txt
Echo with myOAVC.txt containing
Echo 192.168.1.251;Administrator;password
Echo 192.168.1.252;Administrator;password
echo.
goto :EOF



For information, this script use convertunix2dos.vbs to convert unix OA or VC return carriage to windows (script found on the net, don't remember where, sorry for the author)

Dim fso, ts, s, arg, fil, fpath, s1
Set fso = CreateObject("Scripting.FileSystemObject")
arg = WScript.arguments.item(0)
Set ts = fso.OpenTextFile(arg, 1, False)
s = ts.ReadAll
ts.Close
Set ts = Nothing

s1 = Replace(s, vbCrLf, vbCr, 1, -1, 0)
s1 = Replace(s1, vbLf, vbCr, 1, -1, 0)
s1 = Replace(s1, vbCr, vbCrLf, 1, -1, 0)

Set ts = fso.CreateTextFile(arg, True)
ts.Write s1
ts.Close
Set ts = Nothing
Set fso = Nothing

Monday, April 4, 2011

The 2011 Scripting Games begin

The 2011 Scripting Games begin

2011 Scripting Games: All Links on One Page

I will try to do my best in Advanced Category. See you April 25th 2011 for final results

Wednesday, March 23, 2011

new version of ExportRegistyToFile.ps1

New version of ExportRegistyToFile with bug correction in multistring format

Friday, March 18, 2011

Get/Set custom field in Vmware - Is your VM replicated example ?

For billing and production information, I need to know if SAN is replicated or not.
I use a powershell script to indicate me if ESX host is replicate or not using Virtual Center Custom Field.

First, I must set a value to all ESX for indicate me if this ESX have replicated LUN

To set "Replication" in all your hosts

$VMHosts = Get-VMHost | Sort Name
$CustomField = "Replication"
Foreach ($VMHost in $VMHosts){
Write-Host ($VMHost).Name
Set-CustomField -Entity $VMHost -name $CustomField -Value "Yes"
}



Now, for some ESX with no replication set Custom Field Replication manually to No

To do that, select your host then in summary tab in annotations click on edit


















Then in "Edit Annotations" window change value of Replication field











Now, if you need to know if your VM is replicated use this powershell code

$ArrVM = Get-VM
foreach ($VM in $arrVM) {
$VMHost = Get-VMHost -VM $VM
$Replication = $True
If ($VMHost.CustomFields["Replication"].ToUpper() -eq "NO") {
$Replication = $False
}
Write-Host $VM.Name "replication:" $Replication
}

Wednesday, March 9, 2011

Calcul des Indemnités Kilométriques

A french post today, only for french people.

Si vous souhaitez calculer vos indemnités kilométriques, voici un fichier excel que j'ai réalisé qui vous permettra de le faire facilement: Calcul_Indemnites_Kilometrique_2010.xls

[MAJ des IK en avril 2011]
Ci-dessous le même fichier avec la MAJ du barème d'indice kilométrique faite par l'administatrion en avril 2011 Calcul_Indemnites_Kilometrique_2010_maj_2011-04.xls

[MAJ des IK en mars 2012]
La circulaire 5 f-5-12 de février 2012 ne change pas les données IK de 2010. J'ai cependant modifié le fichier Calcul_Indemnites_Kilometrique_2011.xls

[MAJ des IK en avril 2017]
Suite à la demande faite en commentaire, j'ai utilisé le Barème du site des Impôts 2017. Voici donc une version modifié Calcul_Indemnites_Kilometrique_2016-2017.xls

Comment utiliser cette feuille excel:
1) Mettre le nom de la société
2) Choisir le type de véhicule (choix liste)
3) Mettre le modèle de véhicule (pour information comptable)
4) Choisir la puissance fiscale (pour le moment pas de liste mettre 3 CV,4 CV,5 CV,6 CV,7 CV,8 CV,9 CV,10 CV,11 CV,12 CV,13 CV,Cyclo_Inf_50,Cyclo_1_2,Cyclo_3_4_5,Cyclo_Sup_5)
5) Indiquer la date de début d'année fiscale
6) Indiquer le nom et prénom de la personne
7) Remplir les cases NB KM pour chaque mois

Tuesday, February 15, 2011

Get / Determine / Check your ESX version, major version or build version

To check your esx version, use in command line:


vmware -v
return for example in a 3.0.1 ESX
VMware ESX Server 3.0.1 build-32039

vmware -v
return for example in a 3.5 ESX
VMware ESX Server 3.5.0 build-238493

vmware -v
return for example in a 4.1 ESX
VMware ESX 4.1.0 build-260247



But If you need to know only version use

vmware -v | awk -F "uild" '{print $1}' | sed -e 's/[A-Za-z ]//g'

return in our 3 examples
3.0.1
3.5.0
4.1.0


In your script you can use this information into a variable

ESX_VERSION=`vmware -v | awk -F "uild" '{print $1}' | sed -e 's/[A-Za-z ]//g'`
echo $ESX_VERSION

return in our 3 examples
3.0.1
3.5.0
4.1.0




To know major version only

vmware -v | awk -F "uild" '{print $1}' | sed -e 's/[A-Za-z ]//g' | cut '-d.' -f1

return in our 3 examples
3
3
4


To know major and minor version only

vmware -v | awk -F "uild" '{print $1}' | sed -e 's/[A-Za-z ]//g' | awk -F "." '{print $1"."$2}'

return in our 3 examples
3.0
3.5
4.1


If you need to know build only

vmware -v | awk -F "uild-" '{print $2}'

return in our 3 examples
32039
238493
260247

Wednesday, February 9, 2011

Powershell to help you to sort, manipulate or consolidate CSV file

To help you to sort, manipulate or consolidate your information, Powershell is a very interesting tool.

First, you need a .csv file with this format (use excel file save as)


col1,col2,col3
c,cc,ccc
a,aa,aaa
b,bb,bbb
c,cc,ccc
b,bb,bbb


For example, to select only one column, just use colum name

Import-Csv .\test.csv | select col2



col2
----
cc
aa
bb
cc
bb


If your .CSV has ";" and not "," as delimiter you can change this by adding -Delimiter switch like that


Import-Csv .\test.csv -Delimiter ";" | select col2

(Warning: This switch does not work on Powershell 1.0)

Moreover, be sure to have a header else you will have a error
Import-Csv : The member "xxxx" is already present
And do not forget # is considered as a remark

Now, if you only need distinct col2 use -unique switch and Sort-object if you need to have only distinct field

Import-Csv .\test.csv | select -unique col2 | Sort-Object col2



col2
----
aa
bb
cc


To display each line with column 3 then column 1 then column 2 you can do like this

$content = import-csv ".\test.csv"
foreach ($line in $content) {
write-host $line.col3 $line.col2 $line.col1
}


result:

ccc c cc
aaa a aa
bbb b bb
ccc c cc
bbb b bb


or like this:

Import-Csv .\test.csv | select col3, col1, col2


result:

col3 col1 col2
---- ---- ----
ccc c cc
aaa a aa
bbb b bb
ccc c cc
bbb b bb


Or like this:

$Content = Get-Content ".\test.csv"
$arrLine = @( )
Foreach ($line in $Content) {
$line =$line.Trim()
If ($line.length -gt 0) {
$arrLine=$line.split(",")
write-host $arrLine[2] $arrLine[0] $arrLine[1]
}
}


result:

col3 col1 col2
ccc c cc
aaa a aa
bbb b bb
ccc c cc
bbb b bb