0

I am putting together a PowerShell Script which is working, but I just need help with one tiny element if I may. Let me show you...

Script

# Update PC Descritpions.ps1
# v1.0
# J-D06-Produce
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
Import-Csv .\computer_desc.csv | ForEach {
    $OSValues = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $_.Server
    $OSValues.Description = $_.Description
    ""
    write-host "Old Description $OSValues"
    (gwmi win32_operatingsystem -computer $_.Server).description
    $OSValues.Put() >$null 2>&1
    ""
    write-host "New Description $OSValues" 
    (gwmi win32_operatingsystem -computer $_.Server).description   
}  

It loops through a CSV file to iterate new computer descriptions against computer names. I always like to improve the output in the console window for the user so its easy to see what's happening. The Current output Is very close to how I want it...have a look

Old Description \\MUNGO-BONGO\root\cimv2:Win32_OperatingSystem=@
GP-B83409-EGTON CLINIC RM 1

New Description \\MUNGO-BONGO\root\cimv2:Win32_OperatingSystem=@
test1

Old Description \\NECS0983DRTY\root\cimv2:Win32_OperatingSystem=@
GP-B83409-EGTON CLINIC RM 2

New Description \\NECS0983DRTY\root\cimv2:Win32_OperatingSystem=@
test2

Old Description \\ELITE-DESKTOP\root\cimv2:Win32_OperatingSystem=@
GP-B83409-EGTON CLINIC RM 3

New Description \\ELITE-DESKTOP\root\cimv2:Win32_OperatingSystem=@
test3 

So, I can see the PC name, the old description and what its been changed to. However if possible I want rid of this "\root\cimv2:Win32_OperatingSystem=@" to make it neater. Something similar to ...

Old Description for MUNGO-BONGO
GP-B83409-EGTON CLINIC RM 1

New Description for MUNGO-BONGO
test1

Old Description for NECS0983DRTY
GP-B83409-EGTON CLINIC RM 2

New Description for NECS0983DRTY
test2

Old Description for ELITE-DESKTOP
GP-B83409-EGTON CLINIC RM 3

New Description for ELITE-DESKTOP
test3

Many thanks in advance for any suggestions.

1 Answer 1

1

Change these

write-host "New Description $OSValues"

to this

write-host New Description for $OSValues.csname

or this

write-host New Description for $OSValues.pscomputername

If for another reason you need to use double quotes, then just surround $OSValues.csname with $( )

write-host "New Description for $($OSValues.csname)"
write-host "New Description for $($OSValues.pscomputername)"
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect, thanks kind sir. I'm learning this more now, if you get time, how do the changes work? Thanks.
So a couple of very important things to learn is how to inspect objects. If you take the $OSvalues line and run it, you can take that variable and inspect it. Try these commands out and see all the info you get. $OSvalues | Format-List * and $OSvalues | Get-Member The first will show you the properties and values, the second will show you the properties and info about the object type. You can see both csname and pscomputername are properties on the object that have the same value (the computer's name)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.