Azure VM Extensions - azure-virtual-machine

I'm executing the following:
Set-AzureRmVMExtension `
-VMName 'servername' `
-ResourceGroupName 'rgname' `
-Name 'JoinAD' `
-ExtensionType 'JsonADDomainExtension' `
-Publisher 'Microsoft.Compute' `
-TypeHandlerVersion '1.0' `
-Location 'West Europe' `
-Settings #{'Name' = 'domain.com'; 'OUPath' = 'OU=Server 2012 R2,OU=Servers,DC=domain,DC=com'; 'User' = 'domain.com\username'; 'Restart' = 'true'; 'Options' = 3} `
-ProtectedSettings #{'Password' = 'password'}
and get this error:
Set-AzureRmVMExtension : Long running operation failed with status
'Failed'. StartTime: 18.04.2016 18:03:30 EndTime: 18.04.2016 18:04:50
OperationID: 76825458-6c50-404d-bb1a-b27c722b1760 Status: Failed
ErrorCode: VMExtensionProvisioningError ErrorMessage: VM has reported
a failure when processing extension 'JoinAD'. Error message: "Join
completed for Domain 'ddomain.com'". At line:1 char:1
+ Set-AzureRmVMExtension `
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureRmVMExtension], ComputeCloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.SetAzureVMExtensionCommand
What am I missing?

Kept having trouble with extension, therefore opted to perform the domain join using PowerShell Add-Computer without extensions.
One possibly cause might be that NSG configurations block connectivity to the internet and with that to services running in the Azure data center.

Related

How to get shell script to work on gcloud CLI in PowerShell?

I've installed the gcloud CLI according to https://cloud.google.com/sdk/docs/install.
When using cloud shell on browser, I could simply paste a script and it would work. But it won't do the same when using cloud CLI on Powershell.
Script:
# List Projects accessible to these credentials
PROJECTS=$( `
gcloud projects list `
--format="value(projectId)")
# Iterate over each Project
for PROJECT in ${PROJECTS}
do
echo "Project: ${PROJECT}"
# Check Compute Engine service
ENABLED="$( `
gcloud services list `
--project=${PROJECT} `
--filter=config.name=compute.googleapis.com `
--format='value(state)')"
# Is it enabled?
if [ "${ENABLED}" = "ENABLED" ]
then
# Enumerate Disks that have `users` and output `name`
gcloud compute disks list `
--project=${PROJECT} `
--filter="-users:*" `
--format="csv(name,sizeGb,zone,status,type,lastAttachTimestamp,lastDetachTimestamp)"
fi
done
Result on browser cloud shell: successfully iterated through projects and listed disks in that project.
Result on Powershell:
PS C:\WINDOWS\System32> C:\Users\minh.tran\Documents\Get Disk.ps1
At C:\Users\minh.tran\Documents\Get Disk.ps1:7 char:4
+ for PROJECT in ${PROJECTS}
+ ~
Missing opening '(' after keyword 'for'.
At C:\Users\minh.tran\Documents\Get Disk.ps1:8 char:3
+ do
+ ~
Missing statement body in do loop.
At C:\Users\minh.tran\Documents\Get Disk.ps1:17 char:5
+ if [ "${ENABLED}" = "ENABLED" ]
+ ~
Missing '(' after 'if' in if statement.
At C:\Users\minh.tran\Documents\Get Disk.ps1:17 char:7
+ if [ "${ENABLED}" = "ENABLED" ]
+ ~
Missing type name after '['.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword
PS C:\WINDOWS\System32>
The comment from #John Hanley is the correct answer. I tried to use a Linux shell script as a PowerShell script on a Windows machine.
The simplest solution for my case is to convert the shell script to a PowerShell script and run the converted script from PowerShell.
Converted script can be found here: GCP | disks.list method returning error when ran as part of a script . Despite working, it is still throwing some errors.

Elastic Beanstalk post install script won't execute correctly

