-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e73aaa
commit f7c7c6a
Showing
24 changed files
with
876 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<# | ||
.COPYRIGHT | ||
Copyright (c) Brian A. Randell. All rights reserved. Licensed under the MIT license. | ||
See LICENSE in the project root for license information. | ||
#> | ||
|
||
# CREATE A RESOURCE GROUP | ||
$rgName = 'yournamehere'; | ||
$rgLoc = 'West US 2'; | ||
|
||
New-AzureRmResourceGroup -Name $rgName -Location $rgLoc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<# | ||
.COPYRIGHT | ||
Copyright (c) Brian A. Randell. All rights reserved. Licensed under the MIT license. | ||
See LICENSE in the project root for license information. | ||
#> | ||
|
||
Login-AzureRmAccount; | ||
|
||
## Set Variables | ||
# You must fix all of these variables | ||
$rgName = 'resourceGroupName'; | ||
$rgLoc = 'East US 2'; | ||
$pre = 'abc'; | ||
$vmName = 'vmname'; | ||
$osDiskVhdUri = 'https://account.blob.core.windows.net/folder/vm.vhd'; | ||
$vmDns = "vmdnsname"; | ||
$dnsLoc = 'eastus2'; | ||
$diagStorageAccountName = 'storageAccountName'; | ||
|
||
# Use Test-AzureRmDnsAvailability to check Dns Name | ||
$goodDns = Test-AzureRmDnsAvailability -DomainNameLabel $vmDns -Location $dnsLoc; | ||
|
||
if ($goodDns -ne $true) { | ||
Write-Error -Message 'DNS Name is bad'; | ||
} | ||
else { | ||
Write-Output 'DNS Name is good, creating VM'; | ||
|
||
# Create Resource Group | ||
New-AzureRmResourceGroup -Name $rgName -Location $rgLoc; | ||
|
||
## Create Network Objects | ||
# Define Subnet | ||
$subnetName = $pre + 'sn'; | ||
$subnetCfg = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 192.168.1.0/24; | ||
|
||
# Define Virtual Network | ||
$vNetName = $pre + 'vNet'; | ||
$vNet = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Location $rgLoc -Name $vNetName -AddressPrefix 192.168.0.0/16 -Subnet $subnetCfg; | ||
|
||
# Get a public IP address and define a DNS name | ||
$pipName = $pre + 'pip'; | ||
$pip = New-AzureRmPublicIpAddress -Name $pipName; -ResourceGroupName $rgName -Location $rgLoc -DomainNameLabel $vmDns -AllocationMethod Static -IdleTimeoutInMinutes 4 | ||
|
||
# Define an inbound network security group rule for port 3389 (Remote Desktop) | ||
$nsgRuleName = $pre + 'nsrRDP'; | ||
$nsgRuleRDP = New-AzureRmNetworkSecurityRuleConfig -Name $nsgRuleName -Protocol Tcp -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow; | ||
|
||
# Define a network security group | ||
$nsgName = $pre + 'nsg'; | ||
$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $rgName -Location $rgLoc -Name $nsgName -SecurityRules $nsgRuleRDP; | ||
|
||
# Define a virtual network card and link it with the already created public IP address and NSG | ||
$nicName = $pre + 'nic'; | ||
$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $rgLoc -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id; | ||
|
||
# Define a virtual machine configuration | ||
# Make sure you use a valid size for your subscription & location | ||
$vmSize = 'Standard_DS12_v2_Promo'; | ||
|
||
# Configure Disk | ||
$osDiskName = $vmname + '_osDisk'; | ||
$osDiskCaching = 'ReadWrite'; | ||
|
||
# Define Vm Configuration | ||
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize | Add-AzureRmVMNetworkInterface -Id $nic.Id; | ||
$vmConfig = Set-AzureRmVMOSDisk -VM $vmConfig -VhdUri $osDiskVhdUri -name $osDiskName -CreateOption attach -Windows -Caching $osDiskCaching; | ||
|
||
Set-AzureRmVMBootDiagnostics -VM $vmConfig -Enable -ResourceGroupName $rgName -StorageAccountName $diagStorageAccountName; | ||
|
||
# Create the Vm; the Vm will be started when done | ||
$userName = 'Brian' | ||
$purpose = "Workshop Testing" | ||
New-AzureRmVM -ResourceGroupName $rgName -Location $rgLoc -VM $vmConfig -Tags @{ User=$userName; Purpose=$purpose}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<# | ||
.COPYRIGHT | ||
Copyright (c) Brian A. Randell. All rights reserved. Licensed under the MIT license. | ||
See LICENSE in the project root for license information. | ||
#> | ||
|
||
### GETTING CONNECTED | ||
## GET AZURE POWERSHELL (RUN AS ADMINISTRATOR) | ||
# By default, this command will warn of untrusted repo. | ||
# Must accept gallery warning to continue | ||
Install-Module AzureRM -AllowClobber; | ||
Import-Module AzureRM; | ||
# See https://aka.ms/instazpowershelldocs for more details | ||
|
||
## LOGIN | ||
Login-AzureRmAccount; | ||
|
||
## POWERSHELL IN THE BROWSER | ||
https://portal.azure.com | ||
|
||
### CREATING A VM | ||
## FIND VALID VM LOCATIONS AND TYPES FOR SUBSCRIPTION | ||
# Get Vm Resource Provider and List Valid Locations | ||
$resources = Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Compute; | ||
$resources.ResourceTypes.Where{($_.ResourceTypeName -eq 'virtualMachines')}.Locations; | ||
# Get List of Vms in a specific Region | ||
$vmLoc = 'West US 2'; | ||
Get-AzureRmVmSize -Location $vmLoc | Sort-Object Name | Format-Table Name, NumberOfCores, MemoryInMB, MaxDataDiskCount -AutoSize; | ||
|
||
## CREATE A RESOURCE GROUP | ||
$rgName = 'yournamehere'; | ||
$rgLoc = 'West US 2'; | ||
|
||
New-AzureRmResourceGroup -Name $rgName -Location $rgLoc; | ||
|
||
## BUILD OBJECTS FOR A VM | ||
# Resource Group Variables (script assumes you've crated the group) | ||
$rgName = 'yournamehere'; | ||
$rgLoc = 'West US 2'; | ||
|
||
# Define Subnet | ||
$subnetName = "PSRsn"; | ||
$subnetCfg = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 192.168.1.0/24; | ||
|
||
# Define Virtual Network | ||
$vNetName = 'PSRvNet'; | ||
$vNet = New-AzureRmVirtualNetwork -ResourceGroupName $rgName -Location $rgLoc -Name $vNetName -AddressPrefix 192.168.0.0/16 -Subnet $subnetCfg; | ||
|
||
# Get a public IP address and define a DNS name | ||
$vmDns = "yourvmname$(Get-Random)"; | ||
$pip = New-AzureRmPublicIpAddress -ResourceGroupName $rgName -Location $rgLoc -AllocationMethod Static -IdleTimeoutInMinutes 4 -Name $vmDns; | ||
|
||
# Define an inbound network security group rule for port 3389 (Remote Desktop) | ||
$nsgRuleName = 'PSRnsrRDP'; | ||
$nsgRuleRDP = New-AzureRmNetworkSecurityRuleConfig -Name $nsgRuleName -Protocol Tcp -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow; | ||
|
||
# Define a network security group | ||
$nsgName = 'PSRnsg'; | ||
$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $rgName -Location $rgLoc -Name $nsgName -SecurityRules $nsgRuleRDP; | ||
|
||
# Define a virtual network card and link it with the already created public IP address and NSG | ||
$nicName = 'PSRnic'; | ||
$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $rgLoc -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id; | ||
|
||
# Define a virtual machine configuration | ||
$vmName = 'yourvmname'; | ||
$computerName = 'yourcomputername'; | ||
# Make sure you use a valid size for your subscription & location | ||
$vmSize = 'Standard_D2_v2'; | ||
|
||
# Define a credential object | ||
# (this will prompt you for a user name and password) | ||
$cred = Get-Credential; | ||
|
||
# Define Vm Configuration | ||
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize | ` | ||
Set-AzureRmVMOperatingSystem -Windows -ComputerName $computerName -Credential $cred | ` | ||
Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer ` | ||
-Skus 2016-Datacenter -Version latest | Add-AzureRmVMNetworkInterface -Id $nic.Id; | ||
|
||
# Create the Vm; the Vm will be started when done | ||
New-AzureRmVM -ResourceGroupName $rgName -Location $rgLoc -VM $vmConfig; | ||
|
||
## STOP A VM | ||
# Assumes you’ve created a VM | ||
$rgName = 'yournamehere'; | ||
$vmName = 'yourvmname'; | ||
Stop-AzureRmVM -ResourceGroupName $rgName -Name $vmName; | ||
|
||
## START A VM | ||
# Assumes you’ve created a VM | ||
$rgName = 'yournamehere'; | ||
$vmName = 'yourvmname'; | ||
Start-AzureRmVM -ResourceGroupName $rgName -Name $vmName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<# | ||
.COPYRIGHT | ||
Copyright (c) Brian A. Randell. All rights reserved. Licensed under the MIT license. | ||
See LICENSE in the project root for license information. | ||
#> | ||
|
||
# AzureRM-GetAllVMs | ||
Get-AzureRmContext | ||
|
||
$subs = Get-AzureRmSubscription | ||
|
||
$vmarrayx = @() | ||
|
||
foreach ($sub in $subs) | ||
{ | ||
Set-AzureRmContext -Subscription $sub.Name | ||
|
||
# Get all of the VM's: | ||
$rmvms=Get-AzureRmVM | ||
# $smvms=Get-AzureVM | ||
|
||
# $vmarray = @() | ||
# foreach ($vm in $smvms) | ||
# { | ||
# $vmarray += New-Object PSObject -Property @{` | ||
# Subscription=$sub.Name;` | ||
# AzureMode="Service_Manager";` | ||
# Name=$vm.InstanceName;` | ||
# PowerState=$vm.PowerState;` | ||
# Size=$vm.InstanceSize} | ||
# } | ||
|
||
# $vmarray | Format-Table | ||
|
||
foreach ($vm in $rmvms) | ||
{ | ||
# Get status (does not seem to be a property of $vm, so need to call Get-AzurevmVM for each rmVM) | ||
$vmstatus = Get-AzurermVM -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName -Status | ||
|
||
# Add values to the array: | ||
$vmarrayx += New-Object PSObject -Property @{` | ||
Subscription=$sub.Name;` | ||
AzureMode="Resource_Manager";` | ||
Name=$vm.Name;` | ||
PowerState=(get-culture).TextInfo.ToTitleCase(($vmstatus.statuses)[1].code.split("/")[1]);` | ||
Size=$vm.HardwareProfile.VmSize} | ||
} | ||
|
||
|
||
} | ||
|
||
$vmarrayx | Format-Table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<# | ||
.COPYRIGHT | ||
Copyright (c) Brian A. Randell. All rights reserved. Licensed under the MIT license. | ||
See LICENSE in the project root for license information. | ||
#> | ||
|
||
# FIND VALID VM LOCATIONS AND TYPES FOR SUBSCRIPTION | ||
# Get Vm Resource Provider | ||
$resources = Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Compute; | ||
# List Valid Locations | ||
$resources.ResourceTypes.Where{($_.ResourceTypeName -eq 'virtualMachines')}.Locations; | ||
# Get List of Vms in a specific Region | ||
$vmLoc = 'West US 2'; | ||
Get-AzureRmVmSize -Location $vmLoc | Sort-Object Name | Format-Table Name, NumberOfCores, MemoryInMB, MaxDataDiskCount -AutoSize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<# | ||
.COPYRIGHT | ||
Copyright (c) Brian A. Randell. All rights reserved. Licensed under the MIT license. | ||
See LICENSE in the project root for license information. | ||
#> | ||
|
||
# Azure PowerShell Remove Resource Group | ||
$rgName = 'ResourceGroupName'; | ||
|
||
Remove-AzureRmResourceGroup -Name $rgName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<# | ||
.COPYRIGHT | ||
Copyright (c) Brian A. Randell. All rights reserved. Licensed under the MIT license. | ||
See LICENSE in the project root for license information. | ||
#> | ||
|
||
$sw = [Diagnostics.Stopwatch]::StartNew() | ||
|
||
Login-AzureRmAccount | ||
|
||
Get-AzureRmContext | ||
|
||
Get-AzureRmSubscription | Format-Table Name, Id | ||
|
||
Set-AzureRmContext -Subscription "A valid sub name" | ||
|
||
$sw.Stop() | ||
Write-Host "Time elapsed: " $sw.Elapsed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<# | ||
.COPYRIGHT | ||
Copyright (c) Brian A. Randell. All rights reserved. Licensed under the MIT license. | ||
See LICENSE in the project root for license information. | ||
#> | ||
|
||
# Find Excel Files in my Dropbox | ||
$root = 'C:\Dropbox\*.*' | ||
$filter = '*.xl*' | ||
|
||
# Assumes MM/DD/YY date format | ||
$startDate = '1/20/18' | ||
$endDate = '11/27/15' | ||
|
||
Get-ChildItem -Path $root -Filter $filter -Recurse | | ||
Where-Object { | ||
$_.lastwritetime -gt $startDate -AND $_.lastwritetime -lt $endDate | ||
} |
Oops, something went wrong.