Jay Thomas
asked on
Extend powershell script
Hi all. Last week the good folks of EE provided me some wonderful support in providing the script below, which works perfectly. I have a request that will extend the script. Currently, the script looks in the source file c:\temp\servers.txt, and what ever server names are in there the script runs again.
What about this scenario. What if instead of the txt file I had a csv file with 2 columns. column one named VM Name, column two is called Resource Group. So essentially I have two columns with VM names and Resource Group names. Could the script be manipulated so that the script runs only against the VMs if they are in a particular Resource Group?
Example, I have 3 vm names but I only want the script to run against the vms in RG1? See below for existing script.
VM Name Resource Group Name
vm1 RG1
vm2 RG1
vm3 RG2
What about this scenario. What if instead of the txt file I had a csv file with 2 columns. column one named VM Name, column two is called Resource Group. So essentially I have two columns with VM names and Resource Group names. Could the script be manipulated so that the script runs only against the VMs if they are in a particular Resource Group?
Example, I have 3 vm names but I only want the script to run against the vms in RG1? See below for existing script.
VM Name Resource Group Name
vm1 RG1
vm2 RG1
vm3 RG2
Param(
[Parameter(Position=0, Mandatory=$true, HelpMessage="Name of the KeyVault")]
[string]$KVName,
[Parameter(Position=1, Mandatory=$true, HelpMessage="Name of the KeyVault Resource Group")]
[string]$KVResourceGroup,
[Parameter(Position=3, Mandatory=$true, HelpMessage="Name of the VM Resource Group")]
[string]$VMResourceGroup
)
$keyVault = Get-AzureRmKeyVault -VaultName $KVName -ResourceGroupName $KVResourceGroup
$splat = @{
ResourceGroupName = $VMResourceGroup
DiskEncryptionKeyVaultUrl = $keyVault.VaultUri
DiskEncryptionKeyVaultId = $keyVault.ResourceId
}
foreach ($VMName in Get-Content -Path C:\temp\servers.txt)
{
Set-AzureRmVMDiskEncryptionExtension @splat -VMName $VMName
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Flawless as always! Thank you. If EE don't have you on the payroll there're missing a trick.
ASKER