Skip to content

Instantly share code, notes, and snippets.

@eosfor
eosfor / getAzureObject.ps1
Created November 2, 2015 19:33
getAzureObject
<#
# Load ADAL Assemblies
$adal = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"
[System.Reflection.Assembly]::LoadFrom($adal)
[System.Reflection.Assembly]::LoadFrom($adalforms)
#>
function Get-AzureObject {
[CmdletBinding()]
PS X:\> Get-Command -Name "*log*" | where source -like "Azure*"
CommandType Name Version Source
----------- ---- ------- ------
Alias Get-WAPackWebsiteLog 1.2.3 Azure
Alias Login-AzureRmAccount 1.0.5 AzureRM.Profile
Alias Save-WAPackWebsiteLog 1.2.3 Azure
Cmdlet Export-ACSLog 0.9.3 AzureRM.AzureStackStorage
Cmdlet Get-AzureRmDataLakeAnalyticsCatalogItem 1.0.5 AzureRM.DataLakeAnalytics
Cmdlet Get-AzureRmLog 1.0.5 AzureRM.Insights
@eosfor
eosfor / funcGraphDirtyTest.ps1
Last active May 11, 2017 10:51
quick and dirty graph of functions
function Find-ASTItem {
param(
[string[]]$FullName,
[ScriptBlock]$FindAll
)
Process {
$Ast = [System.Management.Automation.Language.Parser]::ParseFile( (Resolve-Path $FullName) , [ref]$null, [ref]$null)
foreach($item in $ast.FindAll($FindAll, $true)) {
$f = gc "C:\Temp\pfirewall_public.log"
$regex = '^(?<datetime>\d{4,4}-\d{2,2}-\d{2,2}\s\d{2}:\d{2}:\d{2})\s(?<action>\w+)\s(?<protocol>\w+)\s(?<srcip>\b(?:\d{1,3}\.){3}\d{1,3}\b)\s(?<dstip>\b(?:\d{1,3}\.){3}\d{1,3}\b)\s(?<srcport>\d{1,5})\s(?<dstport>\d{1,5})\s(?<size>\d+|-)\s(?<tcpflags>\d+|-)\s(?<tcpsyn>\d+|-)\s(?<tcpack>\d+|-)\s(?<tcpwin>\d+|-)\s(?<icmptype>\d+|-)\s(?<icmpcode>\d+|-)\s(?<info>\d+|-)\s(?<path>.+)$'
 
$log =
$f | % {
    $_ -match $regex | Out-Null
    if ($Matches) {
    [PSCustomObject]@{
        action   = $Matches.action
@eosfor
eosfor / cosmosDBDocDBTest.ps1
Last active December 12, 2017 15:30
Adding a VM to DocumentDB
using assembly "C:\Users\<username>\AppData\Local\PackageManagement\NuGet\Packages\Microsoft.Azure.DocumentDB.1.19.1\lib\net45\Microsoft.Azure.Documents.Client.dll"
$client = [Microsoft.Azure.Documents.Client.DocumentClient]::new([Uri]("https://localhost:8081"),"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==")
$db = $client.CreateDatabaseIfNotExistsAsync([Microsoft.Azure.Documents.Database]@{ID="azureinventory"})
$docCollection = $client.CreateDocumentCollectionIfNotExistsAsync([Microsoft.Azure.Documents.Client.UriFactory]::CreateDatabaseUri("azureinventory"),
[Microsoft.Azure.Documents.DocumentCollection]@{id="inventory"},
[Microsoft.Azure.Documents.Client.RequestOptions]@{OfferThroughput = 1000})
$docCollectionURI = [Microsoft.Azure.Documents.Client.UriFactory]::CreateCollectionUri("azureinventory", "inventory")
@eosfor
eosfor / azureDocumentDBforVMInventory_hack.ps1
Last active December 12, 2017 16:47
hack to use Azure Cosmos DB as an inventory for Azure VM Objects
using assembly "C:\Users\<user>\AppData\Local\PackageManagement\NuGet\Packages\Microsoft.Azure.DocumentDB.1.19.1\lib\net45\Microsoft.Azure.Documents.Client.dll"
$client = [Microsoft.Azure.Documents.Client.DocumentClient]::new([Uri]("https://localhost:8081"),"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==")
$db = $client.CreateDatabaseIfNotExistsAsync([Microsoft.Azure.Documents.Database]@{ID="azureinventory"})
$docCollection = $client.CreateDocumentCollectionIfNotExistsAsync([Microsoft.Azure.Documents.Client.UriFactory]::CreateDatabaseUri("azureinventory"),
[Microsoft.Azure.Documents.DocumentCollection]@{id="inventory"},
[Microsoft.Azure.Documents.Client.RequestOptions]@{OfferThroughput = 1000})
$docCollectionURI = [Microsoft.Azure.Documents.Client.UriFactory]::CreateCollectionUri("azureinventory", "inventory")
@eosfor
eosfor / winFWAnalizeGist.ps1
Created December 28, 2017 10:40
windows FW parser
#file and regular expression
$f = gc "C:\Temp\pfirewall_public.log"
$regex = '^(?<datetime>\d{4,4}-\d{2,2}-\d{2,2}\s\d{2}:\d{2}:\d{2})\s(?<action>\w+)\s(?<protocol>\w+)\s(?<srcip>\b(?:\d{1,3}\.){3}\d{1,3}\b)\s(?<dstip>\b(?:\d{1,3}\.){3}\d{1,3}\b)\s(?<srcport>\d{1,5})\s(?<dstport>\d{1,5})\s(?<size>\d+|-)\s(?<tcpflags>\d+|-)\s(?<tcpsyn>\d+|-)\s(?<tcpack>\d+|-)\s(?<tcpwin>\d+|-)\s(?<icmptype>\d+|-)\s(?<icmpcode>\d+|-)\s(?<info>\d+|-)\s(?<path>.+)$'
#parsing
$log =
$f | % {
$_ -match $regex | Out-Null
if ($Matches) {
[PSCustomObject]@{
function Find-ASTItem {
param(
[string[]]$FullName,
[ScriptBlock]$FindAll
)
Process {
$Ast = [System.Management.Automation.Language.Parser]::ParseFile( (Resolve-Path $FullName) , [ref]$null, [ref]$null)
foreach($item in $ast.FindAll($FindAll, $true)) {
function Test-Password {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline=$true)]
[string]$Password
)
begin {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}
@eosfor
eosfor / joinVMNicIPConfigInfo.ps1
Created July 23, 2018 09:03
Join Vm info, NIC info and Public IP info
$rgName = "kubetest"
$vms = Get-AzureRmVM -ResourceGroupName $rgName
$nics = Get-AzureRmNetworkInterface -ResourceGroupName $rgName
$pubIPs = Get-AzureRmPublicIpAddress -ResourceGroupName $rgName
$vmNics = @{}
$nics | ForEach-Object {
$index = $_.id
$value = $_
$vmNics[$index] += @($value)