When setting up a PowerShell component, it's important to create and store the Session object inside the component if there are going to be
multiple calls. A PowerShell session takes ~1 second to initialize before any scripts can be executed.
public ngOnInit() {{ '{' }}
this.displayCodeButtonContent = this.strings.HelloWorld.showCode;
this.psSession = this.appContextService.powerShell.createSession(this.appContextService.activeConnection.nodeName);
this.getServices();
{{ '}' }}
Once the session is created, the service is invoked, and we subscribe to the results:
/*
// The Get Services call on the "hello service" initiates a PowerShell session executes
*/
private getServices() {{ '{' }}
this.serviceSubscription = this.helloService.getService(this.psSession, 'winrm').subscribe(
(service: any) => {{ '{' }}
this.loading = false;
if (service) {{ '{' }}
this.serviceDisplayName = service.displayName;
this.serviceDefinition = service;
{{ '}' }} else {{ '{' }}
this.serviceDisplayName = this.strings.HelloWorld.notFound;
{{ '}' }}
},
(error: AjaxError) => {{ '{' }}
this.errorMessage = Net.getErrorMessage(error);
this.loading = false;
{{ '}' }}
);
{{ '}' }}