New
#11
Hello @das10,
NO
problems, now changed, thanks for the follow up.
I have been mucking around for hours trying to find out how toMaximize
theOut-GridView
Window. The best option appeared to be something likeSet-WindowState -Maximized
, bit I canNOT
get it to work.
I have also tried numerous other options.
I then came across this which said it canNOT
be done . . .
> Out-GridView in PowerShell: How to Change the Initial Size of the Window?
Is it possible orNOT
please before I spend any more time on it.
Thanks.
I too can't find any options re the GridView Window. But, if for eg. say give the GridView Window the title say "
"Get DesktopShortcuts", then by using the Sendkeys method I can maximize the GridView within a second.
My script, which gets the targets for my own "Desktop" ("$env:USERPROFILE\Desktop\*")
Not very straightforward, but hope it works for you, as testing from within Powershell_ISE works, but now testing on the Powershell consol (seems to be working).Code:Function Get-DesktopShortcuts{ $Shortcuts = Get-ChildItem -Recurse "$env:USERPROFILE\Desktop\*" -Include *.lnk -force $Shell = New-Object -ComObject WScript.Shell ForEach ($Shortcut in $Shortcuts) { $Properties = @{ ShortcutName = $Shortcut.Name; ShortcutFull = $Shortcut.FullName; ShortcutPath = $shortcut.DirectoryName; Target = $Shell.CreateShortcut($Shortcut).TargetPath + " " + $Shell.CreateShortcut($Shortcut).Arguments } New-Object PSObject -Property $Properties } [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null } $Output = Get-DesktopShortcuts $Output | Out-GridView -Title "Get DesktopShortcuts" Start-Sleep -M 500 # Start-Process -FilePath $Exe -WorkingDirectory $Path $wsh = New-Object -ComObject Wscript.Shell $wsh.AppActivate("Get DesktopShortcuts") Start-Sleep -M 250 $wsh.SendKeys("% ") Start-Sleep -M 250 $wsh.Sendkeys('x') pause
Last edited by das10; 15 Sep 2021 at 11:41. Reason: Correction; pause to prevent closing GridView
Hello @das10,
Yes, that worked thank you very much. I will put that bit of code in my newly created PS Vault.
In the end I have decided on the following [ one combinedArguments
and one separateArguments
] as it also closes theCMD
Window when I close theOut-GridView
Window . . .
Code:Function Get-DesktopShortcuts{ $Shortcuts = Get-ChildItem -Recurse $Env:SystemDrive\System-Admin_ToolBar -Include *.lnk $Shell = New-Object -ComObject WScript.Shell ForEach ($Shortcut in $Shortcuts) { $Properties = @{ ShortcutName = $Shortcut.Name; ShortcutFull = $Shortcut.FullName; ShortcutPath = $shortcut.DirectoryName; Target = $Shell.CreateShortcut($Shortcut).TargetPath + " " + $Shell.CreateShortcut($Shortcut).Arguments } New-Object PSObject -Property $Properties } [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null } $Output = Get-DesktopShortcuts $Output | Out-GridView -Title "System-Admin Toolbar Shortcuts - Combined Target & Arguments" -PassThru $Output | Export-CSV $Env:UserProfile\Desktop\'Sys Admin TB Shortcuts Combined.ods'
Code:Function Get-DesktopShortcuts{ $Shortcuts = Get-ChildItem -Recurse $Env:SystemDrive\System-Admin_ToolBar -Include *.lnk $Shell = New-Object -ComObject WScript.Shell ForEach ($Shortcut in $Shortcuts) { $Properties = @{ ShortcutName = $Shortcut.Name; ShortcutFull = $Shortcut.FullName; ShortcutPath = $shortcut.DirectoryName; Target = $Shell.CreateShortcut($Shortcut).TargetPath; Arguments = $Shell.CreateShortcut($Shortcut).Arguments; } New-Object PSObject -Property $Properties } [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null } $Output = Get-DesktopShortcuts $Output | Out-GridView -Title "System-Admin Toolbar Shortcuts - Separate Target & Arguments" -PassThru $Output | Export-CSV $Env:UserProfile\Desktop\'Sys Admin TB Shortcuts Separate.ods'
Over the weekend I will carry on trying to get theArguments
column AFTER theTargetPath
column in theOut-GridView
in the SECOND file.
When you have time you could test by changing line no 13 in the second ps1
from:
to:Code:New-Object PSObject -Property $Properties
to get the Order of display ?Code:New-Object PSObject -Property $Properties | Select ShortcutName,ShortcutFull,ShortcutPath,Target,Arguments
Paul:
In a quest to try and autosize cells and maximize the Gridview Window and a few spare hours to boot, I ran into another alternative, based on a custom dialog box 'gridview' function for you to play with.
Made GridView to close with a single F4 key (around line 76) or Escape key if wanted (around line 84) or Alt+F4. So, if there is no pause command in the batch file, closing the GridView also closes the Command Box. The font/font-size can also be changed if desired.
Hopefully, you may be able to debug any issues.
Code:# main Code based on: # https://social.technet.microsoft.com/Forums/windowsserver/en-US/edf7c616-a201-4076-8025-b9ef02bcbd0e/wrap-text-in-grid-column-of-outgridview?forum=winserverpowershell # Function out-datagridView # # shows piplineinput in a GUI using a datagridView # and returns the given field on double-Click or Enter # original source maybe MS devblogs -scripting # /\/\o\/\/ 2006 # http://ThePowerShellGuy.com # Load the System.Windows.Forms assembly into PowerShell - line needed to run in consol as well Add-Type -AssemblyName System.Windows.Forms # Create a new Form object and assign to the variable $Form $Form = New-Object System.Windows.Forms.Form #Initialize Form so it can be seen # $Form.showDialog() Function out-datagridView ([String]$ReturnField) { # Make DataTable from Input $dats = new-object Data.datatable $First = $true foreach ($item in $input){ $DatsRow = $Dats.NewRow() $Item.PsObject.get_properties() | foreach { If ($first) { $Col = new-object Data.DataColumn $Col.ColumnName = $_.Name.ToString() $Dats.Columns.Add($Col) } if ($_.value -eq $null) { $DatsRow.Item($_.Name) = "[empty]" } ElseIf ($_.IsArray) { $DatsRow.Item($_.Name) =[string]::Join($_.value ,";") } Else { $DatsRow.Item($_.Name) = $_.value } } $Dats.Rows.Add($DatsRow) $First = $false } # show Datatable in Form $form = new-object Windows.Forms.form $form.WindowState = 'Maximized' # change font size and style $Font = New-Object System.Drawing.Font("Segoe UI",11,[System.Drawing.FontStyle]::Regular) $Form.Font = $Font # to show full screen use # $form.FormBorderStyle = 'None' $DatsGrid = new-object windows.forms.DataGridView $DatsGrid.DataSource = $Dats.psObject.baseobject $DatsGrid.Dock = [System.Windows.Forms.DockStyle]::Fill $DatsGrid.RowHeadersWidthSizeMode = [System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode]::EnableResizing # Enable wrap mode on the cells and make the grid autosize the rows when the columns wrap # \/\/\/ $DatsGrid.defaultCellStyle.wrapMode= [System.Windows.Forms.DataGridViewTriState]::FALSE $DatsGrid.AutoSizeRowsMode = [System.Windows.Forms.DataGridViewAutoSizeRowsMode]::AllCells $DatsGrid.SelectionMode = 'FullRowSelect' <# $DatsGrid.add_DoubleClick({ $script:ret = $this.SelectedRows |% {$_.DataboundItem["$ReturnField"]} $form.Close() }) #> $form.text = "Powershell - Get Extra Details About Shortcuts ( On The Desktop In This Instance )" $form.KeyPreview = $true $form.Add_KeyDown({ if ($_.KeyCode -eq 'F4') { $form.Close() } # so escape key closes gridview ElseIf ($_.KeyCode -eq 'Escape'){ $form.Close() } }) $form.Controls.Add($DatsGrid) $Form.Add_Shown({$form.Activate();$DatsGrid.AutoResizeColumns()}) $script:ret = $null [void]$form.showdialog() $script:ret } # Your section of code begins here Function Get-DesktopShortcuts{ $Shortcuts = Get-ChildItem -Recurse -Force "$env:PUBLIC\Desktop\*" , "$env:USERPROFILE\Desktop\*" -Include '*.lnk' $Shell = New-Object -ComObject WScript.Shell ForEach ($Shortcut in $Shortcuts) { $Properties = @{ ShortcutName = $Shortcut.Name ShortcutFullPathName = $Shortcut.FullName ShortcutPath = $Shortcut.DirectoryName Target = $Shell.CreateShortcut($Shortcut).TargetPath Arguments = $Shell.CreateShortcut($Shortcut).Arguments Description = $Shell.CreateShortcut($Shortcut).Description Hotkey = $Shell.CreateShortcut($Shortcut).Hotkey WindowStyle = $Shell.CreateShortcut($Shortcut).WindowStyle IconLocation = $Shell.CreateShortcut($Shortcut).IconLocation WorkingDirectory = $Shell.CreateShortcut($Shortcut).WorkingDirectory } # New-Object PSObject -Property $Properties | Select ShortcutName,ShortcutFull,ShortcutPath,Target,Arguments,Description New-Object PSObject -Property $Properties | Select ShortcutPath,ShortcutName,ShortcutFullPathName,Target,Arguments,Description,WorkingDirectory,Hotkey,WindowStyle,IconLocation } [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null } $Output = Get-DesktopShortcuts # To export to CSV file use line below ; & get rid of first line in csv #TYPE Selected.System.Management.Automation.PSCustomObject \/\/\/\/\/\/\/\/ # $Output | Export-CSV $Env:UserProfile\Desktop\'Sys Admin TB Shortcuts Separate.csv' -NoTypeInformation # To use PS's own Out-GridView use the "two lines" below # $Output | Out-GridView -Title "Powershell - Get Extra Details About Shortcuts ( On The Desktop In This Instance )" # pause # To use Custom Grid-View ( using function out-datagridView ) instead of PS's own Out-GridView use the line below $Output | out-datagridView
Last edited by das10; 01 Oct 2021 at 03:51.
Can it also be a batch | VB Script hybrid instead of powershell?
Hello @ricardobohner,
Yes, there isNO
reason whyNOT
. That would make a nice selection of options.
I am hoping to do some more work on this very soon.