Tuesday, January 21, 2020

Creating your OWN SNIPPETS



If you are utilizing ISE and want to add your handy Snippets, here is a template for you to use. Accessing snippets can be done, within ISE by pressing CTRL + J keys. From the selection, available snippets can be reached.


#(-)_.New-Snippet-Text
$SnippetText = @'

 #Place PS code here
  <CODE GOES HERE> 
}
'@

#(-)_.New-Snippet-TParams
$NewSnippetParams = @{
Title       = 'SNIPPET-NAME'
Description = 'SNIPPET-NAME-USAGE'
Text        = $SnippetText
CaretOffset = 33
Author      = 'Author NAME'
}

New-IseSnippet @NewSnippetParams


Some Examples

#(-)_.Foreach-Snippet-V1
$SnippetText = @'

#(-)_.Add Vars
$Path  = 'C:\Temp\List.TXT'
$List  = Get-Content -Path $path -ErrorAction Continue

if(!(Test-Path $Path ))
{
    Write-warning 'Import File cannot be located'
    Write-warning 'Script will stop'
    Start-Sleep -Seconds 5
    break;
}

#(-)_.Start Looping
foreach ($Item in $Items)
{
 Write-host 'Processing:'$Item -f DarkYellow
}

'@

$NewSnippetParams = @{
Title       = 'foreach-Snippet'
Description = 'foreach-Snippet'
Text        = $SnippetText
CaretOffset = 33
Author      = 'Casey.DeDeal'
}

New-IseSnippet @NewSnippetParams





# New-Snippet
$SnippetText = @'

function Function-Get-TimeStamp {
 
  [CmdletBinding()]
  param()  
  return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)   
}


'@

$NewSnippetParams = @{
Title       = 'Get-TimeStamp'
Description = 'Get-TimeStamp Snippet'
Text        = $SnippetText
CaretOffset = 33
Author      = 'Casey DeDeal'
}

New-IseSnippet @NewSnippetParams


Casey, Dedeal
Principal Systems Engineer


Friday, January 10, 2020

Connect-Azure-PowerShell if there is no existing Connection.



By Using MsolService to connect to Azure PowerShell, could be annoying time to time if unable to validate existing connection. The simple function below will just do that. To make below function work, you will need to adjust “$company” variable to ensure it fits into your environment. Rest of the function is pretty easy to understand.



<#   

.NOTES

#=============================================
# Script      : Connect-Azure-PoWerShell.ps1
# Created     : ISE 3.0
# Author(s)   : Casey.Dedeal
# Date        : 01/10/2020 14:39:23
# Org         : ETC Solutions
# File Name   : Connect-Azure-PoWerShell.ps1
# Comments    :
# Assumptions :
#==============================================


SYNOPSIS           : Connect-Azure-PoWerShell.ps1
DESCRIPTION        : O365 Azure PS connect
Acknowledgements   : Open license
Limitations        : None
Known issues       : None
Credits            : Please visit:
                          https://simplepowershell.blogspot.com
                          https://msazure365.blogspot.com

.EXAMPLE

  .\Connect-Azure-PoWerShell.ps1


  MAP:

  -----------
  #(1)_.Check to see if any return for Valid cmdlet
  #(1.1)_.Connected to O365 Azure PowerShell Module
  #(1.2)_.Add Vars Modify $company Var
  #(2)_.Catch Errors

#>


function Connect-Azure-PoWerShell
{
   

# Connect Azure PowerShell with MsolService if ! Connected
Try{

 #(1)_.Check to see if any return for Valid cmdlet
 $session  = Get-MsolDomain -EA SilentlyContinue
 if ($session) {
    #(1.1)_.Connected to O365 Azure PowerShell Module
    Write-Host 'ALREADY Connected: Azure PowerShell' -f Gray -b DarkGreen

   } else {

    #(1.2)_.Add Vars Modify $company Var
     $company   = '@CloudSec365.onmicrosoft.com'
     $adminUser = "$env:USERNAME"
     $UPN =  $adminUser + $company
     Write-Host 'Connecting: Azure PowerShell' -f Gray -b DarkCyan
     $cred  = Get-Credential -Credential $UPN -ErrorAction Stop
     Connect-MsolService -Credential $cred -ErrorAction Stop | Out-Null
          }
}Catch{

 #(2)_.Catch Errors
 Write-Host "ERROR FOUND:$($PSItem.ToString())"

}
}


