PowerShell ISE(Integrated Scripting Environment)
Открыть профиль ISE
if (!(test-path $profile)){new-item $profile -type file -force};ise $profile psedit $profile
Создание сниппета
Ctrl+J - вызов меню сниппетов
Путь расположения файла с новым сниппетом "C:\Users\ИМЯ-ПОЛЬЗОВАТЕЛЯ\Documents\WindowsPowerShell\Snippets\MyComments.snippets.ps1xml"
$MySnippet = @{ Title = 'MyComments' Description = 'MyComments' Author = 'Pavel Nagaev' Text = ' <# ************************************* Comments ************************************* #> ' } New-IseSnippet @MySnippet
Настройка меню
Посмотреть список меню
$psise.CurrentPowerShellTab.AddOnsMenu.Submenus
Очистить меню
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear()
Создание Add-ons меню
Знак "_" , это как "&", доступ к пункту меню по букве.
$menuAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('_Process', {Get-Process}, 'Alt+P')
Создание вложенного меню
$menuAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add('_Process', {Get-Process}, 'Alt+P') $parentAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Parent', $null, $null) $parentAdded.SubMenus.Add('_Dir', {dir}, 'Alt+D')
Добавление без вывода на экран
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("ClearHost",{clear-host },"Ctrl+Shift+Z") | Out-Null
Полезные меню
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("ClearHost",{clear-host },"Ctrl+Shift+Z")|Out-Null $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Edit ISE Profile ",{psEdit $PROFILE },"Ctrl+Shift+E")|Out-Null $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Edit Profile ",{psEdit $PROFILE.CurrentUserAllHosts },"Ctrl+Shift+S")|Out-Null function clip-toarray{ $sb = @" (@' $([windows.forms.clipboard]::GetText() -replace '[`n\s*]+$','') '@).split("``n") | where {`$_ -notmatch '^#'} | foreach {`$_.trim()}`n "@ $ise_current_file = $psise.CurrentFile $ise_current_file.Editor.InsertText($sb) } $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("ClipToArray",{clip-toarray}, "Ctrl+Shift+C") |Out-Null $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Generate password ",{ Add-Type -AssemblyName System.Web [System.Web.Security.Membership]::GeneratePassword(30,4) },"Ctrl+Shift+B")|Out-Null $null = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add( "**** Connect to Exchange", { $s = New-PSSession -ConfigurationName Microsoft.Exchange ` -ConnectionUri http://$($env:COMPUTERNAME)/PowerShell/ ` -Authentication Kerberos Import-PSSession $s }, "Control+Alt+Z" ) function Hide-Mailbox{ $sb = @" (@' $([windows.forms.clipboard]::GetText() -replace '[`n\s*]+$','') '@).split("``n") | foreach {`$_.trim()} | %{ Set-Mailbox -id `$_ -HiddenFromAddressListsEnabled `$true} "@ $ise_new_file = $psISE.CurrentPowerShellTab.Files.Add() $ise_new_file.Editor.InsertText($sb) $ise_new_file.Editor.SetCaretPosition(2,1) } $null = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("**** HideMailbox",{Hide-Mailbox},"Ctrl+Shift+M")