Understand CMD CLI to Powershell Variable



  • I'm not sure that is the correct way of phrasing what I wish to do. It boils down to the group of scrips I am building and have built thus far - and pushing a PS command via batch command.

    I've been using Chocolatey.org to install software, so it starts out with the Powershell script to do so.

    From there, I install my applications using simple Windows CMD batch file which then also installs Webroot via the MSI.

    The last thing I'm doing is renaming the computer using PowerShell with this command:

    powershell Rename-Computer -NewName "NiceComputerName" -DomainCredential domain\admin -Restart
    

    Right now I am having to edit the batch file for each computername - something I'm trying to get to where I can avoid.

    So I need to pass the variable or parameter from CMD to PS on prompt, so I can just right click the batch - run as Admin.

    As I'm not a strong much less basic PS user, how would that be done... A quick search shows it seems to be possible,.. just not fully understanding the context.



  • @gjacobse So basically you want to iterate through a list of computers the same script correct? So do you have a list of computers? What are other steps on your script? because what we can do is the following

    *$computers = import-csv -Path "c:\script\computers.csv" foreach ($oldname in $computers){ Rename-Computer -NewName $newname -DomainCredential domain\admin -Restart}

    This assumes you have a CSV file with a oldname and new name columns with computer names.