Hey guys,
I have this script that selects a site from all the sites created in an IIS server:
Param($webServers,$cred) # ----------------------------------------------------------------- # --------------------------- FUNCIONES --------------------------- # ----------------------------------------------------------------- # Con esta funcion me conecto server por server en SelectSiteInAllServers Function SelectSite () { Import-Module WebAdministration $count = 1 $name = gci IIS:\Sites foreach ($n in $name) { Write-Host $count " - " $n.Name $count += 1 } Write-Host "" # Entra en un loop hasta que de una opción correcta $opt = $null while ($true) { [console]::ForegroundColor = "Yellow" $string = Read-Host -Prompt "Ingrese el número" [console]::ResetColor() if ([int]::TryParse($string, [ref]$opt) -and $opt -lt $count -and $opt -gt 0) { break } } # Verifico que la opción elegida sea la que quiero actualizar $script:env = Out-String -InputObject $name[$opt-1].Name $script:env = $script:env -replace "`n","" -replace "`r","" Write-Host "" # Write-Host "Se seleccionó el site" `'$script:env`'"." $check = Read-Host -Prompt "Presione 1 si desea proseguir, o 2 si quiere volver a elegir" If ($check = 2) { SelectSite } Write-Host "" Return $script:env } Function SelectSiteInAllServers ($webServers,$cred) { $script:res = "True" If ($script:res -ne "False") { # Creo mi conexión al server $s = New-PSSession -Name TempSession -ComputerName $webServers[0] -Credential $cred # Llamo a la función para crear los sitios $script:res = Invoke-Command -Session $s -ScriptBlock ${Function:SelectSite} # Cierro la conexión al server Remove-PSSession -Name TempSession } } # ----------------------------------------------------------------- # ---------------------------- PROCESO ---------------------------- # ----------------------------------------------------------------- CLS Write-Host "|**********************************************************|" Write-Host "|******************* Selección de Sitio *******************|" Write-Host "|**********************************************************|" Write-Host "" $test = SelectSiteInAllServers $webServers $cred Return $script:res
My problem appear when I run the recursive part of the script (this one):
If ($check = 2) { SelectSite }
Because it's telling me that it doesn't recognizes "SelectSite" as a function... It seems like a stupid error, but I can't find it! Is anyone seeing something I'm not?
My brain is going to explode over here!
Thanks!