Pregunta:
¿Es posible utilizar un archivo de configuración con un script de PowerShell?
Por ejemplo, el archivo de configuración:
#links
link1=http://www.google.com
link2=http://www.apple.com
link3=http://www.microsoft.com
Y luego llame a esta información en el script de PS1:
start-process iexplore.exe $Link1
Respuesta:
¡Muchas gracias por tu ayuda, Dennis y Tim! Tus respuestas me pusieron en el buen camino y encontré esto
AJUSTES.TXT
#from http://tlingenf.spaces.live.com/blog/cns!B1B09F516B5BAEBF!213.entry
#
[General]
MySetting1=value
[Locations]
InputFile="C:\Users.txt"
OutputFile="C:\output.log"
[Other]
WaitForTime=20
VerboseLogging=True
COMANDO POWERSHELL
#from http://tlingenf.spaces.live.com/blog/cns!B1B09F516B5BAEBF!213.entry
#
Get-Content "C:\settings.txt" | foreach-object -begin {$h=@{}} -process { $k = [regex]::split($_,'='); if(($k[0].CompareTo("") -ne 0) -and ($k[0].StartsWith("[") -ne $True)) { $h.Add($k[0], $k[1]) } }
entonces
Después de ejecutar el fragmento de código, una variable ($ h) contendrá los valores en una HashTable.
Name Value
---- -----
MySetting1 value
VerboseLogging True
WaitForTime 20
OutputFile "C:\output.log"
InputFile "C:\Users.txt"
* Para recuperar un elemento de la tabla, use el comando $h.Get_Item("MySetting1").*