Exception calling AWS Send-SQSMessage PowerShell command - powershell

Environment
Windows 7
WMF / PowerShell 5.0 installed
AWS PowerShell version 3.3.36.0
Scenario
I'm trying to use the Amazon Web Services (AWS) PowerShell module to send a message to a queue. However, when I invoke the Send-SQSMessage command, I'm getting an exception thrown:
Send-SQSMessage : The specified queue does not exist for this wsdl version.
I've already set up my AWS credentials in the ~/.aws/credentials file, using the Set-AWSCredentials command. Here's the command I'm calling:
$text = (Get-ChildItem)[1] | ConvertTo-Json -Depth 1
Send-SQSMessage -QueueUrl https://sqs.us-east-1.amazonaws.com/redacted/myqueuename -MessageBody $text -ProfileName TrevorAWS

This error message can pop up when the configured region doesn't match up to the AWS resource that you're working with. To configure the region correctly, you have a couple of choices:
Use the Set-DefaultAWSRegion command to configure the default region. This prevents the need to specify the -Region parameter on
You can specify the -Region parameter on any AWS cmdlet, and force it to use that region for that single command invocation.
Use the Initialize-AWSDefaults command to set up your PowerShell environment.
After configuring the correct region, that correlates to your AWS SQS queue, the Send-SQSMessage command should execute without throwing any exceptions.

Related

Create and configuring Application Pool on IIS w10 and powershell 7.2

I'm trying to create a pool of applications with specific parameters using this code:
$currentAppPool = New-WebAppPool -Name myNeyAppPool
# Set pool specifications
$currentAppPool.AutoStart = "true"
$currentAppPool.ManagedRuntimeVersion = "No Managed Code"
$currentAppPool | Set-Item
I have several errors because setitem asks me for a path variable that it doesn't recognize. Set-Item: The input object cannot be bound because it did not contain the information required to bind all mandatory parameters: Path
I tried to give it the parameter -path IIS:\AppPools\myNeyAppPool but I get the message
Set-Item: Cannot find drive. A drive with the name 'IIS' does not exist
There are quite a few changes concerning the management of IIS in w10 via powershell 7, but little documentation seems to exist on the subject.
Is there anything help ?
Thks,
The provider "IIS:" is loaded when importing the webadministration module.
Providers before and after to load webadministration module
Do you have IIS role enabled in windows 10?
You can check the following link:
https://community.lansweeper.com/t5/installation/how-to-install-iis-internet-information-services/ta-p/64422
Which providers appear if you run the "Get-PSProvider" command?
First try running PowerShell as an administrator, and then the drive is provided by the WebAdministration module, so you need make sure install that module, you can install the module with the following PowerShell commands:
Import-Module ServerManager
Add-WindowsFeature Web-Scripting-Tools

What is wrong with this EC2 UserData powershell script?

I'm using AWS S3 to launch a new fleet of spot instances and trying to set up a powershell script to run at luanch as per the instructions here(http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html#user-data-powershell)
Here's the powershell script which generates a name for the server with a random string and then restarts the computer:
<powershell>
$rnd = ([char[]] (65..90) | get-random -count 3) -join ''
$name = "spot-server-$rnd"
Rename-Computer -NewName $name
shutdown /r /f
</powershell>
I've added the script to the UserData field when launching the instances, however, when the instance launches it doesn't seem to work.
NOTE: when i run the script using the powershell terminal it works (renames the computer and restarts the machine)
UPDATE/SOLUTION: I believe the issue was that the AMI I used did not have User Data Enabled in the EC2 Service Properties. I solved the issue by following these steps:
Go to EC2 Service Properties, check the User Data checkbox / click on "Shutdown with Sysprep"
Create a new AMI from that instance that just got shut down
Launch a new instance using the new AMI and specify the User Data script

Powershell Azure : The term 'Get-AutomationConnection' is not recognized as the name of a cmdlet, function, script file, or operable program

