Projects/AzOSDPad/azosdpad.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
######################################################################### # Add shared_assemblies # ######################################################################### [Void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework') foreach ($item in $(gci .\assembly\ -Filter *.dll).name) { [Void][System.Reflection.Assembly]::LoadFrom("assembly\$item") } Add-Type -AssemblyName System.Windows.Forms | Out-Null ######################################################################### # Load Main Panel # ######################################################################### $Global:pathPanel= split-path -parent $MyInvocation.MyCommand.Definition function LoadXaml ($filename){ $XamlLoader=(New-Object System.Xml.XmlDocument) $XamlLoader.Load($filename) return $XamlLoader } $XamlMainWindow=LoadXaml("$Global:pathPanel\azosdpad.xaml") $reader = (New-Object System.Xml.XmlNodeReader $XamlMainWindow) $Form = [Windows.Markup.XamlReader]::Load($reader) $XamlMainWindow.SelectNodes("//*[@Name]") | %{ try {Set-Variable -Name "$("WPF_"+$_.Name)" -Value $Form.FindName($_.Name) -ErrorAction Stop} catch{throw} } Function Get-FormVariables{ if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true} write-host "Found the following interactable elements from our form" -ForegroundColor Cyan get-variable *WPF* } #Get-FormVariables ################################################### # Variables # ################################################### function Start-Scan { [CmdletBinding()] [Alias()] Param ( ) begin { $dummyNode = $null #$AllNodes =$Global:AzOSDCloudBlobScript.BlobClient.BlobContainerName |Group-Object $AllNode = Import-Clixml -path $global:pathPanel\work.xml $AllNodes = $AllNode.BlobClient.BlobContainerName |Group-Object } process { # ================== Handle Folders =========================== foreach ($node in $AllNodes) { $treeViewItem = [Windows.Controls.TreeViewItem]::new() $treeViewItem.Header = $node.Name $treeViewItem.Tag = @("folder",$node) $treeViewItem.Items.Add($dummyNode) | Out-Null $treeViewItem.Add_Expanded({ try { $ListBoxControl.ItemsSource = $null $ListBoxControl.Items.Clear() } catch {} Write-Host "2" $_.OriginalSource.Header "JJJ" $Sublevel = $_.OriginalSource.Header [System.Windows.Controls.TreeViewItem]$sender = $args[0] $OU= $($sender.Tag[1].DN) }) $treeViewItem.Add_PreviewMouseRightButtonDown({ $Menu.IsOpen = $true }) $treeViewItem.Add_PreviewMouseLeftButtonDown({ [System.Windows.Controls.TreeViewItem]$sender = $args[0] #$DistinguishedName.Text = $($sender.Tag[1].DN) $Sobjects.Visibility="Visible" #$Object= Get-AzOSDCloudBlobScriptFile Container "$($sender.Tag[1].DN)" if ($null -eq $($Object).Count){ $CObjects.Content = 1 $TempArray = [System.Collections.ArrayList]::new() $TempArray.Add($Object) $ListBoxControl.ItemsSource = $TempArray } else{ $ListBoxControl.ItemsSource = $Object $CObjects.Content = $($Object).Count } }) $WPF_TreeView.Items.Add($treeViewItem) | Out-Null } } end { } } function Get-AzOSDCloudBlobScriptFile { [CmdletBinding()] param ( $Container ) Try { $Objects = Get-AzStorageBlob -Context $Global:AzCurrentStorageContext -Container $Container -Blob *.ps1 -ErrorAction Ignore $Objects += Get-AzStorageBlob -Context $Global:AzCurrentStorageContext -Container $Container -Blob *.ppkg -ErrorAction Ignore $Objects += Get-AzStorageBlob -Context $Global:AzCurrentStorageContext -Container $Container -Blob *.xml -ErrorAction Ignore } catch {} return $Objects } ######################################################################### # Stuff # ######################################################################### Start-Scan $Form.ShowDialog() | Out-Null |