阿里云CLI 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 aliyun configure list aliyun configure --mode AK --profile "example" .\aliyun.exe ecs DescribeZones --RegionId ap-southeast-1 | tee zone.txt aliyun vpc DescribeVpcs aliyun vpc DescribeVSwitches .\aliyun.exe --profile CLI-exampleAK1 vpc DescribeVSwitches | tee vsw.json .\aliyun.exe vpc DescribeVpcs --output cols="VpcName,VpcId,VSwitchIds" rows="Vpcs.Vpc[]" .\aliyun.exe --profile CLI-exampleAK1 vpc DescribeVpcs --output cols="VpcName,VpcId,VSwitchIds" rows="Vpcs.Vpc[]" .\aliyun.exe --profile CLI-exampleAK1 vpc DescribeVSwitches --output cols="VpcId,ZoneId,VSwitchId,VSwitchName" rows="VSwitches.VSwitch[]" aliyun ecs DescribeInstances --output cols="InstanceId,ImageId,InstanceName,HostName,CreationTime,SecurityGroupIds.SecurityGroupId" rows="Instances.Instance[]" --PageSize 100 aliyun ecs DescribeDisks --output cols="InstanceId,Size,Type" rows="Disks.Disk[]" --PageSize 100
上面是把每页显示从默认的10行改为100,但是默认本身就是只显示第一页。
https://www.alibabacloud.com/help/en/cli/aggregation-of-paging-interface-results
如果希望显示全部数值需要如下:
1 aliyun ecs DescribeInstances --pager
其他:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 .\aliyun.exe --profile CLI-exampleAK1 ecs DescribeSecurityGroups --output cols="VpcId,SecurityGroupId,SecurityGroupName,CreationTime" rows="SecurityGroups.SecurityGroup[]" .\aliyun.exe --profile CLI-exampleAK1 ecs DescribeSecurityGroupAttribute --SecurityGroupId sg-l4v43vk6miwlg8s0wpb0 aliyun ecs CreateSecurityGroup --RegionId ap-southeast-1 --SecurityGroupName SG-exampleName --Description "SG-Desc" --VpcId <vpcid> 加上--VpcId是因为不指定vpc则会新建vpc aliyun ecs AuthorizeSecurityGroup --RegionId ap-southeast-1 --SecurityGroupId sg-l4v46crimxpq60awehuo --IpProtocol tcp --PortRange 3389/3389 --SourceCidrIp 30.26.0.1/16 --Policy Accept --Description "Allow RDP" aliyun ecs ModifyInstanceAttribute --RegionId ap-southeast-1 --InstanceId <your_instance_id> --SecurityGroupIds.1 <your sg id > .\aliyun.exe --profile CLI-exampleAK1 ecs DescribeImages --RegionId ap-southeast-1 --ImageOwnerAlias self aliyun --profile CLI-exampleAK1 ecs DescribeImages --RegionId ap-southeast-1 --ImageOwnerAlias self --output cols="ImageId,ImageName,Size,Status" rows="Images.Image[]" aliyun.exe --profile CLI-exampleAK1 ecs DescribeImages --RegionId ap-southeast-1 --ImageOwnerAlias system aliyun --profile CLI-exampleAK1 ecs DescribeImages --RegionId ap-southeast-1 --output cols="ImageId,OSNameEn,Status,BootMode,ImageOwnerAlias" rows="Images.Image[]" aliyun --profile CLI-exampleAK1 ecs DescribeInstances --RegionId ap-southeast-1 aliyun ecs DescribeDisks --InstanceId <YourInstanceId> aliyun --profile CLI-exampleAK1 ecs CreateSnapshot --DiskId "d-yourDiskid" --SnapshotName "CopilotOS2" aliyun --profile CLI-exampleAK1 ecs CreateImage --SnapshotId s-snapshotid --ImageName "yourImageName" --Architecture x86_64 aliyun eci CreateNetworkInterface --vswitch-id vsw-t4nb3qpn2szg7e7uwj9as aliyun ecs AttachNetworkInterface --InstanceId i-t4n3jslpkf1d012jp0i5 --NetworkInterfaceId eni-t4ngcli5eva9fvooyxpd aliyun ram ListUsers aliyun ram ListAccessKeys --UserName test aliyun ram GetAccessKeyLastUsed --UserName test --UserAccessKeyId <accessKeyId> aliyun ram DeleteAccessKey --UserName test --UserAccessKeyId <accessKeyId> aliyun ram ListPoliciesForUser --UserName test aliyun ram AttachPolicyToUser --PolicyType System --PolicyName AdministratorAccess --UserName test aliyun ram ListPolicies aliyun ram ListPoliciesForUser --UserName test
CLI结果转换为Excel 以查询实例为例:
aliyun ecs DescribeInstances –output cols=”InstanceId,ImageId,InstanceName,HostName,CreationTime,SecurityGroupIds.SecurityGroupId” rows=”Instances.Instance[]” –PageSize 100
得到结果如下:
1 2 3 4 5 InstanceId | InstanceName | HostName | CreationTime | SecurityGroupIds.SecurityGroupId ---------- | ------------ | -------- | ------------ | -------------------------------- i-t4n5578u1oir6zn0oa6e | test02 | exampleHN1 | 2024-04-23T09:40Z | [sg-txxx] i-t4n43xvoens25esjb93q | launch-advisor-20240423 | exampleHN2 | 2024-04-23T08:24Z | [sg-txxx]
直接将结果复制到Excel后,使用分列,分列掉”|”, 删除第二行。然后使用Ctrl+F 替换空行“ ”为“”即可。替换空行是因为默认粘贴到Excel,开头和结尾都有很多空行。