How to set environment variables in PowerShell to fetch a registered schema from Apollo Studio - graphql

I'm following Apollo Router Quickstart documentation.
I am stuck on fetching the registered schema from Apollo Studio by setting environment variables. I'm using PowerShell and since this command is for Linux it doesn't work for windows.
$ APOLLO_KEY="..." APOLLO_GRAPH_REF="..." ./router
What command should I use for windows powershell?
Thank you in advance.

You just need to do set it as,
$Env:APOLLO_KEY = "...."
$Env: APOLLO_GRAPH_REF = "...."

Related

Switching AWS profile via the AWS CLI in VS Code integrated terminal does not work

My different AWS profiles from various projects are stored in the standard config-file C:\Users\username\.aws\config.
According to the official documentation it should be as easy as executing the following commands in my integrated CMD-prompt terminal in VS Code.
setx AWS_PROFILE default
Using setx to set an environment variable changes the value in all
command shells that you create after running the command.
Next, open a new cmd-terminal session like so:
Checking the caller identity does not show what I expect to see:
aws sts get-caller-identity
An error occurred (ExpiredToken) when calling the AssumeRole
operation: The security token included in the request is expired.
Carrying out the reload window - command did also not resolve the issue:
Next thing I tried was the mere set- instead of the previous setx - command:
Using set to set an environment variable changes the value used until
the end of the current command prompt session, or until you set the
variable to a different value.
Carrying out this leads to the following output:
set AWS_PROFILE default
AWS_PROFILE=profile_name_from_other_project
Even if I delete all open (integrated) CMD-shell after using setx and opening a new one, the profile from the other project is still active:
Finally, I switched to my already open integrated bash - shell in VS Code and executed the command:
export AWS_PROFILE=default
This magically worked:
❯ aws sts get-caller-identity
{
"UserId": "A....",
"Account": "7.....",
"Arn": "arn:aws:iam::7....:user/username"
}
I'm still wondering why I cannot make it work in the integrated VS-Code CMD-terminal..

InfluxDBv2 - get a remote config working as a telegraf windows service

I'm trying to use the remote config feature of InfluxDB and Telegraf. If I set the enviroment variable with
$env:INFLUX_TOKEN = "thisIsMyToken"
and then test things with
.\telegraf.exe --config "https://influxdbserver:port/myremoteconfig" --test
it seems to be working.
When I try to install the service with
.\telegraf.exe --service install --config "https://influxdbserver:port/myremoteconfig"
the connection does not work and according to the windows event manager it can't load the config file due to "401 Unauthorized". Which is the same error I get when not setting the token before using the --test command.
I assume the problem is with the service not seeing the enviroment variable. But how can I get the variable into the service?
You can use setx, though that'll set an env var that all users on your system can view
setx /M INFLUX_TOKEN "ThisisMyToken"
credits to kittenless_tootler

How to Import-Module in Windows 2008 R2 using Puppet facter?

