Hi guys,
i need a script that get the date format from 5 virtual machines, the script output should be in html format for the vcops.
thanks,
Itay
Something like this should do the trick.
$vmNames = "VM1","VM2","VM3","VM4","VM5"
$username = "Administrator"
$pswd = "MyPassword"
$script = '(Get-Culture).DateTimeFormat.ShortDatePattern'
$pswdSecure = ConvertTo-SecureString -String $pswd -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$pswdSecure
Get-VM -Name $vmNames | %{
New-Object PSObject -Property @{
VM = $_.Name
DateFormat = (Invoke-VMScript -VM $_ -ScriptText $script -GuestCredential $cred).ScriptOutput.TrimEnd("`n")
}
} |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure I get the question.
Do you want to know the locale settings in the guest OS that runs in 5 VMs ?
Are these VM running a Windows guest OS ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc, i need that the format will be always dd/mm/yy, the script will be a monitor for me that the format not changed to mm/dd/yy
all the VM's are windows.
You can launch the following via Invoke-VMScript in the guest OS of the VMs.
It will show the default setting.
$culture = Get-Culture
$culture.DateTimeFormat.ShortDatePattern
Is that what you are looking for ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks but how i need to run this on the vm in the powercli, let's say that the vm name is vmum
You can do something like this
$vmName = "vmum"
$username = "Administrator"
$pswd = "MyPassword"
$script = 'Get-Culture | Select Name,@{N="DateFormat";E={$_.DateTimeFormat.ShortDatePattern}}'
$pswdSecure = ConvertTo-SecureString -String $pswd -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$pswdSecure
$vm = Get-VM -Name $vmName
Invoke-VMScript -VM $vm -ScriptText $script -GuestCredential $cred
If your account has no authority in the guest OS, you have to pass the credentials.
Otherwise you can skip that parameter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
great Luc it's work!
now how i run the script on 5 different VM's?
i need the output will be in txt ot html and will be server name and date format
Something like this should do the trick.
$vmNames = "VM1","VM2","VM3","VM4","VM5"
$username = "Administrator"
$pswd = "MyPassword"
$script = '(Get-Culture).DateTimeFormat.ShortDatePattern'
$pswdSecure = ConvertTo-SecureString -String $pswd -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$pswdSecure
Get-VM -Name $vmNames | %{
New-Object PSObject -Property @{
VM = $_.Name
DateFormat = (Invoke-VMScript -VM $_ -ScriptText $script -GuestCredential $cred).ScriptOutput.TrimEnd("`n")
}
} |
Export-Csv c:\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks a lot Luc!!