I have a script that turns out a UI with variable inputs and places these variables into a .txt. I need to be able to call parts of the text file into another script. IE:
Text File Reads
UserID: username
I need to separate this line and call “username” as a variable in another script so the script will read:
import-module ActiveDirectory
$id = "username"
$ADLocation = ($id.ParentContainer)
$hoou = "OU=User,OU=Office,OU=win7,DC=company,DC=corp"
get-aduser $id
Move-ADObject -Identity $ADLocation -TargetPath $hoou
Can someone help?
Can you store the variables as PowerShell variables in a .ps1 file?
Then you could simply dot-source the file:
Update: Since you can’t use PowerShell format you have to parse the input file. If the line with the user information looks like you mentioned above
you could do something like this to extract the username and assign it to a variable: