@@ -487,6 +487,26 @@ pub fn get_schema(resource: &ResourceManifest, cwd: &str) -> Result<String, DscE
487487/// Error returned if the resource does not successfully export the current state
488488pub fn invoke_export ( resource : & ResourceManifest , cwd : & str , input : Option < & str > ) -> Result < ExportResult , DscError > {
489489 let Some ( export) = resource. export . as_ref ( ) else {
490+ // see if get is supported and use that instead
491+ if resource. get . is_some ( ) {
492+ info ! ( "{}" , t!( "dscresources.commandResource.exportNotSupportedUsingGet" , resource = & resource. resource_type) ) ;
493+ let get_result = invoke_get ( resource, cwd, input. unwrap_or ( "" ) ) ?;
494+ let mut instances: Vec < Value > = Vec :: new ( ) ;
495+ match get_result {
496+ GetResult :: Group ( group_response) => {
497+ for result in group_response {
498+ instances. push ( serde_json:: to_value ( result) ?) ;
499+ }
500+ } ,
501+ GetResult :: Resource ( response) => {
502+ instances. push ( response. actual_state ) ;
503+ }
504+ }
505+ return Ok ( ExportResult {
506+ actual_state : instances,
507+ } ) ;
508+ }
509+ // if neither export nor get is supported, return an error
490510 return Err ( DscError :: Operation ( t ! ( "dscresources.commandResource.exportNotSupported" , resource = & resource. resource_type) . to_string ( ) ) )
491511 } ;
492512
@@ -840,7 +860,7 @@ fn json_to_hashmap(json: &str) -> Result<HashMap<String, String>, DscError> {
840860 } ,
841861 Value :: Null => {
842862 // ignore null values
843- } ,
863+ } ,
844864 Value :: Object ( _) => {
845865 return Err ( DscError :: Operation ( t ! ( "dscresources.commandResource.invalidKey" , key = key) . to_string ( ) ) ) ;
846866 } ,
0 commit comments