I want to create a script to create VDIs. Basically it's ready, but now I want to modify it to work with gridviews to make it more usable.
My goal is, that you may get a gridview like this code:
$id = 1
$table = @( @{'ID'=$id ++; 'VM Name'="VM0001"; 'Assigned User'=$null},
@{'ID'=$id ++; 'VM Name'="VM0002"; 'Assigned User'=$null},
@{'ID'=$id ++; 'VM Name'="VM0003"; 'Assigned User'=$null} )
$out = $null
$out = $table.ForEach({[PSCustomObject]$_}) |
Select ID, 'VM Name', 'Assigned User' |
Out-GridView -Title "VM Creator" -OutputMode Single -OutVariable selectedID
if ($selectedID -eq $null -or $out.Count -eq 0) {
Write-Host -BackgroundColor Black -ForegroundColor Red "Error: nothing is choosed"
}
if ($selectedID.'Assigned User' -eq $null) {
Write-Host -BackgroundColor Black -ForegroundColor Green "Debug: Input UserName for Desktop" $selectedID.'VM Name'
$newUser = Read-Host "Input UserName"
}
Now when you select an entry without a assigned User you should be able to add a name into the hashtable.
When I tried this:
$table.Add("123", "VM0004", "Pete")
I got the following error (in German):
Für "Add" und die folgende Argumenteanzahl kann keine Überladung gefunden werden: "3". In Zeile:8 Zeichen:1 + $table.Add("123", "VM0004", "Pete") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest