I think I am overcomplicating this, or missing something really obvious. A
script I wrote last year stopped working a month or two ago and I have
pinpointed the cause. One of the functions cannot be accessed and I believe it
is scope related. When I wrote it, I ran across an issue and just put $global:
on everything, I should have taken the time to understand each scope and
properly write it, but alas I didn't. Now I think it may be causing an issue.
Where it fails is at the very bottom in my if statement, $global:printerinstall
cannot be found. The ISE also tells me the -printerip parameter on
$global:printerlist also cannot be found.
Thoughts?
Here are the main parts (not the entire script is posted):
function global:PrinterList {
Param(
[string]$global:printerip
)
}
function global:PrinterInstall {
$global:printerlist -printerip $global:dataip
}
if ($printerarray -eq $null -or $printerarray -eq "") {
write-warning "No printers found!"
} else {
foreach ($port in $printerarray) {
if ($port -like "IP_*") {
$port = $port.replace("IP_","")
$global:dataip = $port
write-host "$global:dataip"
} elseif ($port -eq $null -or $port -eq "") {
write-host "Portname is invalid!"
} elseif ($port -notlike "*.*.*.*") {
if (Test-Connection $port -count 1 -ErrorAction SilentlyContinue) {
$port = (Test-Connection $port -count 1).protocoladdress
$global:dataip = $port
write-host "$global:dataip"
} else {
write-error "Portname is invalid!"
}
} else {
$global:dataip = $port
write-host "Port: $global:dataip"
}
$global:printerinstall
}
}
Daniel Ratliff
The information transmitted is intended only for the person or entity to which
it is addressed
and may contain CONFIDENTIAL material. If you receive this
material/information in error,
please contact the sender and delete or destroy the material/information.
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1