Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

SOLVED Use task sequence variable in Powershell script

Status
Not open for further replies.

Charlypop2357

Member
Messages
13
Solutions
2
Reaction score
1
Points
1
Hi community,

Here is my scenario. I use a Powershell form I developped myself to set a few task sequence variables that are used later on during the OSD.
I have added another TS var which stores the user's firstname and lastname so then I set the AD computer's description attribute with the proper value.
I would like to pass that TS var in a task run as a domain user.
So far, I have created a command line task which holds that line : powershell.exe -ExecutionPolicy ByPass -File "my_pwsh_function.ps1" "Computer of `"%OSDUserID%`""
For your information - "Computer of `"%OSDUserID%`"" is the parameter passed to the function.
The question is : is that going to work?
Second question : I would like to write a more complex script so I can move the computer to the proper OU. Can I pass the TS var inside a Powershell script and have it to work?
Thank you guys for your insight.
 
Solution
I did try that option but couldn't get it to work. Once TS var is set using my form I create another task that will create a file containing the value of the computer's description. Bear in mind that both variable declaration and file creation (which contains var value) are run with system account. I create a second task (Run Powershell script) that reads the file I previously created which is run using a domain account that has proper permissions to write in AD. I use a custom Powershell script you can easily find on the web (sorry I don't have the opportunity to paste my script right now). Hope it is clear enough.
Hi Charlypop2537,
Did you get this working?
Hi mtariqkhan,

Yes I did eventually. The point was I that I was trying to get a variable's content with another user. Basically a domain account that will help me to set AD attribute 'description'. Since variable was set using SYSTEM account I was then not able to access its content using my domain account. The trick was to write the content of the variable in a file and then read this file using my domain account. And that did it!
Hope it can help you.
 
Hi mtariqkhan,

Yes I did eventually. The point was I that I was trying to get a variable's content with another user. Basically a domain account that will help me to set AD attribute 'description'. Since variable was set using SYSTEM account I was then not able to access its content using my domain account. The trick was to write the content of the variable in a file and then read this file using my domain account. And that did it!
Hope it can help you.
Hi,
Is it possible for you to share that script and command with me. I am trying to get the description input during the task sequence and update in AD by using the same command you used. It’s only updating the text %description% and not the task sequence variable value that is inputted during the task sequence.
Thanks
 
Hi,
Is it possible for you to share that script and command with me. I am trying to get the description input during the task sequence and update in AD by using the same command you used. It’s only updating the text %description% and not the task sequence variable value that is inputted during the task sequence.
Thanks
I see. I use a form to get user's first name and last name then populate a task sequence variable. You might be using a task that calls a mere MS form to get your variable populated then have the AD record amended with the value.
 
I see. I use a form to get user's first name and last name then populate a task sequence variable. You might be using a task that calls a mere MS form to get your variable populated then have the AD record amended with the value.
What I am doing is that I have created a custom task sequence variable for computer description and it pops up for the input during the task sequence. I am using this command to populate the tasks sequence variable's value in that TS variable

powershell.exe -NoProfile -ExecutionPolicy Bypass -File AddComputerDesc.ps1 %OSDComputerDescription%
I am not very good at Powershell. Is this the right way to use the TS variable with the PS Script command line?

Thanks
 
I did try that option but couldn't get it to work. Once TS var is set using my form I create another task that will create a file containing the value of the computer's description. Bear in mind that both variable declaration and file creation (which contains var value) are run with system account. I create a second task (Run Powershell script) that reads the file I previously created which is run using a domain account that has proper permissions to write in AD. I use a custom Powershell script you can easily find on the web (sorry I don't have the opportunity to paste my script right now). Hope it is clear enough.
 
Solution
Status
Not open for further replies.

Forum statistics

Threads
7,144
Messages
27,894
Members
18,191
Latest member
escdarck

Trending content

Back
Top