Does anyone know how to get the return value of whoami /upn into a action script parameter?
I’m trying to get the Azure username of the currently logged on user “which is their domain email address” into some action code I have to add them to the local admin group.
I know this will not work, and is simplistic attempt at this, but something like this?
There’s not a way to redirect stdout from a process into a parameter directly. Instead you’d need to use a shell to redirect the whoami output into a file, and then fill the parameter by reading the file in relevance.
Of course you shouldn’t just assume “c:\temp”. The folder might not exist, the data might be tampered by another user on the machine, etc. Instead use the tip at Tip - Action Override User settings about finding a good per-user path for the active user… except another thread here recently highlighted that profile folder of user does not work for AzureAD users, so…that maybe still needs some work, but do be careful about where you write the file (as the user) and where we read the file content (as LocalSystem)
I sometimes use a text file but often times I will write it to a registry key so that I can reference it easily without having to worry whether or not the file was deleted.
ran into a odd result on this, it worked on some machines but not others.
the problem was this line.
wait cmd /c "whoami /upn > c:\temp\whoami.txt"
it would create a empty file on some machines.
running the command manually on the same machine would populate the file fine, so this makes no sense why Bigfix running the command on some machines would not populate the file. the pipe is working because the file is being created.
thought I would mention this, in case someone else tries to use this code.
I found a work around, if I build a VB program and compile it to a .exe that does the same thing and pipes the whoami to a text file, it works.
so there is something about bigfix running the whoami command directly it does not pipe out the value to a text file, but if I run a sub process that is an exe it works.
odd thing is bigfix will work for other command pipes, like I can do a dir > sometextfile.txt and it works.