Powershell ISE class
#region
powershell ise came with ps 2.0
windows management frame
#endregion
$PSVersionTable
# File - new poowershell tab --> will create a new tab which completly new session from the cuurent where ur working
32 tabs
$psISE.PowerShellTabs | select displayname
$psISE.PowerShellTabs[1].displayname = 'newname'
$psISE.PowerShellTabs.Remove($psISE.PowerShellTabs[3])
$psISE.CurrentPowerShellTab.DisplayName
$psISE.PowerShellTabs.Add()
$psISE.CurrentPowerShellTab.Files.displayname
Get-ChildItem c:\ | ForEach-Object{
if($_.BaseName -like 'windows')
{
$created = $_.creationtime
Write-Output "the windows folder was created in $($created.toshortdatestring())"
}
}
#region
we can collapse the region
#endregion
$profile
$profile.psextended | fl
$profile.AllUsersAllHosts #every one on the system
#creating new profile
New-Item -ItemType File -Path $profile -Force
Get-Content Function:\psEdit
#editing profile
psEdit $profile
#script in new profile
function prompt {'[localhost]'}
#save it
function new-actiedirectorytab{
$psISE.PowerShellTabs[0].DisplayName = 'localhost' # changing the cuurent working tab to renaming to local host
$new = $psISE.PowerShellTabs.add() # creating new tab
$newtab.displayname = 'activedirectory' #changing the name to activedirecoty
while(-not $newtab.caninvoke)
{
Start-Sleep -Seconds 1
}
$newtab.invoke({Enter-PSSession -ComputerName dc1})
}
powershell_ise.exe -file E:\scriptsinput\example.ps1,E:\scripts\exampl2.ps1
powershell_ise.exe -noprofile
#to run ISe without $profile
Start-Transcript
Get-Service
Stop-Transcript
psEdit $profile
function save_Isescript {
param(
$scriptname,
$Path = 'E:\scriptsoutput'
)
$scriptpath = Join-Path $path "$scriptname.ps1"
$psISE.CurrentFile.SaveAs($scriptpath,[System.Text.Encoding]::UTF8)
}
Set-PSBreakpoint -Script 'E:\scripts\sample.ps1' -Variable var
Set-PSBreakpoint -Script 'E:\scripts\sample.ps1' -Command Get-Service
Get-PSBreakpoint
Get-PSBreakpoint | Remove-PSBreakpoint
#enter s to move to next line while debugginh
#enter 0 to step out of function
Update-Help -Force
#snipptets Ctrl+j
foreach ($item in $collection)
{
}
do
{
}
until ($x -gt 0)
for ($i = 1; $i -lt 99; $i++)
{
}
$psISE.CurrentPowerShellTab.Snippets | select displaytitle, description
New-IseSnippet -Title get-topcpu -Description gettpcpu -Text 'Get-Process | sort cpu' -Force
#ctrl + j
#will get newly created snippet
Get-Process | sort cpu
Get-IseSnippet
Get-IseSnippet | Remove-Item
Show-Command New-IseSnippet
Get-IseSnippet
#for multi line snippter
$code = @'
Get-WmiObject win32_logicaldisk -Filter "Drivetype='3'" | Select-Object @{ n="drive"; e={$_.deviceid}},
@{n="Size";e={[math]::round($_.size/1gb,2)}},
@{n="freespace";e={[math]::round($_.freespace/1gb,2)}}
'@
New-IseSnippet -Title get-diskspace -Description diskspave -Text $code -Force
Get-WmiObject win32_logicaldisk -Filter "Drivetype='3'" | Select-Object @{ n="drive"; e={$_.deviceid}},
@{n="Size";e={[math]::round($_.size/1gb,2)}},
@{n="freespace";e={[math]::round($_.freespace/1gb,2)}}
#autorecovery
every 2 minutes powershell ise saves ise with unsaved data, incase of crash. when u open ise again u will get all the unsaved scripts
#challenge
New-Item -ItemType File -Path $profile -Force
psedit $profile
function new-isetab{
Param(
$tabname
)
$newtab = $psISE.PowerShellTabs.add()
If($tabname)
{
$newtab.displayname = $tabname
}
}
#custom menus # add-ons
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(
"Connect to dc1", #name
{
Enter-PSSession -ComputerName dc1 # code
},
'ctrl+alt+z' # shortcut
)
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(
"Throw running services out",
{
Get-Service | Where-Object {$_.status -eq "running"} | ogv
},
'ctrl+alt+o'
)
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(
"BIOS",
{Get-WmiObject -Class win32_bios},
'ctrl+alt+b'
)
#region
one thing to note is that this is non persistant means if u close the ise u will not get the add-ons menu again so u need to run the code again to get the add-ons
so the
solution is to add it in profile scripts
#endregion
$psISE.Options.Zoom = '100'
$psISE.Options.ShowToolBar = $true
Function Zoom{
Param($value)
$psISE.Options.Zoom = $value
}
psedit $profile
$Parent = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('connect', $null,$null)
$Parent.submenus.add('primary',$null,$null)
$Parent.submenus.add('secondary',$null,$null)
$Parent.submenus.add('thirdpary',$null,$null)
$Parent.submenus.add('SCCM',{Enter-PSSession -ComputerName sccm},$null)
#### or below using brackets instaed of assigning variable and and then adding submenus #####
$Parent = ($psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('connect', $null,$null)).submenus.add('sccm1',{cd sitecode},$null)
#region
one thing to note is that this is non persistant means if u close the ise u will not get the add-ons menu again so u need to run the code again to get the add-ons
so the
solution is to add it in profile scripts
#endregion
psEdit $profile
# third party module which will help you to create exe
Install-Module ISEsteroids -Scope CurrentUser
start-steroids
$text = 'good night'
$rate = '0'
$obj = new-object -comobject Sapi.spvoice
$obj.rate = $rate
$null = $obj.speak($text)
psedit $profile
<# once profile script is edited and opened shell if u see any running script output
use $null variable and assign ur script to this
or pipe it to Out-Null
#>
Function Save-AllIsefiles{
Foreach($tab in $psISE.PowerShellTabs)
{
Foreach($files in $tab.files)
{
if(!$files.isuntitled)
{
$files.save()
}
}
}
}
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("save all",{Save-AllIsefiles},$null) | Out-Null
$psISE.CurrentPowerShellTab.Snippets | select displaytitle
Comments
Post a Comment