Hi,
I need to come up with a way to show correct name for the server. For now, I would like to hard-code the server.
For example, if the Name is A,
then the name should be webserver001.
If B
then
webserver002.
This is my current command for it, but I am not sure how to add a column to represent the column names.
You should setup an alias table. It could be done numerous ways with a PSObject or in this example a hashtable. You can build a hashtable manually for reference:
If they are sequential, another approach is foregoing the alias table and reversing what I did above with subtraction versus addition to get the server number:
Get the drive (G:), split it at the semicolon into an array, get the first index (i.e. G), subtract 64 and convert the character code to an integer. Somewhat complex, but it works and no alias table is needed (seems like the coffee is working this morning):
That wasn’t part of the original requirements. Keep in mind $alias is a manually generated PSObject. You could put this data in a CSV and use Import-CSV the same way.
Can you provide what you are actually doing? What you data you are working with and the expected end results? The community is here to assist, but vague requirements will just waste time.
I need to check disk space capacity on 30 servers. Ideally using IP Addresses would work better.
I have used the following but struggle to get to custom columns to indicate info on what is hosted on each server i.e. like the previous post regarding adding a column for the domain name and the description.
They will not care if you use an IP address or DNS name for a computer. As every system is different, it’s probably simpler to not filter the partition and just pull all partitions on that server.
There an tons of examples of what you are asking for.
If a file is formatted like:
Computer1
Computer2
foreach ($computer in (Get-Content C:\Computers.txt) { $computer }
XML files is a bit ominous. Powershell can export data as XML, which can be imported using Import-CliXML. If you just want to parse XML data, there are many examples on working with XML using many methods such as XPath. You can also easily import CSV’s with Import-CSV. If you are just starting, I would lookup Month Of Lunches book by Don Jones to help with understanding Powershell fundamentals.
Yeah, basically an idea is to have a configuration file for support and system administrators to add or remove data.
I think xml looks more in order because parameter names make it easier for humans to read.
You should take a look at JSON. It is similar to XML but as you appropriately put, it is supposed to be more “human readable”. There is a ConvertTo-JSON and ConvertFrom-JSON to export and import data into Powershell respectively.