Skip to content

Instantly share code, notes, and snippets.

View PCfromDCSnippets's full-sized avatar

Patrick Curran PCfromDCSnippets

View GitHub Profile
@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==
#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 `
#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()
@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
@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 / Create Resource Group and Storage Account.ps1
Last active April 4, 2017 01:26
Create Resource Group and Storage Account
#region Create Resource Group
$rg = Get-AzureRmResourceGroup -Name $resourceGroup -Location $location -ErrorAction SilentlyContinue
if ($rg) {
Write-Host "$resourceGroup resource group already exists..."
}
else {
Write-Host "Creating $resourceGroup Resource Group..."
$rg = New-AzureRmResourceGroup -Name $resourceGroup -Location $location -Force
}
#endregion
@PCfromDCSnippets
PCfromDCSnippets / downloadAllYammerFiles.js.min
Created June 21, 2016 00:50
Download All Yammer Files (min)
javascript:!function(e){function a(e,a){var n=/.+\//,o=e.href&&e.href.replace(n,"")||"",r="https://www.yammer.com/api/v1/uploaded_files/"+o+"/download";return r}function n(e){var a=document.createElement("a");a.download="filename",a.target="_blank",a.href=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),delete a}var o=Array.from(e.querySelectorAll(".page-content .yj-tabular-data-name"));o.map(a).forEach(n)}(document);
@PCfromDCSnippets
PCfromDCSnippets / restoreDatabases_Orig.ps1
Created January 29, 2016 02:23
Restore SQL Databases
$restoreDir = "J:\Backups"
# Get files in backup directory
$files = get-childitem $restoreDir -recurse
foreach ($file in $files)
{
$query = "RESTORE DATABASE [" + $file.basename + "]
FROM DISK = N'" + $restoreDir + $file + "' WITH FILE = 1,
MOVE N'" + $file.basename + "' TO N'" + $dataLocation + $file.basename + ".mdf',
MOVE N'" + $file.basename + "_log' TO N'" + $logLocation + $file.basename + "_log.LDF',
NOUNLOAD,
@PCfromDCSnippets
PCfromDCSnippets / backupDatabases_Orig.ps1
Last active January 29, 2016 02:02
backupDatabases_Orig
$bkdir = "\\SQL2012B\Shared\Temp" # Set Backup Path!
# SSMS needed to be installed to load the SQL Assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | out-null
$s = new-object ("Microsoft.SqlServer.Management.Smo.Server") $instance
# Grabs ALL of the databases
$dbs = $s.Databases
foreach ($db in $dbs)
{
if(($db.Name -ne "tempdb") -and ($db.Name -ne "master") -and ($db.Name -ne "model") -and ($db.Name -ne "msdb"))
@PCfromDCSnippets
PCfromDCSnippets / Wait 10 Seconds and Delete Old File.ps1
Last active January 5, 2016 18:15
Wait 10 Seconds and Delete Old File
#region wait for 10 then Delete Old Files
# wait for 10
for ($i = 10; $i -gt 0; $i--) {
Write-Host("Deleting old files in $i seconds")
Start-Sleep -Seconds 1
}
# delete old files
foreach ($item in $items) {
Remove-Item -Path $item.CurrentLocation -Force
}