Skip to content

Instantly share code, notes, and snippets.

View marckean's full-sized avatar

Marc Kean marckean

View GitHub Profile
$adminnumbers = @("0402345678", "0401234567")
# Get the latest event of the password change
$who = (Get-EventLog -LogName Application | where {$_.EventID -eq "656"} | select -First 1).Message | Select-String -Pattern 'CN=(.*?),' -AllMatches |
ForEach-Object {$_.Matches} |
ForEach-Object {$_.Groups[1].Value}
$when = (Get-EventLog -LogName Application | where {$_.EventID -eq "656"} | select -First 1).Message | Select-String -Pattern 'Change\sDate\s:\s(.*?)[\n]' -AllMatches |
ForEach-Object {$_.Matches} |
ForEach-Object {$_.Groups[1].Value}
# Google Blogger necessities - Setup your app here https://console.developers.google.com/ along with OAuth credentials
$blogID = "This is the ID of your blog, a series of numbers found on the Blogger site"
$app_key = "This is your client ID from your Google app"
$app_secret = "This is your client secret from your Google app"
$redirect_uri = "https://domain.com" # Can be any HTTPS URL, URL has to be specified when adding the OAuth credentials to your app here https://console.developers.google.com/
# Twitter necessities - http://www.adamtheautomator.com/twitter-module-powershell/
$TwitterApiKey = 'n924hf924f92f0824f'
$TwitterApiSecret = 'ng3op8g39ghn39g4wn8gi3p'
$TwitterAccessToken = 'n938hgv0985jg0398g059jg03g950jg'
$MyService = @()
$EmailFrom = @()
$Subject = @()
$Body = @()
$computer = @()
$computer = gc env:computername
$SMTPServer = "smtp.sendgrid.net"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $false
Add-AzureRmAccount
##########################################################################################
########################## Select Source Subscription ############################
##########################################################################################
#region Select a source & target subscription | @marckean
$subscription = Get-AzureRmSubscription | Out-GridView -Title "Select the Source Azure subscription that you want to use ..." -PassThru
$SourceSubscriptionID = $Subscription.SubscriptionId
$StackAadTenantId="<>.onmicrosoft.com"
#region Source Environment | @marckean
$MigrationOptions = @("Azure Public", "Azure Stack")
cls
Write-Host "`nWhere does the VM exist?" -ForegroundColor Cyan
$SourceEnvironment = ($MigrationOptions | Out-GridView -Title "Where are you migrating from?" -PassThru)
### Log into Azure ARM
Login-AzureRmAccount
### Choose Subscription
$subscription = (Get-AzureRmSubscription | Out-GridView -Title "Select the Azure subscription that you want to use ..." -PassThru).SubscriptionName
Select-AzureRmSubscription -SubscriptionName $subscription
##########################################################################################
########################## Select source Virtual Machine ###########################
##########################################################################################
$OU = 'OU=Test Users,DC=test,DC=local'
$primaryemaildomain = "demo.domain.com"
$secondaryemaildomain = "demo2.domain.com"
$users = Import-Csv C:\users\Administrator\Desktop\New-ADUser.csv
$users | ForEach-Object {
$Name = $_.givenname + " " + $_.surname
$UPN = ($_.GivenName).ToLower().Chars(0) + $_.Surname.ToLower() + "@" + $primaryemaildomain
$SamAccountName = ($_.GivenName).ToLower().Chars(0) + $_.Surname.ToLower()
#$secondaryaddress = ($_.GivenName).ToLower().Chars(0) + $_.Surname.ToLower() + "@" + $secondaryemaildomain
$password = $_.AccountPassword
#region Connect to Remote PowerShell WinRM HTTPS port 5986 with untrusted certificate - single connection
### Variables
$ServerName = "ServerName / or / IP Address"
$adminname = 'UserName'
$adminpassword = 'Password'
$password = ConvertTo-SecureString $adminpassword -AsPlainText -Force
$cred= New-Object System.Management.Automation.PSCredential (".\$adminname", $password)
### Enter session
$SessionOptions = New-PSSessionOption –SkipCACheck –SkipCNCheck –SkipRevocationCheck
Enter-PSSession -ComputerName $ServerName -Port 5986 -UseSSL -Credential $cred -SessionOption $SessionOptions
### Log into Azure using certificate authentication
$AzureADAppID = '49fy7934-dc71-4bdd-8804-h9742fyh93y'
$certThumbprint = (Get-ChildItem Cert:\LocalMachine\My | where {$_.Subject -match 'PowerShell_SP'}).ThumbPrint
$TenantId = '3494h480-6a11-78k0-a439-49hh8f49d0'
Login-AzureRmAccount -ServicePrincipal -TenantId $tenantId -ApplicationId $AzureADAppId -CertificateThumbprint $certThumbprint
$Subscription = (Get-AzureRmSubscription | Out-GridView -Title "Choose a Source & Target Subscription ..." -PassThru)
Select-AzureRmSubscription -SubscriptionId $Subscription.Id
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"SBname": {
"type": "string"
},
"location": {
"type": "array",
"defaultValue": [