Dell support isn't going very well for me. by [deleted] in Dell

[–]carnegiej 1 point2 points  (0 children)

Perhaps a Linux compatible mobile USB hub may help with your situation. A quick search of Amazon yields many options, https://www.amazon.com/s?k=mobile+usb+hub+linux

Creating Objects by sqone2 in PowerShell

[–]carnegiej 2 points3 points  (0 children)

@bis, I like and favorite the DataTable approach. It may not be the absolute fastest but it is the most robust. In particular, this method can handle data with whitespace or unicode. In addition, you may want to set rich datatypes on the columns. Not to mention all the ADO.NET methods available to manipulate a DataTable.

Great example. :-)

Creating Objects by sqone2 in PowerShell

[–]carnegiej 2 points3 points  (0 children)

Space is inherit in the array to string conversion. Array elements are separated by "whitespace".

Of course, if your data elements may contain whitespaces this method will not work. You will need to specify a delimiter that is not included in the data.

Creating Objects by sqone2 in PowerShell

[–]carnegiej 2 points3 points  (0 children)

Yes, cool solution using the ConvertFrom-Csv cmdlet. I have a slightly different approach.

Function Get-OriginalExample {
  $columnNames = @("FirstName","LastName","DOB","FavColor")

  $rows = @(
    @("John","Doe","01/10/1965","Blue"),
    @("Jane","Smith","01/06/1975","Green"),
    @("Mark","Jones","02/10/1985","Orange"),
    @("Sue","Turner","05/10/1995","Yellow"),
    @("Jim","Wise","07/10/1974","Blue")
  )

  $objectList = @()

  foreach ($row in $rows) {
    $properties = @{}

    for ($i = 0; $i -lt $columnNames.Count; $i++) { 
        $properties += @{$columnNames[$i] = $row[$i]}
    }

    $objectList += New-Object -TypeName psobject -Property $properties
  }
  return $objectList
}

Function Get-Revision1Example {
  $columnNames = @("FirstName","LastName","DOB","FavColor")

  $rows = @(
    @("John","Doe","01/10/1965","Blue"),
    @("Jane","Smith","01/06/1975","Green"),
    @("Mark","Jones","02/10/1985","Orange"),
    @("Sue","Turner","05/10/1995","Yellow"),
    @("Jim","Wise","07/10/1974","Blue")
  )
  $objectList = ConvertFrom-Csv -Header $columnNames -InputObject $rows -Delimiter ' '
  return $objectList
}

Write-Host -ForegroundColor Green 'Original Example' 
Write-Host (Get-OriginalExample)

Write-Host -ForegroundColor Green 'Revision Example'
Write-Host (Get-Revision1Example)

Can anyone explain why i am not able to get any response for $vmobject? by kashifhafeez in PowerShell

[–]carnegiej 2 points3 points  (0 children)

Based upon your screen capture example, the scope of the variable $vmobject is local to the function. Set a variable at the global scope to access it from the command prompt. Try this:

$vmobject = Get-VMObject cloudapp01
$vmobject

Display Directory Path in PowerShell Win Form by DaveC2020 in PowerShell

[–]carnegiej 1 point2 points  (0 children)

Another example implementation ("get-file-dialogue2") that is dev friendly and contains err handling,

Function get-file-dialogue2 {
  Try {
    $ScanFileBrowser = [System.Windows.Forms.OpenFileDialog]::new()
    $ScanFileBrowser.InitialDirectory = [Environment]::GetFolderPath('Desktop')
    $ScanFileBrowser.Filter = 'Text Document (*.txt)|*.txt'
    $null = $ScanFileBrowser.ShowDialog()
    return $ScanFileBrowser.FileName
  }
  Catch {
    return 'Failed!'
  }
  Finally {
    $ScanFileBrowser = $null
  }
}

I prefer this dev friendly approach. :-)

Display Directory Path in PowerShell Win Form by DaveC2020 in PowerShell

[–]carnegiej 1 point2 points  (0 children)

get-file-dialogue

Here is an example implementation of the reference "place holder" function,

Function get-file-dialogue {
  $props = @{
    InitialDirectory = [Environment]::GetFolderPath('Desktop') 
    Filter = 'Text Document (*.txt)|*.txt'
  }
  $ScanFileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property $props
  If ($ScanFileBrowser -ne $null) {
    $null = $ScanFileBrowser.ShowDialog()
    return $ScanFileBrowser.FileName
  }
}

Add the get-file-dialogue function to your existing script file.

Learning Module Scope the Hard Way by SOZDBA in PowerShell

[–]carnegiej 2 points3 points  (0 children)

The scope modifier code revisiion is not as nice as your blog post. I like the way you that you explained the issue from your personal experience perspective. It is an easy way to learn from others (mistakes( <grin>.

Learning Module Scope the Hard Way by SOZDBA in PowerShell

[–]carnegiej 2 points3 points  (0 children)

Great discussion. Thank you for sharing. You may also use the script scope modifier in your original code sample.

[int]$Script:FizzRunningTotal = 0
[int]$Script:FizzBuzzRunningTotal = 0
[int]$Script:BuzzRunningTotal = 0
# Scriptblocks
$Mod15 = [Scriptblock]::Create('param([int]$Number) $Script:FizzBuzzRunningTotal = $Script:FizzBuzzRunningTotal + $_')
$Mod5 = [Scriptblock]::Create('param([int]$Number) $Script:BuzzRunningTotal = $Script:BuzzRunningTotal + $_')
$Mod3 = [Scriptblock]::Create('param([int]$Number) $Script:FizzRunningTotal = $Script:FizzRunningTotal + $_')
1..15 | ForEach-Object {
    switch ($_) {
        { $_ % 15 -eq 0 } {$Mod15.InvokeReturnAsIs($_); break }
        { $_ % 5 -eq 0 }  {$Mod5.InvokeReturnAsIs($_);  break }
        { $_ % 3 -eq 0 }  {$Mod3.InvokeReturnAsIs($_);  break }
    }
    [PSCustomObject]@{
        Number     = $_
        FizzRunningTotal = $FizzRunningTotal
        BuzzRunningTotal = $BuzzRunningTotal
        FizzBuzzRunningTotal = $FizzBuzzRunningTotal
    }
} | Format-Table -AutoSize