Author Posts

April 1, 2017 at 3:33 am

I was hoping somebody could help me with the below script. When I use Read-Host it prompts to enter a value which is what I expect and want. The problem is I need to make a change on 80 servers and was looking for a way not to enter the IP or name 80x.
Hard coding is not an option since the info will change as the objects get updated.

I would appreciate some help.

Just want to add my skills are lacking and I am a beginner. Please be patience ......

$servers = @("server1","server2")
foreach($member in $servers){
Invoke-Command -ComputerName $member -ScriptBlock `
{
$server = hostname
$a = Read-Host -Prompt "IP"
$printerip = "$a"
$port = ([WMICLASS]“\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort”).createInstance()
$port.Name=$printerip
$port.SNMPEnabled=$false
$port.Protocol=1
$port.HostAddress=$printerip
$port.Put()
$port
$b = Read-Host -Prompt "Name"
$p=gwmi win32_printer -filter "Name='$b'"
$p.PortName= $printerip
$p.Put()
}}

April 1, 2017 at 4:13 pm


$myData = Import-Csv .\myData.csv
foreach($member in $myData){
    Invoke-Command -ComputerName $member.ServerName -ScriptBlock {
        $server = $Using:member.ServerName
        $printerip = $Using:member.IP
        $port = ([WMICLASS]“\\$($Using:member.ServerName)\ROOT\cimv2:Win32_TCPIPPrinterPort”).createInstance()
        $port.Name = $Using:member.IP
        $port.SNMPEnabled = $false
        $port.Protocol = 1
        $port.HostAddress = $Using:member.IP
        $port.Put()
        $port
        $p=gwmi win32_printer -filter "Name='$($Using:member.PrinterName)'"
        $p.PortName= $Using:member.IP
        $p.Put()
    }
}

April 1, 2017 at 9:34 pm

You could make a csv file with server,ip,name values defined, and then just iterate through that list processing your script.

IE
input.csv contains

server,ip,name
server1,10.10.1.1,printer1
server2,10.10.2.1,printer2
server3,10.10.3.1,printer3

in script

import-csv input.csv | 
ForEach-Object {
    
}

April 3, 2017 at 1:35 pm

Thank you Curtis, I appreciate the help !!!