CustomModules/AliasCmdlets.psm1
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 |
function Set-MSGraphAlias { [CmdletBinding()] param ( [Parameter()] [ValidateNotNullOrEmpty()] [string]$Module = 'PowershellGraphSDK', [Parameter()] [switch]$PassThru ) $newcmds = Get-Command -Module $Module | ForEach-Object {@{ Name = $_.Name Verb = $_.Verb Noun = $_.Noun NewNoun = $_.Noun }} $rep = [Ordered]@{ ManagedDeviceMobileApp = "MDMA" ManagedAppRegistrations = "MAR" MediaContentRating = "MCR" DeviceCompliancePolicies = "DCP" DeviceCompliancePolicy = "DCP" DeviceAppManagement ="DAM" DeviceManagement = "DM" ManagedDevs = "MgDev" Status = "Stat" Device = "Dev" Configuration = "Cfg" Managed = "Mgd" Management = "Mgt" Compliance = "Cmp" Targeted = "Tgt" Target = "Tgt" Windows = "Win" TermsAndConditions = "TnC" Information = "Info" OperatingSystem = "OS" Object = "Obj" Protections = "Prot" Protection = "Prot" Policies = "Pol" Message = "Msg" Template = "Tpl" Registrations = "Reg" Operations = "Op" Summaries = "Sum" Summary = "Sum" Default = "Def" Reference = "Ref" Security = "Sec" Availability = "Avail" Deployment = "Dep" Categories = "Cat" Mobile = "Mob" Scheduled = "Sched" Actions = "Act" Events = "Evt" Definitions = "Dfn" Software = "SW" Notification = "Notif" Connectors = "Conn" Workbook = "Wbk" } foreach ($c in $newcmds) { $c.newNoun = $c.Noun foreach ($k in $rep.Keys) { if ($c.Noun -match $k) { $c.NewNoun = $c.NewNoun -replace $k, $rep.$k } } } # Set aliases $newcmds | ForEach-Object { $oldName = $_.Name $newName = "$($_.Verb)-$($_.NewNoun)" Set-Alias -Name $newName -Value $oldName -Scope Global if ($PassThru) { $info = [PSCustomObject]@{ Command = $oldName Alias = $newName } Write-Output $info } } } |