Powershell script to create a file


hello,

i need come powershell script create file gets imported application. found vb version of script, it's limited , need have input file script calls csv file or excel file need import more servername, need have connectionname specified, description, , folder.
here link thread vb script , below vbscript code, can me out? have no idea how this..

http://forum.visionapp.de/showthread.php?tid=193

************************
'*************'set basic scripting objects****************************
'option explicit

dim objshell, objfso, objwshnetwork
dim computername, username, userdomain, scriptname, scriptnamefull

set objshell = createobject("wscript.shell")
set objfso = createobject("scripting.filesystemobject")
set objwshnetwork = createobject("wscript.network")

computername = objwshnetwork.computername
username = objwshnetwork.username
userdomain = objwshnetwork.userdomain
scriptname = wscript.scriptname
scriptnamefull = wscript.scriptfullname
'*********************************************************
'define , set object visionapp vrd file - imported desired folder within visionapp
strlogfile= "c:\temp\server_import_visionapp.vrd"
set objlogfile = objfso.createtextfile(strlogfile)

'set servers.txt file list of servernames & write initial ine out output vrd file
const forreading = 1
set objtextfile = objfso.opentextfile ("c:\scripts\servers.txt", forreading)
mystring = "<?xml version=""1.0"" encoding=""utf-16""?>" & vbcrlf & "<vrdconfigurationfile>"
objlogfile.writeline mystring
mystring =""

'loop , following every line in servers.txt file - create connection every server in servers.txt
do until objtextfile.atendofstream
strline = objtextfile.readline
mystring = mystring & vbcrlf & "<connection name= """ & strline & """ servername=""" & strline & """>"
mystring = mystring & vbcrlf & "<description>" & strline & "</description>"
mystring = mystring & vbcrlf & "<credentials>00000000-0000-0000-0000-000000000000</credentials>"
mystring = mystring & vbcrlf & "<audio>false</audio>"
mystring = mystring & vbcrlf & "<autosize>true</autosize>"
mystring = mystring & vbcrlf & "<console>false</console>"
mystring = mystring & vbcrlf & "<inheritcredentials>true</inheritcredentials>"
mystring = mystring & vbcrlf & "<localdrives>true</localdrives>"
mystring = mystring & vbcrlf & "<printer>false</printer>"
mystring = mystring & vbcrlf & "<resolutionx>1024</resolutionx>"
mystring = mystring & vbcrlf & "<resolutiony>768</resolutiony>"
mystring = mystring & vbcrlf & "<serial>false</serial>"
mystring = mystring & vbcrlf & "<smartcard>false</smartcard>"
mystring = mystring & vbcrlf & "<port>3389</port>"
mystring = mystring & vbcrlf & "<separatewindow>false</separatewindow>"
mystring = mystring & vbcrlf & "</connection>"

objlogfile.writeline mystring
mystring = ""
loop
'write out final line in vrd file , close out
objlogfile.writeline "</vrdconfigurationfile>"
objlogfile.close

wscript.echo "done"

this should work (tested little no errors)

$log = "c:\temp\server_import_visionapp.vrd" @" <?xml version="1.0" encoding="utf-16"?> <vrdconfigurationfile> "@ | out-file $log {foreach ($computer in (get-content "c:\scripts\servers.txt")) { @" <connection name= "$computer" servername="$computer"> <description>$computer</description> <credentials>00000000-0000-0000-0000-000000000000</credentials> <audio>false</audio> <autosize>true</autosize> <console>false</console> <inheritcredentials>true</inheritcredentials> <localdrives>true</localdrives> <printer>false</printer> <resolutionx>1024</resolutionx> <resolutiony>768</resolutiony> <serial>false</serial> <smartcard>false</smartcard> <port>3389</port> <separatewindow>false</separatewindow> </connection>  "@ | out-file -append $log } "</vrdconfigurationfile>" | out-file -append $log}.invoke() write-host ("done!") -foregroundcolor green -backgroundcolor black


boe prox

please remember mark best solution answer using mark answer. if find solution helpful, please use vote helpful.

looking script? check out script repository
need script written you? submit request @ script request page



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

more indexes

ActiveDirectory

Virtual Channel