这更像是一次学习练习,但我希望这会有所帮助.
我想创建一个这样的函数:
function array_to_array ($stuff, $new_type){
$new_stuff = $stuff -as $new_type
$new_stuff
}
Run Code Online (Sandbox Code Playgroud)
我在传递字符串或甚至[char]是new_type等值时遇到问题.我想我需要做一些事情,$type = [char]但我想尽可能保持基于字符串的?
反正有没有这样做?比如激活一个字符串?
我期待创建一个将生成Word文档的PowerShell脚本.它按预期工作,但是当我运行脚本时,"我的文档:标题"和"日期:01-07-2014"之间存在空格或换行符.结果如下:
My Document: Title
Date: 01-07-2014
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样:
My Document: Title
Date: 01-07-2014
Run Code Online (Sandbox Code Playgroud)
如何在段落中删除空格的方式写入此脚本?我的意思是,我想在PowerShell中将段落间距设置为单一(默认情况下不在Word中)顺便说一下,如果我不在"Date:$ date"之前添加$ selection.TypeParagraph(),结果如下:
My Document: TitleDate: 01-07-2014
Run Code Online (Sandbox Code Playgroud)
如同,根本没有回车.目标是在回车后返回一个回车但没有空间.这是脚本.
$date = get-date -format MM-dd-yyyy
$filePath = "C:\users\myuser\file"
[ref]$SaveFormat = "microsoft.office.interop.word.WdSaveFormat" -as [type]
$word = New-Object -ComObject word.application
$word.visible = $true
$doc = $word.documents.add()
$selection = $word.selection
$selection.font.size = 14
$selection.font.bold = 1
$selection.typeText("My Document: Title")
$selection.TypeParagraph()
$selection.font.size = 11
$selection.typeText("Date: $date")
$doc.saveas([ref] $filePath, [ref]$saveFormat::wdFormatDocument)
Run Code Online (Sandbox Code Playgroud) 所以,我不明白这里发生了什么...我有(3)微型EC2实例启动(没有弹性IP)
然后我转到Network Security->Elastic IPs并单击关联IP地址.我选择了一个正在运行的EC2实例,然后该实例使用弹性ip.
如果我stop,那么 start这个SAME ec2实例,它没有相同的先前弹性IP地址,而是一些全新的IP地址.这会弄乱脚本,然后依赖于之前关联到该EC2实例的弹性IP.
为什么会发生这种情况以及为什么我无法获得任何(3)个实例并保持这个弹性ip?
我想创建一个只允许s3的AWS访问密钥.这意味着密钥不能与任何其他服务一起使用.可能吗?怎么样?
我一直在尝试使用以下脚本,但没有成功:
$Ami=Get-EC2ImageByName WINDOWS_2012_BASE
New-EC2Instance -ImageId $Ami[0].ImageId -MinCount 1 -MaxCount 1 -KeyName uckey -InstanceType `
t1.micro -SubnetId subnet-56738b33 -AssociatePublicIp $true
Run Code Online (Sandbox Code Playgroud)
错误是:
New-EC2Instance : Object reference not set to an instance of an object.
At line:1 char:1
+ New-EC2Instance -ImageId $Ami[0].ImageId -MinCount 1 -MaxCount 1 -KeyName uckey ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Amazon.PowerShe...2InstanceCmdlet:NewEC2InstanceCmdlet)
[New-EC2Instance], InvalidOperationException
+ FullyQualifiedErrorId : System.NullReferenceException,Amazon.PowerShell.Cmdlets.EC2.NewEC2InstanceC
mdlet
Run Code Online (Sandbox Code Playgroud)
问题在于-AssociatePublicIp没有它的参数,脚本可以工作。
谢谢阅读
使用aws CLI,如何在给定其instanceID的情况下检索EC2实例的私有IP地址?
当我做:
aws ec2 describe-instance-status --instance-ids <instance_ID>
Run Code Online (Sandbox Code Playgroud)
我得到其他信息,但不是私有IP地址,例如:
{
"InstanceStatuses": [
{
"InstanceId": "XXXXX",
"InstanceState": {
"Code": 16,
"Name": "running"
},
"AvailabilityZone": "us-east-1a",
"SystemStatus": {
"Status": "ok",
"Details": [
{
"Status": "passed",
"Name": "reachability"
}
]
},
"InstanceStatus": {
"Status": "ok",
"Details": [
{
"Status": "passed",
"Name": "reachability"
}
]
}
}
]
}
Run Code Online (Sandbox Code Playgroud) 我只是提出一个红移集群来开始开发工作,并且通常使用cron服务在工作时间之外关闭我的所有开发资源以节省资金.
当我浏览aws cli帮助时:
aws redshift help
Run Code Online (Sandbox Code Playgroud)
我没有看到任何停止或关闭我的测试集群的选项,就像我在控制台中一样.
如果没有办法做到这一点,有人知道他们为什么不提供这个功能吗?这些实例非常花钱,可以保持在线,我不想每天晚上都用手将它们关闭.
我正在使用 powershell 使用以下脚本创建新的 EC2 密钥对:
Import-Module AWSPowerShell
$Region = "EU West"
$ProfileName = "AWS Default"
Initialize-AWSDefaults -ProfileName $ProfileName
$KeyName = "SecurityEssentials"
$KeyPair = New-EC2KeyPair -KeyName $KeyName
Run Code Online (Sandbox Code Playgroud)
但是它在最后一行失败并显示以下消息:
New-EC2KeyPair:无效的 URI:无法解析主机名。在 C:\Users\John\Documents\Cloud\AWS Setup.ps1:12 char:12 + $KeyPair = New-EC2KeyPair -KeyName $KeyName + ~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Amazon.PowerShe...C2KeyPairCmdlet:NewEC2KeyPairCmdlet) [New-EC2KeyPair], InvalidOperationException +fullyQualifiedErrorId : System.UriFormatException,Amazon.PowerShell.Cmdlets .EC2.NewEC2KeyPairCmdlet
使用调试标志不会提供任何新信息。我正在使用带有最新 AWS SDK 和 AWS powershell cmdlet 的 Windows 8.1
编辑:问题似乎与 AWSDefaults 的设置方式有关。事实证明,在此之后发出的任何命令都会出现相同的错误。
我需要从php调用我的Amazon Lambda函数,但是当我拥有AWSLambdaFullAccess权限时,我得到了奇怪的权限错误.我的代码:
$client = LambdaClient::factory(array(
'key' => 'AKI...G',
'secret' => 'VXD...YOse',
'region' => 'us-west-2'
));
$result = $client->invokeAsync(array(
'FunctionName' => 'arn:aws:lambda:us-west-2:180...52:function:fe...st',
'InvokeArgs' => json_encode($array),
));
Run Code Online (Sandbox Code Playgroud)
这是错误:
User: arn:aws:iam::69...67:user/developer is not authorized to
perform: lambda:InvokeFunction on resource:
arn:aws:lambda:us-west-2:180...52:function:fe...st
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢
我正在构建一个更大的 AWS CLI 工作,但其中一个构建块让我感到困惑;
如何获取当前正在运行的每个 AWS Cloudformation 堆栈的名称列表?
我可以使用以下内容很好地列出堆栈,但我无法获得将其与堆栈名称配对的查询。
aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE --output text
Run Code Online (Sandbox Code Playgroud)
我可以在 bash 中减少结果表,但如果存在更优雅的 aws 解决方案,我会喜欢。
aws-cli ×4
powershell ×4
amazon-ec2 ×3
amazon-iam ×1
amazon-s3 ×1
aws-lambda ×1
bash ×1
casting ×1
dynamic ×1
elastic-ip ×1
ms-word ×1
php ×1
string ×1
types ×1