I am trying to connect to an Azure Run As connection, as part of a Powershell script that does a backup of a database.
This script attempts to call Get-AutomationConnection
As seen in the screenshot, Get-Module does return that Azure / Azure.Storage and AzureRM shows.
What module should I import in addition for this to work?
If you want to connect to an Azure Run As connection from Windows PowerShell, you should use New-AzureRmAutomationConnection.
$ConnectionAssetName = "AzureRunAsConnection"
$ConnectionFieldValues = #{"ApplicationId" = $Application.ApplicationId; "TenantId" = $TenantID.TenantId; "CertificateThumbprint" = $Cert.Thumbprint; "SubscriptionId" = $SubscriptionId}
New-AzureRmAutomationConnection -ResourceGroupName $ResourceGroup -AutomationAccountName $AutomationAccountName -Name $ConnectionAssetName -ConnectionTypeName AzureServicePrincipal -ConnectionFieldValues $ConnectionFieldValues
You are able to use the script to create the connection asset because when you create your Automation account, it automatically includes several global modules by default along with the connection type AzurServicePrincipal to create the AzureRunAsConnection connection asset.
Get-AutomationConnection runs in Azure runbook internally.
Please refer to connection assets in Azure Automation.
If you want similar functionality to runbooks on-premise, you can install AzureAutomationAuthoringToolkit. It will give you very similar functionality. I have one script that logs in using the service principal, whether it is running on-premise or in an Azure runbook. It uses the resources provided by AAATK when running on-premise, that simulate a runbook.
I did try using the version of Get-AutomationConnection that comes with the "Microsoft Monitoring agent" (Hybrid worker), but I have since read that it is different to the one that comes with AzureAutomationAuthoringToolkit, detailed in the "Known Issues" in the GitHub readme. I couldn't get it to work, so I reverted to AAATK's version.

Get AWS S3 Bucket Object Using PowerShell DSC

Using PowerShell DSC, I'm trying to read an object from within an AWS S3 bucket but I get the following error:
Unable to load stored credentials for profile = [default]
I have tried using the -ProfileLocation parameter however that then throw the error "A parameter cannot be found that matches parameter name 'ProfileLocation'". My code is as follows:
Read-S3Object -ProfileName default BucketName $bucket -Key $key -File $file
Make sure you have read this documentation "Using AWS Credentials" and followed the instructions it provided.
Troubleshooting
ProfileName is not supported in the AWS Powershell Tools prior to version v1.1. You can check your version through the Get-AWSPowerShellVersion cmdlet. If you are using an earlier version, try using the StoredCredentials parameter instead. Alternatively, you can update.
Make sure that the profile name "default" actually exists. You can check this by running Get-AWSCredentials -ListStoredCredentials, which will return a list of stored AWS credentials.
If your desired profile name does not exist, you will need to create it.
The documentation provides the following example for creating a new profile:
Set-AWSCredentials -AccessKey AKIAIOSFODNN7EXAMPLE `
-SecretKey wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY `
-StoreAs MyProfileName
Note: Concerning terminology, Stored Credential and Profile seem to be used interchangeably by the documentation.

PowerShell Stop-Service/Start-Service not working on a specific server

I have three servers, let's call them Deploy1, Deploy2, Target.
All servers are running Windows Server 2008R2, fully updated.
A domain user, admin1, is configured as administrator on all servers, and this is the user I'm running all the commands with.
The following command works on Deploy1:
Get-Service "MyService" -ComputerName Target | Stop-Service
When running the same command on Deploy2, the command fails with the following message:
Cannot find any service with service name 'MyService'.
On Deploy2, the following command works, and displays the service and its status.
Get-Service "MyService" -ComputerName Target
Now, I know there are other ways to stop/start services via PowerShell, but I like this one as it automatically waits for the server to actually stop/start.
So what could be wrong with Deploy2?
Powershell v2.0 has a bug (feature?) in how the object returned by Get-Service is implemented. It does not actually set the ComputerName property correctly. Because of this, it can only affect local services. If you upgrade to Windows Management Framework 3.0 (and consequently Powershell v3) the bug is fixed and will work correctly.
Does this work? If not, is there an error produced?
(Get-Service "MyService" -ComputerName Target).Stop()