I'm creating a puppet custom fact using ruby script to output some AD related details. I learned the ServerManager is a prerequisite module as this is not automatically added in the Windows 2008 R2 build yet. I have manually run my powershell commands in one of my 2008 R2 servers and it worked. However, I am getting the following error everytime I run it as a puppet facter.
Appreciate your help on this. Thanks!
Successful Manually run in Windows 2008 R2 server via Powershell
Import-Module ServerManager
Script
if ( $operatingsystemrelease == '2008 R2' )
Facter::Core::Execution.execute(%q[powershell Import-Module ServerManager])
end
Error
error while resolving custom fact "mycustomfact": execution of command "powershell Import-Module ServerManager" failed: command not found.
Source: Facter
Thank you.
The method you have provided worked perfectly fine for me (I tested it with Ruby 2.5.8, 2.6.6, and 2.7.1), so there must be a deeper reasoning for this not working. Nevertheless, I have a solution. In my own personal experience with Ruby and PowerShell I have always used the ` operator which also executes a command and returns the output. For example, you could do:
if ( $operatingsystemrelease == '2008 R2' )
`powershell.exe Import-Module ServerManager`
end
If that still doesn't work, I would turn to your installation of Windows Server, specifically making sure your environment variables haven't been messed up. As unlikely and wild as things may seem sometimes, there are always those moments that can only be explained with "because windows" ;)
Check that the Powershell module exists in the target server - it wasn't available by default until 2008 R2 I believe.
It should be in a folder by the same name at:
C:\Windows\System32\WindowsPowerShell\v1.0\Modules
You also might need to use 32-bit Powershell instead of 64-bit.
Okay. So I've decided to use external facts instead. And it's working fine.
You may look at Puppet's external facts page.
Update
I managed to use ruby puppet custom facter. I removed only %q[]. Here's the script.
if ( $operatingsystemrelease == '2008 R2' )
Facter::Core::Execution.execute('powershell Import-Module ServerManager')
end

Execute bash commands on Azure Linux VM using azure automation

I need to install software on Azure VM with Ubuntu image. One way of manually doing it is ssh into the terminal using putty or other command-line tool and executing the installation bash command. Another way of doing it was by automating this by creating a bash script and calling it from Azure automation. But I unable to find a way to call the bash script from the azure automation runbooks. Kindly let me know if this is possible.
I am able to call powershell scripts because Azure Automation supports powershell by default.
I tried using the command New-SshSession and using Invoke-SshCommand to run my command but I get the below error while trying to connect to a session.
Also, what are the prerequisites for using New-SshSession (see below)?
New-SshSession -ComputerName 'ComputerName' -Username 'UserName'
Unable to create SSH client object: Exception calling ".ctor" with "4" argument(s): "Could not load type 'System.Security.Cryptography.HMACRIPEMD160' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral,
Are there any prerequisites before I should start using New-SshSession? Do I need to install any .Net library on my linux machine?
Welcome to Stack Overflow!!
If the requirement was for Windows VM then it would have been easy by leveraging Invoke-AzVmRunCommand cmdlet but as requirement is for Linux VM so looks like the comment (with sample script) provided by Azure Automation team content author in this GitHub helps you to accomplish your requirement of executing bash commands on Azure Linux VM using azure automation.
Hope this helps!!

Azure xplat to run a CustomScriptExtension in a Windows VM

I am creating Windows VMs from the azure xplat cli, using the following command:
azure network vnet create --location "East US" testnet
azure vm create --vm-name xplattest3 --location "East US" --virtual-network-name testnet --rdp 3389 xplattest3 ad072bd3082149369c449ba5832401ae__Windows-Server-Remote-Desktop-Session-Host-on-Windows-Server-2012-R2-20150828-0350 username SAFEpassword!
After the Windows VM is created I would like to execute a powershell script to configure the server. As far I understand, this is done by executing a CustomScriptExtension.
I found several examples for PowerShell but no examples for Xplat cli.
I would like, for example, to run the following HelloWorld PowerShell script:
New-Item -ItemType directory -Path C:\HelloWorld
After reading documentation I should be able to run a CustomExtensionScript by executing something like this (the following command does not work):
azure vm extension set xplattest3 CustomScriptExtension Microsoft.Compute 1.4 -i '{"URI":["https://gist.githubusercontent.com/tk421/8b7dd37145eaa8f82e2f/raw/36c11aafd3f5d6b4af97aab9ef5303d80e8ab29b/azureCustomScriptExtensionTest"] }'
I think that the problem is the parameter -i. I have not been able to find an example on Internet. There are some references and documentation such as MSDN and Github, but no examples.
Therefore, my question: How to execute a PowerShell script after creating a Windows VM in Azure using the xplat cli ?
Please note that the my current approach is a CustomScriptExtension, but anything that allows to bootstrap a configuration script will be considered!
EDIT How do I know it is failing ?
After I run the command azure vm extension ...:
xplat cli confirms that the command has been executed properly.
As per MSDN documentation, the folder C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\ is created, but there is no script downloaded to C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\{version-number}\Downloads\{iteration}
The folder C:\HelloWorld is not created, which means that the contents of the script has not been executed.
I cannot find any sort of logs or a trace to know what happened. Does anyone knows where can I find this information ?
The parameters (The Json) that I used after reading the MSDN documentation were not correct. However, you can get clues of the correct parameters by reading the C# code.
And the final command is:
azure vm extension set xplattest3 CustomScriptExtension Microsoft.Compute 1.4 -i '{"fileUris":["https://macstoragetest.blob.core.windows.net/testcontainername/createFolder.ps1"], "commandToExecute": "powershell -ExecutionPolicy Unrestricted -file createFolder.ps1" }'
This command successfully creates the C:\HelloWorld directory.
NOTE: I decided to upload the script to Azure as I read in a post and in the documentation that is mandatory. However I just made a test to download the original script from Github and it is working fine, so I guess that the documentation is a bit outdated.
EDIT: I created an detailed article that explains how to provision windows servers with xplat-cli in Azure.

Resources