Casey, Dedeal
Azure Solutions Architect
AWS Certified Cloud Practitioner

https://simplepowershell.blogspot.com
https://cloudsec365.blogspot.com
https://msazure365.blogspot.com
https://twitter.com/Message_Talk


Tuesday, January 7, 2020

Azure Simple Users License Report

Below script will provide simple snapshot of Azure License status for your organization by using MsolService to connect to Azure Directory services. Script is built with few simple functions to gather license information.
Script also have option to review output within Grid view as shown; which is super useful way of sorting and saving output if desired to CSV or excel file.
Let me know if you find it handy.





<#    

.NOTES
#=============================================
# Script      : Get-Azure-License-Status-Report.ps1
# Created     : ISE 3.0 
# Author(s)   : Casey.Dedeal 
# Date        : 01/06/2020 08:53:36 
# Org         : ETC Solutions
# File Name   : Get-Azure-License-Status-Report.ps1
# Comments    : Get-Azure-License-Status-Report.ps1
# Assumptions : Running from administrator Server
#==============================================

SYNOPSIS           : Get-Azure-License-Report-Status.ps1
DESCRIPTION        : Get-Azure-License-Report-Status.ps1
Acknowledgements   : Open license
Limitations        : None
Known issues       : None
Credits            : https://simplepowershell.blogspot.com

.EXAMPLE
  .\Get-Azure-License-Status-Report.ps1

  MAP:
  -----------
  #(1)_.Function-EXO-MSOL-Connect-V1
  #(2)_.Function-Get-TimeStamp
  #(3)_.Adding Options and Displaying results
  (4)_.Run License Status Report
#>


#(1)_.Function-EXO-MSOL-Connect-V1
function Function-CON-AZURE-ADD-V1
{

Try{
$URL   = 'https://outlook.office365.com/powershell-liveid/'
$Luser = $env:USERNAME
$Mail  = '@'
$UPN   = $Luser + $Mail
$UserCredential = Get-Credential $UPN
Connect-MsolService -Credential $UserCredential -ErrorAction Stop

}Catch{
  Write-Warning 'Error has occoured'
  Write-host "Problem FOUND: $($PSItem.ToString())" -f red -b White
}}


#(2)_.Function-Get-TimeStamp
function Function-Get-TimeStamp {
   
  return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
   
}

#(3)_.Function-Get-License-Status-Report
function Function-Get-License-Status-Report
{
$Options =@(

'AccountName',
'AccountSkuID',
'ActiveUnits',
'ConsumedUnits',
'SuspendedUnits',
'WarningUnits'
)

Try{

Function-CON-AZURE-ADD-V1
$status = Get-MsolAccountSku -ErrorAction Stop | Select $Options

Write-host '++++++++++++++++++++++++++++++++++++++++' -f Yellow
write-host 'O365 License status Summary Report'
Write-Host 'Report run:' -NoNewline; Function-Get-TimeStamp
Write-host '++++++++++++++++++++++++++++++++++++++++' -f Yellow
$status | ft -AutoSize
Write-host '++++++++++++++++++++++++++++++++++++++++' -f Cyan
Read-host 'Press <ENTER> to open report in GridView'
$status | Out-GridView

}Catch{
  Write-Warning 'Error has occoured'
  Write-host "Problem FOUND: $($PSItem.ToString())" -f red -b White
}}

#(4)_.Run License Status Report
Function-Get-License-Status-Report 




Casey, Dedeal
Azure Solutions Architect
AWS Certified Cloud Practitioner

https://simplepowershell.blogspot.com
https://cloudsec365.blogspot.com
https://msazure365.blogspot.com
https://twitter.com/Message_Talk

NoSpam@Oz.DeDeal@CloudSec365.onmicrosoft.com
P: 202-656-9206