Skip to content

Instantly share code, notes, and snippets.

View PCfromDCSnippets's full-sized avatar

Patrick Curran PCfromDCSnippets

View GitHub Profile
@PCfromDCSnippets
PCfromDCSnippets / Create Storage Context and File Share.ps1
Created April 4, 2017 01:29
Create Storage Context and File Share
#region Create File Share
# Get Storage Key
$key = ($sa | Get-AzureRmStorageAccountKey).Value | Select -First 1
# Create Context
$ctx = New-AzureStorageContext -StorageAccountName $storageAccountName.ToLower() -StorageAccountKey $key
$csa = Set-AzureRmCurrentStorageAccount -Context $ctx
# Create File Share
$ss = Get-AzureRmStorageAccount | Get-AzureStorageShare | Where-Object {$_.Name -eq $fileShareName.ToLower()}
if ($ss.count -gt 0) {
Write-Host("$fileShareName file share already exists...")
@PCfromDCSnippets
PCfromDCSnippets / Store File Share Credentials.ps1
Created April 4, 2017 01:32
Store File Share Credentials
#region Store Credentials
Write-Host "Storing file share credentials..."
$add = "$storageAccountName.file.core.windows.net"
cmdkey /add:$add /user:AZURE\$storageAccountName /pass:$key
#endregion
#region Mount File Share
$root = "\\" + $storageAccountName + ".file.core.windows.net\" + $fileShareName
$psd = Get-PSDrive | Where-Object {$_.DisplayRoot -eq $root}
if ($psd.Count -gt 0) {
Write-Host "File share already exists as drive $psd..."
}
else {
$command = "net use " + $driveLetter + ": " + $root
$sb = [scriptblock]::Create($command)
$sb.Invoke()
#region Create Log In Task
$user = whoami
$sj = Get-ScheduledJob -Name $jobName -ErrorAction SilentlyContinue
if ($sj.count -gt 0) {
Write-Host "$jobName scheduled job already exists..."
}
else {
Write-Host "Creating $jobName scheduled Job..."
$sj = Register-ScheduledJob –Name $jobName `
-ScriptBlock $sb `
@PCfromDCSnippets
PCfromDCSnippets / Create File Share with Key.ps1
Created April 4, 2017 01:51
Create File Share with Key
net use x: \\storagefileshare.file.core.windows.net\file-service-01 /u:storagefileshare OYP63u3CiAD5QmySY+67notmyStorageKeySxQWJ56zK5eHWiPQdhIlGp0n8aIiDaqvkThRrWwZqmefXrgqYRq4ZVvw==
@PCfromDCSnippets
PCfromDCSnippets / get-msol.ps1
Created December 15, 2017 12:38
Get Latest MSOL Module
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false
Install-Module -Name MSOnline -AllowClobber -Confirm:$false
@PCfromDCSnippets
PCfromDCSnippets / Create MSOL User.ps1
Last active December 15, 2017 16:47
Create MSOL User
Param (
[string]$displayName = "SVC-Nework-Gateway-Updater",
[string]$firstName = "Network-Gateway",
[string]$lastName = "Updater-Account",
[string]$upn = "svc_network-updater@yourDomain.onmicrosoft.com",
[string]$password = "MyPassword#12345",
[string]$usageLocation = "US"
)
$oCred = Get-Credential -Message "Enter Admin Credentials for O365..."
@PCfromDCSnippets
PCfromDCSnippets / update RBAC.ps1
Created December 15, 2017 16:59
Add User to Azure Access Control
Param (
[string]$subscriptionName = "mySubscription",
[string]$resourceGroupName = "Networking",
[string]$localGatewayName = "LocalGateway",
[string]$userID = "508bb5e1-898e-user-9a71-47de815db2af"
)
Login-AzureRmAccount -SubscriptionName $subscriptionName
$ID = Get-AzureRmResourceGroup $resourceGroup1 | Get-AzureRmLocalNetworkGateway -Name $localGatewayName | select Id
@PCfromDCSnippets
PCfromDCSnippets / updateAzureLocalNetworkGateway.ps1
Created December 15, 2017 20:20
Update Azure Local Network Gateway IP
Param (
[string]$resourceGroup = "Networking-US-East-2",
[string]$localGatewayName = "LocalGateway-HQ",
[string]$location = "East US 2",
[string]$lgwSubnetPrefix = "192.168.0.0/21"
)
function Get-LocalIP {
$wc = New-Object net.webclient
$localIP = $wc.downloadstring("http://checkip.dyndns.com") -replace "[^\d\.]"
@PCfromDCSnippets
PCfromDCSnippets / updateLogs.ps1
Created December 15, 2017 20:30
Update Log File
function Update-Logs ($content) {
$logPath = 'C:\S2S Logs'
if (-not (Test-Path -Path $logPath)) {New-Item -Path $logPath -ItemType Directory}
$date = Get-Date
$lastMonth = $date.AddMonths(-1)
$fileName = $date.ToString("yyyy-MM-dd") + "- S2S Log.txt"
$filePath = ($logPath + "\" + $fileName)
$exists = Test-Path $filePath
if ($exists) {
$string = (Get-Date).ToShortTimeString().ToString() + " $content"