|
Mostrar Mensajes
|
Páginas: [1] 2 3
|
1
|
Programación / Scripting / Re: Resolucion de IP y DNS - Powershell
|
en: 4 Abril 2013, 16:51 pm
|
Solucion : Si alguien esta interesado $computers= Get-Content C:\sql.txt $list = @()
Foreach ($computername in $computers) { If(Test-Connection $computername -Quiet) {
write-host "$computername - $IP - OK" -ForegroundColor GREEN Try { $IP = [System.Net.Dns]::GetHostEntry($computername).AddressList | %{$_.IPAddressToString} $IP | %{$HostName = [System.Net.Dns]::GetHostEntry($_).HostName} }
Catch { write-error "NO se puede resolver el IP o DNS." }
$compStatus = New-Object PSObject -Property @{ Equipo = $computername Status = $true DNS = $HostName IP = $IP } $list += $compStatus
}
Else { write-host "$computername - $IP - NO_OK" -ForegroundColor RED $IP = $null $HostName = $null $compStatus = New-Object PSObject -Property @{ Equipo = $computername Status = $false DNS = $null IP = $null } $list += $compStatus
} } $list | Export-Csv c:\prueba2.csv -NoTypeInformation
|
|
|
2
|
Programación / Scripting / Resolucion de IP DNS VBSCRIPT
|
en: 4 Abril 2013, 16:48 pm
|
Buenas tardes, Tengo un problema, bueno uno de muchos. Ahora el problema va por VBSCRIPT planteo el requerimiento. Tengo que realizar informacion de un una relacion de maquinas las cuales tengo que hacr ping y tengo que resolver el IP y que resuelve el DNS. Hostname IP PING DNS MyPc 127.0.0.1 OK MyPC.Dominio.com Mypc2 127.0.0.2 NO_OK No register host Esta informacion pasarlo a un CSV. Pero tambien necesito trabajar con los equipos por separado es decir que me saque un log por separado de los equipos que hacen ping y los que no. esto esta en un TXT. si alguien me puede ayudar se lo agradecería adjunto el codigo. Dim strComputerName, ScriptPath, OnlineFileName, OfflineFileName Dim ArgObj, OnlineFile, OfflineFile, oInputFile, InputFileName Dim ReadLineArray(3000), a, b, c, Temp
Const ForAppending = 8 Const ForReading = 1 Const ForWriting = 2 Const ReadTheFile = False Const CreateTheFile = True
' Valores de Formato Const ASCII = 0 Const UniCode = -1 Const Default = -2
Set oFSO = CreateObject("Scripting.FileSystemObject") Set objShell = WScript.CreateObject("WScript.Shell")
' ******************** Declaracion de Varibles ********************
' Declaracion de nombre de archivos '********************************************************************* FilePath=CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
Set ArgObj = WScript.Arguments If WScript.Arguments.count > 0 Then InputFileName = UCase(ArgObj(0)) Else InputFileName = FilePath & "\IP_List.txt" End If
OnlineFileName = FilePath & "\OnlineSystems.txt" OfflineFileName = FilePath & "\OfflineSystems.txt"
' Elimina los arhivos TXT Online y Offline si es que existe '********************************************************************* If oFSO.FileExists(OfflineFileName) = True Then oFSO.deletefile OfflineFileName, force End If If oFSO.FileExists (OnlineFileName) Then oFSO.deletefile OnlineFileName, force End If
' Crea los Archivos Online y Offline '********************************************************************* oFSO.CreateTextFile OnlineFileName, CreateTheFile oFSO.CreateTextFile OfflineFileName, CreateTheFile
' Abre el archivo y lee el contenido '********************************************************************* Set OnlineFile=oFSO.OpenTextFile(OnlineFileName, ForWriting, ReadTheFile) Set OfflineFile=oFSO.OpenTextFile(OfflineFileName, ForWriting, ReadTheFile) Set oInputFile=oFSO.OpenTextFile(InputFileName, ForReading, ReadTheFile)
' Loop through the InputFile to get all the computer names and then check to see if they are online or not.
' Importa la informacion del archivo en el array '********************************************************************* Do while not oInputFile.AtEndOfStream a = a + 1 ReadLineArray(a) = Trim(oInputFile.ReadLine) ' Reads the line of text Loop
' Busca duplicaciones '********************************************************************* For b = 1 To a ' If data matches, then set the duplicates in the array to "" (blank) For c = (b + 1) To a If trim(ReadlineArray(b)) <> "" And trim(ReadLineArray(b)) = trim(ReadLineArray(c)) Then ' Found a duplicate! Set it to blank ReadLineArray(c) = "" End If Next Next
' Copy information into "output.txt" text file (exclude blank lines). '********************************************************************* For b = 1 To a If trim(ReadlineArray(b)) <> "" Then strComputerName = trim(ReadlineArray(b)) IsConnectible End If Next
' Cierra todos los archivos abiertos '********************************************************************* OnlineFile.close OfflineFile.close
' Let user know the program has completed its operation. wscript.echo "Finished" '*********************************************************************
Function IsConnectible
Dim objPing,objStatus ' Test to see if the remote machine is online or offline '********************************************************************* Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._ ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputerName & "'") ' Test for the status. If the system is Null or if its offline or does not exist on the network, ' then dump the results to "Offline.txt", else, dump it to "online.txt" '********************************************************************* For Each objStatus in objPing If IsNull(objStatus.ReplySize) Then ' Machine is offline --> dump the results to "Offline.txt" OfflineFile.Writeline strComputerName Else ' Machine is online --> dump the results to "Online.txt" OnlineFile.Writeline strComputerName End If Next ' Destruye las variable de memoria '********************************************************************* Set objPing=Nothing Set objStatus=Nothing
End Function
|
|
|
3
|
Programación / Scripting / Resolucion de IP y DNS - Powershell
|
en: 31 Marzo 2013, 03:15 am
|
Hola, alguien me pueda ayudar. el problema es el siguiente que una no puedo resolverlo estoy un poco estancado. Tengo que realizar un script que me resuleva el PING y DNS y toso esto escrtibirlo en un CSV. tengo hasta al momento el codigo pero aun no puedo armarlo dando tantas vueltas ya me quede un poco bloqueado. a ver si alguien mepuede ayudar gracias por todo. Saludos Clear $log = "C:\log.log" $output = @() ## Validar si el equipo hace PING $PingMachines = Get-Content "C:\sql.txt"
ForEach($MachineName In $PingMachines){
$PingStatus = Get-WmiObject Win32_PingStatus -Filter "Address = '$MachineName'" | Select-Object StatusCode #$tmp = New-Object Psobject -Property @{Name = $MachineName; Status = $PingStatus.StatusCode} If ($PingStatus.StatusCode -eq 0){ $output += = "$machines - OK" } Else{ $output += = "$machines - NO_OK" }
## Validar si el equipo resuelve el DNS $result = $null $currentEAP = $ErrorActionPreference $ErrorActionPreference = "silentlycontinue" $result = [System.Net.Dns]::GetHostbyName($MachineName) $ErrorActionPreference = $currentEAP If($Result){ $output += [string]$Result.HostName } Else{ $output += = "$machines - No HostNameFound" } } $output | Export-csv c:\export.csv -NoTypeInformation
|
|
|
4
|
Programación / Scripting / Re: [VBS] Problema al ejecutar un .EXE y crear su acceso directo
|
en: 5 Mayo 2012, 18:25 pm
|
Graciassssssssss !!!!!!!!!!!!!!! ya solucione el problema.
una consulta referente a programacion. yo estoy comenzando con esto de VBSCRIPT y POwerShell pero no me aclaro mucho eh revisado los manuales publicados por este foro y estan muy bien pero aun no logro comprender muchas cosas.
tu me puedes orientar como puedo averiguar mas o si hay algun libro en español donde pueda aprovechar a sacarle todo el provecho.
saludos
|
|
|
5
|
Programación / Scripting / Re: [VBS] Problema al ejecutar un .EXE y crear su acceso directo
|
en: 5 Mayo 2012, 17:42 pm
|
Hola. disculpa pero me sale el siguiente error, no se si esta bien lo que puse ya que en vbscript no tengo tantas nociones. el error es el siguiente. .vbs(16, 1) Error de Microsoft VBScript en tiempo de ejecución: Variable no definida: 'strComputer' y el codigo es el siguiente. '******************************************************************** Option Explicit ' Declaracion de las variables Dim Wshshell, Command Dim objShell, objDesktop, objLink 'Variables Dim strAppPath, strWorkDir, strIconPath 'Variables Dim srtComputer ' ----------------------------------------------------------' ' Ejecuta el .EXE Set Wshshell = Wscript.createObject("WScript.Shell") Command = "pspad454inst_en.exe" ' Mozilla.exe es un ejemplo como puede ser cualquier .EXE WshShell.Run Command ' Ejecuta el comando strComputer = "." Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") ''# Create an event query to be notified within 5 seconds when Firefox is closed Set colEvents = oWMI.ExecNotificationQuery _ ("SELECT * FROM __InstanceDeletionEvent WITHIN 5 " _ & "WHERE TargetInstance ISA 'Win32_Process' " _ & "AND TargetInstance.Name = 'pspad454inst_en.exe'") ''# Wait until Firefox is closed Set oEvent = colEvents.NextEvent ' Creación de Acceso Directo Aplicación ' -------------------------------------------------- strWorkDir ="z:\mozilla.exe" ' Directorio donde esta la aplicacion strAppPath = "d:\mozilla.exe" 'Ruta de la aplicación Set objShell = CreateObject("WScript.Shell") objDesktop = objShell.SpecialFolders("D:\Users\Public\Desktop") ' Acceso directo en el escritorio Set objLink = objShell.CreateShortcut(objDesktop & "\COP - Comptabilitat Organisme Pagador.lnk") ' Nombre del acceso directo ' --------------------------------------------------- 'Propiedades acceso ridercto objLink.Description = "mozilla" ' Comentario 'objLink.HotKey = "CTRL+SHIFT+X" ' Teclado de método abreviado objLink.TargetPath = strAppPath 'Ruta de la aplicación (Destino) objLink.WindowStyle = 3 objLink.WorkingDirectory = strWorkDir ' Directorio donde esta la aplicacion (Iniciar en) objLink.Save ' Guardar WScript.Quit ' Salir '********************************************************************
saludos
|
|
|
6
|
Programación / Scripting / [VBS] Problema al ejecutar un .EXE y crear su acceso directo
|
en: 5 Mayo 2012, 15:56 pm
|
Hola a todos, tengo un problema que aun no me puedo aclarar debe ser algo simple pero no da mi cabeza para mas, estoy bloqueado. El problema que tengo es el siguiente. tengo un Script que realiza lo siguiente. instala un programa el ejecutable es un .exe una vez termine de ejecutar como no te hace una acceso directo, lo genero yo. pero el problema es que realiza la primera instruccion y a la misma vez la instruccion del acceso directo. pero como aun no termina la ejecucion del .exe no puede generar el acceso directo. solo me hace la primera parte. este es el script. alguien me puede dar alguna orientacion ******************************************************************** Option Explicit ' Declaracion de las variables Dim Wshshell, Command Dim objShell, objDesktop, objLink 'Variables Dim strAppPath, strWorkDir, strIconPath 'Variables ' ----------------------------------------------------------' ' Ejecuta el .EXE Set Wshshell = Wscript.createObject("WScript.Shell") Command = "mozilla.exe" ' Mozilla.exe es un ejemplo como puede ser cualquier .EXE WshShell.Run Command ' Ejecuta el comando ' Creación de Acceso Directo Aplicación ' -------------------------------------------------- strWorkDir ="z:\mozilla.exe" ' Directorio donde esta la aplicacion strAppPath = "d:\mozilla.exe" 'Ruta de la aplicación Set objShell = CreateObject("WScript.Shell") objDesktop = objShell.SpecialFolders("D:\Users\Public\Desktop") ' Acceso directo en el escritorio Set objLink = objShell.CreateShortcut(objDesktop & "\COP - Comptabilitat Organisme Pagador.lnk") ' Nombre del acceso directo ' --------------------------------------------------- 'Propiedades acceso ridercto objLink.Description = "mozilla" ' Comentario 'objLink.HotKey = "CTRL+SHIFT+X" ' Teclado de método abreviado objLink.TargetPath = strAppPath 'Ruta de la aplicación (Destino) objLink.WindowStyle = 3 objLink.WorkingDirectory = strWorkDir ' Directorio donde esta la aplicacion (Iniciar en) objLink.Save ' Guardar WScript.Quit ' Salir ********************************************************************
Saludos y espero alguna orientacion
|
|
|
8
|
Programación / Scripting / Re: Mapeo de impresoras en red por usuarioa
|
en: 28 Abril 2011, 22:18 pm
|
Hola,
eh estado revisando y es lo que tengo hasta el momento en algo me equivoco al momento de conectar
Elimina correctamente, hace el array pero no puedo agregarlo a ver si alguien me ayuda.
Gracias por la pasciencia.
-------------------------------------------------------------------------
'Set global script objects and variables Set wshShell = WScript.CreateObject("WScript.Shell") Set wshNetwork = WScript.CreateObject("WScript.Network") Set wshObj = WScript.CreateObject("Scripting.FileSystemObject")
'Variables strNetworkPath = "C:\Copia de impresoras1.txt"
'-----------------------------------------------------------------------------' Eliminar impresora
'On Error Resume Next
Call DisconnectNetworkPrinters() MsgBox "Ejecuta asignar prn" Call ConnectPrinters(strNetworkPath, wshNetwork.computername)
Sub DisconnectNetworkPrinters() Set arPrinters = wshNetwork.EnumPrinterConnections
For i = 0 to (arPrinters.Count - 1) Step 2 If (Left(arPrinters.Item(i + 1), 2) = "\\") Then wshNetwork.RemovePrinterConnection arPrinters.Item(i + 1) End If Next End Sub
'--------------------------------------------------------------------------------' Conectar impresoras
Sub ConnectPrinters(strListFile, strCompname) Dim arrLinParts() Dim strCadTratar Set ListFile = wshObj.OpenTextFile(strListFile, 1) Do While ListFile.AtEndOfStream <> True strCadTratar = ListFile.ReadLine arrLineParts = Split(strCadTratar, Space(1)) MsgBox strCompname & " " & strCadTratar If UCase(strCompname) = UCase(arrLineParts(0)) Then For i = 0 To UBound(arrLineParts) If arrLineParts(i) <> "" Then wshNetwork.AddWindowsPrinterConnection UCase(arrLineParts(i)) End If Next If arrLineParts(1) <> "" Then wshNetwork.SetDefaultPrinter UCase(arrLineParts(1)) End If End If Loop ListFile.Close End Sub
|
|
|
9
|
Programación / Scripting / Re: Mapeo de impresoras en red por usuarioa
|
en: 28 Abril 2011, 21:00 pm
|
Hola, si lo ejecute con permisos pero el error continua lo que hice fue lo siguiente.
Eliminar impresoras de RED strComputer = "." Set WshNetwork = WScript.CreateObject("WScript.Network") Set objShell = CreateObject("Wscript.Shell") Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") For Each objPrinter in colInstalledPrinters if InStr(objPrinter.Name, "\\")> 0 then WshNetwork.RemovePrinterConnection objPrinter.Name end if Next
Ahora me falta agregarlas.
eh estado probando que leea desde un archivo plano pero no puedo lograrlo es decir tengo el siguiente txt.
ouprueba1 \\server\printer ouprueba2 \\server\printer ouprueba3 \\server\printer
quiero que leea este archivo y lo compare con las ou que tengo en el active directory si pertenece el ou comparando con el txt que agregue la impresora.
a ver si me puedes ayudar yo sigo probando y te comento mis avances.
saludos
|
|
|
|
|
|
|