Read-Host Prompts per Server

Welcome Forums General PowerShell Q&A Read-Host Prompts per Server

This topic contains 3 replies, has 3 voices, and was last updated by

2 years, 3 months ago.

  • Author
  • #67695

    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member

    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()
    $b = Read-Host -Prompt "Name"
    $p=gwmi win32_printer -filter "Name='$b'"
    $p.PortName= $printerip

  • #67710

    Topics: 9
    Replies: 387
    Points: 500
    Helping Hand
    Rank: Contributor
    $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
            $p=gwmi win32_printer -filter "Name='$($Using:member.PrinterName)'"
            $p.PortName= $Using:member.IP
  • #67716

    Topics: 6
    Replies: 653
    Points: 20
    Rank: Member

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

    input.csv contains


    in script

    import-csv input.csv | 
    ForEach-Object {
  • #67777

    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member

    Thank you Curtis, I appreciate the help !!!

The topic ‘Read-Host Prompts per Server’ is closed to new replies.