import boto3
client = boto3.client('workspaces')
folder = input('directoryId> ')
workspaces = client.describe_workspaces()['Workspaces']
directoryIds = [workspaces['DirectoryId']for workspaces in workspaces]
directoryIds.sort()
for DirectoryIds in folder:
print(workspaces)
##----------------CSV Writer Code----------------##
import csv
#with open('workspacesdata.csv', 'w', newline='') as csvfile:
with open('workspacesdata.csv', 'w') as fp:
print('created', workspaces)
datawriter = csv.writer(csvfile,dialect='excel')
fieldnames=['WorkspaceId', 'DirectoryId', 'UserName', 'IpAddress','State', 'BundleId', 'SubnetId','ComputerName','VolumeEncryptionKey' , 'WorkspaceProperties','RunningMode']
datawriter = csv.DictWriter(fp, fieldnames=fieldnames)
datawriter.writeheader()
##----------------CSV Reader Code----------------##
import os
os.system('start excel.exe workspacesdata.csv')
Error:
File "d:\Users\imatt010\Desktop\vpc.py", line 21, in <module>
datawriter = csv.writer(csvfile,dialect='excel')
NameError: name 'csvfile' is not defined
Output:
D:/Users/imatt010/AppData/Local/Programs/Python/Python310/python.exe d:/Users/imatt010/Desktop/vpc.py
directoryId> d-92672c44a1
[{'WorkspaceId': 'ws-0gsp8c21g', 'DirectoryId': 'd-92671ccf44', 'UserName': 'msand149', 'IpAddress': '10.113.98.195', 'State': 'AVAILABLE', 'BundleId': 'wsb-wvlsl0kmt', 'SubnetId': 'subnet-0acf167ed5eaf8207', 'ComputerName': 'EC2AMAZ-72US9NV', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/7bd71746-a7ab-4d91-99dc-367218580a72', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-w48symlvx', 'DirectoryId': 'd-92672eca2c', 'UserName': 'fepps005', 'IpAddress': '10.159.248.251', 'State': 'AVAILABLE', 'BundleId': 'wsb-8vbljg4r6', 'SubnetId': 'subnet-08c10fc6c56006f5c', 'ComputerName': 'WSAMZN-DRDQV134', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/6ea5ddec-f663-4a66-a850-a61f85836cb7', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 50, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-4l4j8kw71', 'DirectoryId': 'd-92672c44a1', 'UserName': 'eliba005', 'IpAddress': '10.159.250.43', 'State': 'AVAILABLE', 'BundleId': 'wsb-8vbljg4r6', 'SubnetId': 'subnet-0eb119c83fcd876b5', 'ComputerName': 'WSAMZN-JM97ED2F', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/b8c6cee2-6eeb-441e-bc8e-d8b8c5469738', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 100, 'ComputeTypeName': 'PERFORMANCE'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-561h0qt8y', 'DirectoryId': 'd-92671ce35c', 'UserName': 'jbusa003', 'IpAddress': '10.113.90.44', 'State': 'AVAILABLE', 'BundleId': 'wsb-9mw5qstcj', 'SubnetId': 'subnet-055c1fd5f0f78926a', 'ComputerName': 'EC2AMAZ-EC8RJR6', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/c0bf7254-4ed0-49db-b068-aa35aead1569', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-91hbn4hwv', 'DirectoryId': 'd-92672ca3ab', 'UserName': 'nflow005', 'IpAddress': '10.159.250.211', 'State': 'AVAILABLE', 'BundleId': 'wsb-b31hkn0hd', 'SubnetId': 'subnet-0bd2f24ad8422306f', 'ComputerName': 'WSAMZN-UI44V8J4', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/520f7329-1a6c-47f9-82ec-37da09216d81', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'PERFORMANCE'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-xvx82z7z8', 'DirectoryId': 'd-92672ca3ab', 'UserName': 'gslag001', 'IpAddress': '10.159.250.232', 'State': 'AVAILABLE', 'BundleId': 'wsb-b31hkn0hd', 'SubnetId': 'subnet-0bd2f24ad8422306f', 'ComputerName': 'WSAMZN-M5LJQOSM', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/520f7329-1a6c-47f9-82ec-37da09216d81', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'PERFORMANCE'}, 'ModificationStates': []}, {'WorkspaceId':
'ws-jl99sthlm', 'DirectoryId': 'd-92671ce35c', 'UserName': 'gorig004', 'IpAddress': '10.113.92.145', 'State': 'AVAILABLE', 'BundleId': 'wsb-9mw5qstcj', 'SubnetId': 'subnet-0df248a17a13690bb', 'ComputerName': 'EC2AMAZ-B9HGV8L', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/e2cf9e85-13aa-4129-b35e-29be08d4a8c9', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-9q0yp939t', 'DirectoryId': 'd-92672eca2c', 'UserName': 'vjone045', 'IpAddress': '10.159.248.126', 'State': 'AVAILABLE', 'BundleId': 'wsb-b31hkn0hd', 'SubnetId': 'subnet-08c10fc6c56006f5c', 'ComputerName': 'WSAMZN-20ISH4MP', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/6ea5ddec-f663-4a66-a850-a61f85836cb7', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-xq2qdvgt1', 'DirectoryId': 'd-92671ce35c', 'UserName': 'mbaoi001', 'IpAddress': '10.113.91.107', 'State': 'AVAILABLE', 'BundleId': 'wsb-9mw5qstcj', 'SubnetId': 'subnet-055c1fd5f0f78926a', 'ComputerName': 'EC2AMAZ-PFE6K8C', 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-gqqf4jbx0', 'DirectoryId': 'd-92671ce35c', 'UserName': 'rroge011', 'IpAddress': '10.113.92.84', 'State': 'AVAILABLE', 'BundleId': 'wsb-8vbljg4r6', 'SubnetId': 'subnet-0df248a17a13690bb', 'ComputerName': 'WSAMZN-SJA7ICMM', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/e2cf9e85-13aa-4129-b35e-29be08d4a8c9', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 50, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-b2hbfj6pp', 'DirectoryId': 'd-92671ce35c', 'UserName': 'simal001', 'IpAddress': '10.113.90.222', 'State': 'AVAILABLE', 'BundleId': 'wsb-9mw5qstcj', 'SubnetId': 'subnet-055c1fd5f0f78926a', 'ComputerName': 'EC2AMAZ-DF2QICP', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/e2cf9e85-13aa-4129-b35e-29be08d4a8c9', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-83p69rk1d', 'DirectoryId': 'd-92671dad88', 'UserName': 'crex001', 'IpAddress': '10.113.48.134', 'State': 'AVAILABLE', 'BundleId': 'wsb-hsqhwwxjz', 'SubnetId': 'subnet-056af6011ea8e94fe', 'ComputerName': 'EC2AMAZ-O889V6D', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/225c3919-c904-4c4c-88b2-b8aff6a3c2e5', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-327hd6ftk', 'DirectoryId': 'd-92672738e7', 'UserName': 'msher032', 'IpAddress': '10.159.24.64', 'State': 'AVAILABLE', 'BundleId': 'wsb-362t3gdrt', 'SubnetId': 'subnet-0c63e957', 'ComputerName': 'WSAMZN-NE8FC4O5', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/6ea5ddec-f663-4a66-a850-a61f85836cb7', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 50, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-xph652g88', 'DirectoryId': 'd-92671dae7d', 'UserName': 'fsier010', 'IpAddress': '10.113.46.198', 'State': 'AVAILABLE', 'BundleId': 'wsb-hsqhwwxjz', 'SubnetId': 'subnet-071e647325ac3750d', 'ComputerName': 'EC2AMAZ-PFV4FFG', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/225c3919-c904-4c4c-88b2-b8aff6a3c2e5', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-fqtph8155', 'DirectoryId': 'd-92671ce35c', 'UserName': 'jduad002', 'IpAddress': '10.113.93.199', 'State': 'AVAILABLE', 'BundleId': 'wsb-9mw5qstcj', 'SubnetId': 'subnet-0df248a17a13690bb', 'ComputerName': 'EC2AMAZ-LA5QENM', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/c0bf7254-4ed0-49db-b068-aa35aead1569', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-k4yx85xw2', 'DirectoryId': 'd-92671ce35c', 'UserName': 'jdela455',
'IpAddress': '10.113.91.29', 'State': 'AVAILABLE', 'BundleId': 'wsb-9mw5qstcj', 'SubnetId': 'subnet-055c1fd5f0f78926a', 'ComputerName': 'EC2AMAZ-ROUT3HC', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/e2cf9e85-13aa-4129-b35e-29be08d4a8c9', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-36n767rfc', 'DirectoryId': 'd-926728f384', 'UserName': 'amelg005', 'IpAddress': '10.159.16.192', 'State': 'AVAILABLE', 'BundleId': 'wsb-8vbljg4r6', 'SubnetId': 'subnet-712b3a38', 'ComputerName': 'WSAMZN-DFNFQ2FN', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/6ea5ddec-f663-4a66-a850-a61f85836cb7', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 50, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-bz46m2bsr', 'DirectoryId': 'd-92671ccf44', 'UserName': 'amonr018', 'IpAddress': '10.113.98.6', 'State': 'AVAILABLE', 'BundleId': 'wsb-wvlsl0kmt', 'SubnetId': 'subnet-00bc82572544985a2', 'ComputerName': 'EC2AMAZ-NKJ1JJP', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/7bd71746-a7ab-4d91-99dc-367218580a72', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-kctzpvr7l', 'DirectoryId': 'd-92671ce35c', 'UserName': 'ttrum003', 'IpAddress': '10.113.93.73', 'State': 'AVAILABLE', 'BundleId': 'wsb-9mw5qstcj', 'SubnetId': 'subnet-0df248a17a13690bb', 'ComputerName': 'EC2AMAZ-7NTK35R', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/c0bf7254-4ed0-49db-b068-aa35aead1569', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-3f6z05rgx', 'DirectoryId': 'd-92671ce35c', 'UserName': 'krafi003', 'IpAddress': '10.113.90.39', 'State': 'AVAILABLE', 'BundleId': 'wsb-9mw5qstcj', 'SubnetId': 'subnet-055c1fd5f0f78926a', 'ComputerName': 'EC2AMAZ-5OKBEUQ', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/e2cf9e85-13aa-4129-b35e-29be08d4a8c9', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-2ptlkm5qv', 'DirectoryId': 'd-92671ce35c', 'UserName': 'mdomi077', 'IpAddress': '10.113.91.208', 'State': 'AVAILABLE', 'BundleId': 'wsb-9mw5qstcj', 'SubnetId': 'subnet-055c1fd5f0f78926a', 'ComputerName': 'EC2AMAZ-T18AKN8', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/c0bf7254-4ed0-49db-b068-aa35aead1569', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-6bw7svsnp', 'DirectoryId': 'd-92672c445d', 'UserName': 'arico027', 'IpAddress': '10.159.250.248', 'State': 'AVAILABLE', 'BundleId': 'wsb-b31hkn0hd', 'SubnetId': 'subnet-0bd2f24ad8422306f', 'ComputerName': 'WSAMZN-T8VRNFTT', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/95d05f8e-7e21-4852-8cb8-f4a8505d8110', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-08h9cjkvt', 'DirectoryId': 'd-92670ed06d', 'UserName': 'vsanc079', 'IpAddress': '10.113.81.161', 'State': 'AVAILABLE', 'BundleId': 'wsb-35gdsrk4x', 'SubnetId': 'subnet-04f8860f4dbcbb4e4', 'ComputerName': 'WSAMZN-J6IHDJ93', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/bef5e0aa-2c8f-4b2d-8c31-9456e5de18ce', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 10, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-h6vs896fs', 'DirectoryId': 'd-92672c44a1', 'UserName': 'achoa004', 'IpAddress': '10.159.250.36', 'State': 'AVAILABLE', 'BundleId': 'wsb-gm4d5tx2v', 'SubnetId': 'subnet-0eb119c83fcd876b5', 'ComputerName': 'WSAMZN-JOSCE5IC', 'VolumeEncryptionKey': 'arn:aws:kms:us-west-2:336694646358:key/95d05f8e-7e21-4852-8cb8-f4a8505d8110', 'UserVolumeEncryptionEnabled': True, 'RootVolumeEncryptionEnabled': True, 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 100, 'ComputeTypeName': 'PERFORMANCE'}, 'ModificationStates': []}, {'WorkspaceId': 'ws-b1t8zwt6b', 'DirectoryId': 'd-926728fc2c', 'UserName': 'drahu001', 'IpAddress': '10.159.24.21', 'State': 'AVAILABLE', 'BundleId': 'wsb-8vbljg4r6', 'SubnetId': 'subnet-0c63e957', 'ComputerName': 'IP-C0A8D2AA', 'WorkspaceProperties': {'RunningMode': 'ALWAYS_ON', 'RootVolumeSizeGib': 80, 'UserVolumeSizeGib': 50, 'ComputeTypeName': 'STANDARD'}, 'ModificationStates': []}]