Hi all
I need some assistance. I have a few powershell script that work well, but they get a list of PC from a txt file. Using te GET-content commond. How do you create a file with the PC that it did not able to connect to or complete the task on?
Hi all
I need some assistance. I have a few powershell script that work well, but they get a list of PC from a txt file. Using te GET-content commond. How do you create a file with the PC that it did not able to connect to or complete the task on?
Daljit Phull,
Welcome to the forum.
That depends pretty much on the code you already have - please show your code.
In general:
This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.
We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.
Regardless of all that … in the vast majority of the cases you’re not the very first one with a given task. So there are pretty likely somewhere already examples of code you can easlily adapt to your particular needs. Please use your prefered internet search engine to look for some of those examples.
Thanks in advance
Thank you for the info.
The script i am currently working on is
Get-wmiobject -class win32_bios -ComputerName (Get-Content D:\PowershellScript\PC\ALLLAPTOP.txt) | select-object PSComputerName,Manufacturer,SMBIOSBIOSVersion,SerialNumber,ProductNumber,Version | export-csv -Path D:\PowershellScript\PC\PCLONout.csv -noTypeInformation
Where ALLLAPTOP is a file with all the laptop names. ideally i would like the one where i have the information delete from this file o append to another file.
Please remember to format code when sharing online. You can use the “preformatted text” button, sometimes hiding behind the gear icon.
Get-wmiobject -class win32_bios -ComputerName (Get-Content D:\PowershellScript\PC\ALLLAPTOP.txt) | select-object PSComputerName,Manufacturer,SMBIOSBIOSVersion,SerialNumber,ProductNumber,Version | export-csv -Path D:\PowershellScript\PC\PCLONout.csv -noTypeInformation
What you have here is technically a script, but I would also call it a one-liner. There’s no room for really doing anything else because you’re piping one cmdlet to another to another.
Like @Olaf said, the forum isn’t ChatGPT, we expect you to make an effort and try some things when asking for help.
This sounds like a good opportunity for you to learn a bit more about Powershell. Consider breaking up your script in to pieces. Get-Content against a text file to load all your computers in to a variable, e.g. $Computers
, and then you can use a Foreach loop to perform your Get-WmiObject action against each one.
If you want error handling you’ll want to use try/catch blocks. You can put your Get-WmiObject cmdlet inside a try/catch block and capture any errors in another variable.
Then after you’ve looped through all your machines you can have a variable of the results, and a variable of the errors, and you can write them to a file or csv as you wish.