I want to publish a .NET core application to Elastic Beanstalk and they will be running on Windows Server. I want to make some changes to IIS settings... more precisely Queue Length of Application Pool.
I have aws-windows-deployment-manifest.json file with the following content
{
"manifestVersion": 1,
"deployments": {
"aspNetCoreWeb": [
{
"name": "my-dotnet-core-app",
"scripts": {
"postInstall": {
"file": "SetupScripts/setupAppPool.ps1"
}
}
}
]
}
}
Inside setupAppPool.ps1 script is the following content:
Import-Module WebAdministration
$defaultAppPool = Get-ItemProperty IIS:\AppPools\DefaultAppPool
#$defaultAppPool.PSPath
Write-Host "Display Queue Length before change: " -NoNewline
(Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength
#Value changed here
Set-ItemProperty -Path $defaultAppPool.PSPath -Name queueLength -Value 3000
Write-Host "Display Queue Length after change: " -NoNewline
(Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength
If it will be a simple scritp like hostname it executes with no problem, however this one fails with the following error:
2022-07-12 17:41:25,025 [INFO] Running config InfoTask-TailLogs
AWS.DeploymentCommands.2022.07.12-17.40.30.log:
Starting deployment for my-dotnet-core-app of type AspNetCoreWeb
Parameters:
appBundle: .
iisPath: /
iisWebSite: Default Web Site
Starting restart of my-dotnet-core-app
---------- Executing command "C:\Windows\system32\iisreset.exe /restart" ----------
---------- CWD "" ----------
Attempting stop...
Internet services successfully stopped
Attempting start...
Internet services successfully restarted
---------- Command complete with exit code 0 ----------
Starting ASP.NET Core web deployment my-dotnet-core-app at C:\inetpub\AspNetCoreWebApps\my-dotnet-core-app with IIS path Default Web Site/
Copying C:\staging\. to C:\inetpub\AspNetCoreWebApps\my-dotnet-core-app
Removing existing application from IIS
Adding application to IIS
Commit changes to IIS
---------- Executing command "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy unrestricted -NonInteractive -NoProfile -Command "& { & \"C:\staging\SetupScripts/setupAppPool.ps1\"; exit $LastExitCode }" " ----------
---------- CWD "C:\inetpub\AspNetCoreWebApps\my-dotnet-core-app" ----------
Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for
component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At C:\staging\SetupScripts\setupAppPool.ps1:2 char:19
+ $defaultAppPool = Get-ItemProperty IIS:\AppPools\DefaultAppPool
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand
Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for
component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At C:\staging\SetupScripts\setupAppPool.ps1:7 char:2
+ (Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand
Set-ItemProperty : Cannot bind argument to parameter 'Path' because it is null.
At C:\staging\SetupScripts\setupAppPool.ps1:10 char:24
+ Set-ItemProperty -Path $defaultAppPool.PSPath -Name queueLength -Valu ...
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ItemProperty], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetItemProp
ertyCommand
Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for
component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At C:\staging\SetupScripts\setupAppPool.ps1:13 char:2
+ (Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand
Display Queue Length before change: Display Queue Length after change:
---------- Command complete with exit code 0 ----------
Error messages running the command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy unrestricted -NonInteractive -NoProfile -Command "& { & \"C:\staging\SetupScripts/setupAppPool.ps1\"; exit $LastExitCode }"
Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for
component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At C:\staging\SetupScripts\setupAppPool.ps1:2 char:19
+ $defaultAppPool = Get-ItemProperty IIS:\AppPools\DefaultAppPool
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand
Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for
component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At C:\staging\SetupScripts\setupAppPool.ps1:7 char:2
+ (Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand
Set-ItemProperty : Cannot bind argument to parameter 'Path' because it is null.
At C:\staging\SetupScripts\setupAppPool.ps1:10 char:24
+ Set-ItemProperty -Path $defaultAppPool.PSPath -Name queueLength -Valu ...
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-ItemProperty], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetItemProp
ertyCommand
Get-ItemProperty : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for
component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At C:\staging\SetupScripts\setupAppPool.ps1:13 char:2
+ (Get-ItemProperty IIS:\AppPools\DefaultAppPool\).queueLength
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ItemProperty], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemPropertyCommand
---------- Executing command "C:\Windows\system32\iisreset.exe /start" ----------
---------- CWD "" ----------
Attempting start...
Internet services successfully started
---------- Command complete with exit code 0 ----------
AWSCommandWrapper.log:
How can I solve this problem?

Unable to connect to vCloud Server because of authorization error

I'm running the below command to connect to vCloud Director using PowerShell
Connect-CIServer -Server "company.com.au" -User "username" -Password "password" -Org "testorg"
However, it is giving me error like below:
Connect-CIServer : 20/09/2019 2:13:12 PM Connect-CIServer
Unable to connect to vCloud Server 'https://company.com.au:443/api/'. The
server returned the following: Unauthorized: ''.
At line:1 char:1
+ Connect-CIServer -Server "company.com.au" -User "username" -Pas ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-CIServer], CIException
+ FullyQualifiedErrorId : Cloud_ConnectivityServiceImpl_ConnectCloudServer_ConnectError,VMware.VimAutomation.Cloud.Commands.Cmdlets.ConnectCIServer
Unfortunately, not much information is given, I can login to the UI by the same credentials but not on command line?
I had similar issue when I was trying to login to VCentre, I got it working by ignoring certificates. Not sure if for VCloud Server,I am facing same issue?
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
Works well when I drop -Org parameter! so the command which worked for me to login to Cloud Director is as below:
Connect-CIServer -Server "company.com.au" -User "username" -Password "password"

Ansible using AWS interactions throws exception

I was trying to run a playbook to automate AWS but i encountered this exception which I can't understand. I have the following playbook:
- name: Just for testing
hosts: windows-server
gather_facts: no
vars:
aws_a_key: accesskey
aws_s_key: secretkey
tasks:
- name: Ping
win_ping:
- name: Create a file to C:\Temp\test.conf
win_file:
path: C:\Temp\test.conf
state: touch
- name: Create another file to C:\Temp\test2.conf
win_file:
path: C:\Temp\test2.conf
state: touch
- name: Gather S3 facts
aws_s3_bucket_facts:
aws_access_key: "{{ aws_a_key }}"
aws_secret_key: "{{ aws_s_key }}"
region: eu-central-1
When I try to execute it I get the following error:
PLAY [Just for testing] *******************************************************************************************************
TASK [Ping] *******************************************************************************************************************
ok: [WIN-40NQ43PHHA5]
TASK [Create a file to C:\Temp\test.conf] *************************************************************************************
changed: [WIN-40NQ43PHHA5]
TASK [Create another file to C:\Temp\test2.conf] ******************************************************************************
changed: [WIN-40NQ43PHHA5]
TASK [Gather S3 facts] ********************************************************************************************************
fatal: [WIN-40NQ43PHHA5]: FAILED! => {"changed": false, "module_stderr": "Exception calling \"Create\" with \"1\" argument(s): \"At line:4 char:21
+ def _ansiballz_main():
+ ~
An expression was expected after '('.
At line:12 char:27
+ except (AttributeError, OSError):
+ ~
Missing argument in parameter list.
At line:14 char:7
+ if scriptdir is not None:
+ ~
Missing '(' after 'if' in if statement.
At line:21 char:7
+ if sys.version_info < (3,):
+ ~
Missing '(' after 'if' in if statement.
At line:21 char:30
+ if sys.version_info < (3,):
+ ~
Missing expression after ','.
At line:21 char:25
+ if sys.version_info < (3,):
+ ~
The '<' operator is reserved for future use.
At line:23 char:32
+ MOD_DESC = ('.py', 'U', imp.PY_SOURCE)
+ ~
Missing expression after ','.
At line:23 char:33
+ MOD_DESC = ('.py', 'U', imp.PY_SOURCE)
+ ~~~~~~~~~~~~~
Unexpected token 'imp.PY_SOURCE' in expression or statement.
At line:23 char:32
+ MOD_DESC = ('.py', 'U', imp.PY_SOURCE)
+ ~
Missing closing ')' in expression.
At line:23 char:46
+ MOD_DESC = ('.py', 'U', imp.PY_SOURCE)
+ ~
Unexpected token ')' in expression or statement.
Not all parse errors were reported. Correct the reported errors and try again.
\"
At line:6 char:1
+ $exec_wrapper = [ScriptBlock]::Create($split_parts[0])
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ParseException
The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command
name, a script block, or a CommandInfo object.
At line:7 char:2
+ &$exec_wrapper
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : BadExpression
", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
to retry, use: --limit #/Users/mpolgardi/ansible/test_playbook.retry
PLAY RECAP ********************************************************************************************************************
WIN-40NQ43PHHA5 : ok=3 changed=2 unreachable=0 failed=1
Can someone help me decode this error? I have no idea where to even look. Also is there a way for ansible to give me readable error messages?
According to the fine manual, use of aws_s3_bucket_facts requires python with both the boto and boto3 modules available to it.
What appears to be happening to you is that the windows machine is trying to execute that .py file as if it were PowerShell, and (of course) those two syntaxes are wholly incompatible.
Do you have ansible_python_interpreter set to a working binary? It is possible that switching gather_facts: to yes will surface any misconfiguration earlier, although I can't swear to it since I don't know if the winrm connection pre-empts fact gathering using just PowerShell, and wouldn't notice a bogus ansible_python_interpreter value.
While this isn't exactly what you asked, it's also quite a common behavior to use delegate_to: localhost and/or connection: local for those AWS-y tasks, since there is little to no value in having those tasks run on the target machine, given that the credentials are already present in the playbook (that is: it doesn't acquire credentials from anything on the target machine). That presumes, naturally, that you have a local python which has boto and boto3 installed in them, but that's presumably far more likely than convincing a random windows machine to work correctly.

Unable to register targets on AWS Target group

I am trying to setup an automated DNS deployment using powershell. I have written a powershell script that creates TargetGroup, registers instances to the TG, creates an ALB and adds a listener to it. Once, that is done, it creates R53 RecordSet and creates an A record to the ALB DNS.
I am having issues in having the instances registered to the TargetGroup.
This is my code snippet to that section:
$searchFor1 =#( #{name = 'tag:Name'; values = $target1})
$searchFor2 =#( #{name = 'tag:Name'; values = $target2})
$id1 = (Get-EC2Instance -Filter $searchFor1).Instances | select InstanceId
$id2 = (Get-EC2Instance -Filter $searchFor2).Instances | select InstanceId
# Create Target Group
$tg = New-ELB2TargetGroup -TargetType "instance" -HealthyThresholdCount 4 -Name $custname -Port $siteport -Protocol "HTTP" -UnhealthyThresholdCount 4 -VpcId $vpcid
Start-Sleep -s 120
$addid1 = New-Object Amazon.ElasticLoadBalancingV2.Model.TargetDescription
$addid2 = New-Object Amazon.ElasticLoadBalancingV2.Model.TargetDescription
$addid1.Id = $id1.InstanceId
$addid2.Id = $id2.InstanceId
$addid1.Port = $siteport
$addid2.Port = $siteport
$tgarn = (Get-ELB2TargetGroup -Name $custname).TargetGroupArn
Register-ELB2Target -TargetGroupArn $tgarn -Target #($addid1)
Register-ELB2Target -TargetGroupArn $tgarn -Target #($addid2)
It throws below error:
Register-ELB2Target : An instance ID must be specified
At C:\scripts\Distinct-DNS-Deployment.ps1:107 char:1
+ Register-ELB2Target -TargetGroupArn $tgarn -Target #($addid1)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Amazon.PowerShe...LB2TargetCmdlet:RegisterELB2TargetCmdlet) [Register
-ELB2Target], InvalidOperationException
+ FullyQualifiedErrorId : Amazon.ElasticLoadBalancingV2.AmazonElasticLoadBalancingV2Exception,Amazon.PowerShell.Cm
dlets.ELB2.RegisterELB2TargetCmdlet
I have checked a similar post here. And the corresponding posts, so far nothing helped. I am wondering if anyone can guide me what am I doing wrong?
I have tried to run each line one by one and that happens to register the instance to the TargetGroup, just the script fails.
Instances are t2.micro and they are in running state.
As per the https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/ElasticLoadBalancingV2/TTargetDescription.html -
the Amazon.ElasticLoadBalancingV2.Model.TargetDescription is about 'Information about a target' -
which means, you should be assigning a single instance id Also, if you take a close look at the properties:
AvailabilityZone System.String
Id System.String
Port System.Int32
The result of your instance search may or may not be single output - you should keep them in loop to create each target via TargetDescription
$Instances = (Get-EC2Instance -Filter #{Name="tag:auto-delete";Value="no"}).instances |select instanceid
$theVpc = get-ec2vpc -VpcId vpc-4565e5c4
$name = "new-tg"
$port = "80"
$protocol = "HTTP"
$tg = New-ELB2TargetGroup -TargetType "instance" -HealthyThresholdCount 4 -Name $name -Port $port -Protocol "HTTP" -UnhealthyThresholdCount 4 -VpcId $theVpc.VpcId
$tgarn = (Get-ELB2TargetGroup -Name $name).TargetGroupArn
If($instances -ne $null){
foreach ($instance in $instances ){
$addid1 = New-Object Amazon.ElasticLoadBalancingV2.Model.TargetDescription
$addid1.Id = $Instance.instanceid
$addid1.Port = $port
Register-ELB2Target -TargetGroupArn $tgarn -Target #($addid1)
Remove-Variable addid1
}
}
else {
echo "There were no instances with the matching filter"
}