Hi Luc,
could you check following when i am running as ps1 i get all three parameters in commnd
like below
![]()
however when i convert it to module and then run i dont get all parmeters option only entity is avaliable from command .
function Get-logs
{
[cmdletbinding()]
param (
[parameter(mandatory = $true,
valuefrompipeline = $true,
valuefrompipelinebypropertyname = $true)]
[string]$vcenter,
[string]$entity,
[string]$targetPath
)
$cred = Get-Credential
connect-viserver -Server $vcenter -Credential $cred | Out-Null
#$targetPath = read-host "please provide path"
# "c:\users\in0079d6\desktop\Technicolor_script\logs"
Try{
$target = Get-Item -Path $targetPath -ErrorAction stop
}
Catch{
$target = New-Item -ItemType Directory -Force -Path $targetPath
}
if((Get-VM -ErrorAction SilentlyContinue).Name -contains $entity){
Write-Host "It's a VM" -ForegroundColor Yellow
$vm = Get-VM -Name $entity
$ds = Get-Datastore -RelatedObject $vm
New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root '\' | Out-Null
#Get-ChildItem -Path DS:\
Set-Location DS:\
cd $vm
#Get-ChildItem vmware.log
Copy-DatastoreItem -Item vmware.log -Destination $targetpath
Remove-PSDrive -Name DS -Confirm:$false
}
elseif(((Get-VMHost).Name | %{$_.Split('.')[0]}) -contains $entity){
Write-Host "It's an ESXi" -ForegroundColor Green
#specify domain starting with "."
$domain=Read-Host "specify domain"
$log_type=Read-Host "specify log type"
$esxi_name = "$($entity).$($domain)"
$esxi_name
$esxi=get-vmhost $esxi_name
$res1=Read-Host "do yu need log bundle""y/n"
if($res1 -eq 'y')
{
Write-Host "generating log bundle" -ForegroundColor DarkCyan
Get-Log -VMHost $esxi -Bundle -DestinationPath $target.FullName
}
elseif($res1 -eq 'n')
{
Write-Host "......."
$allCondition = Read-Host -Prompt "Should all substrings appear (y/n)?"
$strings = @()
do {
$answer = Read-Host -Prompt "Enter a substring (blank to end)"
if($answer){
$strings += $answer
}
} until ($answer -eq '')
if($allCondition -eq 'y'){
$regexStr = ($strings | %{"(?=.*$_)"}) -join ''
$regexStr = ".*$($RegexStr).*"
}
else{
$regexStr = $strings -join '|'
}
Get-Log -VMHost $esxi -key $log_type | Select -ExpandProperty Entries |
where{$_ -match $regexStr} |
#Out-File -FilePath "$($target.FullName)\$($esxi_name)-vmkernellog_match.txt"
out-file -FilePath $targetPath\$esxi_name-vmkernellog_match.txt
}
}
$res2=read-host "do yu need full log file without mataching expresions"
if($res2 -eq 'y')
{
write-host "generating" $log_type "log file"
get-log -VMHost $esxi -Key $log_type | select -ExpandProperty entries|out-file $targetPath\$esxi_name_$log_type.txt
}
Disconnect-VIServer -Server "*" -Force -Confirm:$false
}