Reputation: 1
I am trying to generate a PowerShell script that will either take a file from C:\*FOLDER*\users\
or just create a file that will have an individual information in it. Here is a snip of contents. The DB name is the item that will need to be changed.
<?xml version="1.0" encoding="UTF-8"?>
<Connections>
<Connection>
<Server>*SERVERNAME\INSTANCE*</Server>
<db>rduser1</db>
</Connection>
</Connections>
The second part would be to take the generated file and move it to C:\*FOLDER*\Users\rduser*
but to rduser 1-350. The script below is what I started on to get the file to move but unsure if it will work with a new file generated. Any help is appreciated!!
$source="C:\rfms\users\dbconnect.xml"
$target="C:\rfms\users\%username%"
foreach ($directory in $(get-childitem $target).Name)
{
$targetpath= join-path -path $target -childpath $directory
copy-item -path $source -Destination $targetpath
}
Upvotes: 0
Views: 53
Reputation: 1
I think I got it now..
$DirectoryNames=get-childitem "C:\users" -Name
foreach($directory in $DirectoryNames){
$xmlsettings = New-Object System.Xml.XmlWriterSettings
$xmlsettings.Indent = $true
$xmlsettings.IndentChars = " "
$rduser="C:\users" + $directory + "\dbconnect.xml"
$XmlWriter = [System.XML.XmlWriter]::Create($rduser, $xmlsettings)
$xmlWriter.WriteStartElement("Connections")
$xmlWriter.WriteStartElement("Connection") # <-- Start <Object>
$xmlWriter.WriteElementString("Server","OC-RFMS-SQL")
$xmlWriter.WriteElementString("db",$directory)
$xmlWriter.WriteEndElement() # <-- End <Object>
$xmlWriter.WriteEndElement() # <-- End
$xmlWriter.WriteEndDocument()
$xmlWriter.Flush()
$xmlWriter.Close()
} '
Upvotes: 0