Tag Archives: powershell

Drop SQL Server database from powershell

Questions: I have a SQL Server instance on my local computer called .\SC. I want to drop a database from that instance using a PowerShell script. I need to login with the sa user for my database. This is the code I have so far, but it doesn’t work: [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”) $srv = new-object Microsoft.SqlServer.Management.Smo.Server(“.\SC”) $conContext… Read More »

Updating XML files using PowerShell

Questions: I’m using PowerShell to update an XML directory listing for an application across a number of servers but having an issue making the actual updates. Using the following XML as an example, looking to update the filepaths with qualnas1 to use something like \GlobalNAS…etc and remove the qualnas2 entry. <?xml version=”1.0″ encoding=”UTF-8″ ?> <directory>… Read More »

Error restoring database backup to new database with smo and powershell

Questions: Taking a database backup from another server I’m trying to restore to sqlexpress on the localhost. This restore will work via the gui but I’m having issues restoring it with powershell. I get the following error message: Exception calling “SqlRestore” with “1” argument(s): “Restore failed for Server + $smoRestore.SqlRestore <<<< ($server) + CategoryInfo :… Read More »

Replacing XML nodes in PowerShell

Questions: I have two XML files (File1.xml, File2.xml). File2.xml is a subset of File1.xml. File1.xml has nodes like so: <parentnode> <item id=”GUID1″> <Text>Some Text</Text> </item> <item id=”GUID2″> <Text>Here’s some more text</Text> </item> </parentnode> File2.xml has: <parentnode> <item id=”GUID1″> <Text>Some Replacement Text</Text> </item> </parentnode> I want to take the item with GUIDx in File1.xml, and replace… Read More »

PowerShell to get attribute values from XML with multiple attributes

Questions: The following XML file is one Object node of the output from the command Get-ClusterGroup run from a 2008 R2 Failover Cluster with PowerShell 2: <?xml version=”1.0″?> <Objects> <Object> <Property Name=”Cluster”>Cluster1</Property> <Property Name=”IsCoreGroup”>False</Property> <Property Name=”OwnerNode”>Node1</Property> <Property Name=”State”>Offline</Property> <Property Name=”Name”>SAP PL1</Property> <Property Name=”Description” /> <Property Name=”PersistentState”>1</Property> <Property Name=”FailoverThreshold”>4294967295</Property> <Property Name=”FailoverPeriod”>6</Property> <Property Name=”AutoFailbackType”>1</Property> <Property Name=”FailbackWindowStart”>4294967295</Property> <Property… Read More »

Edit .XML file with Powershell, encoding

Questions: I need to edit a .xml file with powershell. The thing I need to do is to download the .xml file from the server, updated the version number, and then save it in my local computer. This is what I did. [xml]$myXML = get-content $xmlFileServer $myXML.’ivy-module’.info.revision = $newVersion $myXML.Save($newXMLFileName) Then I will have a… Read More »

PowerShell XML Output

Questions: I’m having trouble getting the desired results in the correct format with this PowerShell query when run against an XML file exported from Task Scheduler. I will eventually have this run against all Task Scheduler exported jobs dumped to the same one XML file but I’m starting with just one for now. PowerShell Logic… Read More »

Edit .XML file with Powershell, encoding

Questions: I need to edit a .xml file with powershell. The thing I need to do is to download the .xml file from the server, updated the version number, and then save it in my local computer. This is what I did. [xml]$myXML = get-content $xmlFileServer $myXML.’ivy-module’.info.revision = $newVersion $myXML.Save($newXMLFileName) Then I will have a… Read More »