Read-Host Prompts per Server

This topic contains 3 replies, has 3 voices, and was last updated by  NewDesign 7 months, 3 weeks ago.

  • Author
    Posts
  • #67695

    NewDesign
    Participant

    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()
    }}

  • #67710

    Sam Boutros
    Participant
    
    $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()
        }
    }
    
  • #67716

    Curtis Smith
    Participant

    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 {
        
    }
  • #67777

    NewDesign
    Participant

    Thank you Curtis, I appreciate the help !!!

You must be logged in to reply to this topic.