Ask for Input and Use Input in the Next Command

Hi Everyone,

I am not very god at scripting and need a bit of your help.

I have a command hat I plan on using to get a remote computesr's OS version and installed patches. 

I can use a txt file with the computer name to be queried, but I thought it would be even easier for the batch file to ask me for input so I enter the computer name and once I enter it, it uses it for the next command.

Here is the code I have so far:

@echo off

set /p CompName= Enter name of computer? %Compname% > c:\computers.txt

wmic  /node:@c:\computers.txt  os get Caption,CSDVersion /value /format:htable >> C:\OSnPatches.htm  & wmic /node:@c:\computers.txt qfe list full /format:htable >> C:\OSnPatches.htm


Can you help me get the CompName variable be used in the WMIC query?

Thanks in advance,

S

August 31st, 2015 12:35pm

Batch files are obsolete. You should be using PowerShell.

wmic  /node:%compname% ...

 

Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 12:45pm

Batch files are obsolete. You should be using PowerShell.

wmic  /node:%compname% ...

 save it as a PS1, I get it. Any help with the code?

August 31st, 2015 12:55pm

There are numerous resources available to you to find pre-written scripts.

For example, there is a Repository link right at the top of this page.

Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 1:36pm

There are numerous resources available to you to find pre-written scripts.

For example, there is a Repository link right at the top of this

August 31st, 2015 2:03pm

Thanks, i have already spent 2 days searching for something I do not need to write from scratch, and the repository doesn ot contain what I am looking for.

Do you actually have further questions (if so, you'll need to start a new thread)? Yours has already been answered.

I also highly recommend that you drop batch and do all further work in PowerShell.

Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 2:09pm

Batch files are obsolete. You should be using PowerShell.

wmic  /node:%compname% ...

 save it as a PS1, I get it. Any help with the code?

August 31st, 2015 2:17pm

Thanks, i have already spent 2 days searching for something I do not need to write from scratch, and the repository doesn ot contain what I am looking for.

It is usually rare to find a pre-written script that meets your exact specifications.

In these cases, you will need to look for examples of scripts that do things like what you want, and then customize to your specifications.

The purpose of this forum to answer scripting questions, not to deliver pre-written scripts to requested specifications. If you need for someone to write code for you, it would be appropriate to pay a consultant.

Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 3:26pm

Thank. I'm just starting to learn, but got a task to do this stuff. Will need to learn faster, it seems.
September 1st, 2015 4:35am

Here is what I got trying to put together a script to read the patches on a remote PC:

$computer = gc env:computername
$computers= get-content -path c:\computer.txt
$csvfile = "c:\name.csv"
foreach ($computer in $computers) {Get-WmiObject -Class WIN32_QuickFixEngineering | Select-Object "Caption","CSName","Description","InstalledBy","InstalledOn" |ConvertTo-HTML | Out-File $csvfile}

I do get the results, but I get them from the local machine and not the remote one. What am I doing wrong trying to get the computer name from the c:\computer.txt file?

Thanks again for the help.

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 7:27am

You need to use the -ComputerName parameter of Get-WmiObject.

http://ss64.com/ps/get-wmiobject.html

September 1st, 2015 7:43am

Thank. I'm just starting to learn, but got a task to do this stuff. Will need to learn faster, it seems.

There is no such thing as learning faster.  Learning is a biochemical process that operates according to the laws of chemistry and physics.  You can only be healthy and study carefully.  The learning happens at its own pace.

Trying to jam 10 pounds into a 5 pound bag never works.

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 7:56am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics