Change VMConfig file using azure powershell - powershell

I have a vmConfig file. I want to change subnet and IP Address as I want to create a new VM out of config file in new subnet, rest all configurations no need to be changed. I can manually edit xml file content but I want to do it through powershell so that I can have an automated process for everything.
Here is the sample vmConfig xml-
<?xml version="1.0" encoding="utf-8"?>
<PersistentVM xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ConfigurationSets>
<ConfigurationSet xsi:type="NetworkConfigurationSet">
<ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
<InputEndpoints>
<InputEndpoint>
<LocalPort>5986</LocalPort>
<Name>PowerShell</Name>
<Port>64929</Port>
<Protocol>tcp</Protocol>
<Vip>191.237.20.225</Vip>
<EnableDirectServerReturn>false</EnableDirectServerReturn>
<IdleTimeoutInMinutes xsi:nil="true" />
</InputEndpoint>
</InputEndpoints>
<SubnetNames>
<string>mysubnet</string>
</SubnetNames>
<StaticVirtualNetworkIPAddress>12.13.14.15</StaticVirtualNetworkIPAddress>
<PublicIPs />
<NetworkInterfaces />
I am interested changing only IP Address and Subnet.

This is basically xml parsing using powershell. I hope this should work for you-
$path = 'C:\myFolder\XmlVM.xml'
[xml]$myXML = Get-Content $path
$myXML.PersistentVM.ConfigurationSets.ConfigurationSet.SubnetNames.string="MYNEWSUBNET"
$myXML.PersistentVM.ConfigurationSets.ConfigurationSet.StaticVirtualNetworkIPAddress="10.11.14.115"
$myXML.Save($path)

Related

Deploying communities using package.xml

I am trying to retrieve Salesforce communities names 'XXX Community' from one org into VS Code and subsequently want to deploy it into another org.
However, when I use the sfdx force:source:retrieve -u DemoMaster -x ./package.xml command, for the below package.xml file, I get the following error:
Entity of type 'CustomSite' named 'XXX_Community_Test' cannot be found
Entity of type 'SiteDotCom' named 'XXX_Community_Test1' cannot be found
Only the network and network branding elements got retrieved.
The package.xml file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>XXX Community</members>
<name>Network</name>
</types>
<types>
<members>XXX_Community_Test</members>
<name>CustomSite</name>
</types>
<types>
<members>XXX Community_Test1</members>
<name>SiteDotCom</name>
</types>
<types>
<members>cbXXX_Community</members>
<name>NetworkBranding</name>
</types>
<version>48.0</version>
</Package>
Any help appreciated!
D

Changing network configuration for all VMs in VirtualBox

I've a problem with forceing NAT mode on network cards in all VirtualBox machines. The only solution I have found is to replace the code in the configuration file located in the C:\Users\USER\VirtualBoxVMs\VirtualMachineName\VirtualMachineName.vbox.
Unfortunately, I cannot simply replace these files because each user has different settings (such as the name of the VM)
I have to replace the text in the
<Adapter>...<Adapter> tag. Doing it on one computer for one user is not a problem. I can't deal with the fact that I have to do it with a script on multiple computers for all users. So far, I've managed to do something like this, and I don't know what to do next.
$InputFiles = Get-Item "C:\Users\*\VirtualBox VMs\*\*.vbox"
$OldString = '<Adapter ...various computer-dependent variables...>
...
...
</Adapter>'
$NewString = '<Adapter ...various computer-dependent variables...>
<NAT/>
</Adapter>'
$InputFiles | ForEach {
(Get-Content -Path $_.FullName).Replace($OldString,$NewString) | Set-Content -Path $_.FullName
}
Another complication is that when saving changes, everything is saved in one file for all users, i.e. all settings from all machines on a given computer as one file.
Unfortunately, VB does not store such values in the register, which makes it very difficult. Maybe there is another, easy way?
EDIT: Sample VBox config file
<?xml version="1.0"?>
<!--
** DO NOT EDIT THIS FILE.
** If you make changes to this file while any VirtualBox related application
** is running, your changes will be overwritten later, without taking effect.
** Use VBoxManage or the VirtualBox Manager GUI to make changes.
-->
<VirtualBox xmlns="http://www.virtualbox.org/" version="1.15-windows">
<Machine uuid="{1d96510c-97ce-4671-a1df-3f08c7d2b2c7}" name="TEST" OSType="Windows7_64" snapshotFolder="Snapshots" lastStateChange="2020-05-04T09:56:34Z">
<MediaRegistry>
<HardDisks>
<HardDisk uuid="{eab23143-54ec-4f7d-822d-a56bf90a58bb}" location="TEST.vdi" format="VDI" type="Normal"/>
</HardDisks>
</MediaRegistry>
<ExtraData>
<ExtraDataItem name="GUI/FirstRun" value="yes"/>
</ExtraData>
<Hardware>
<CPU>
<PAE enabled="false"/>
<LongMode enabled="true"/>
<HardwareVirtExLargePages enabled="true"/>
</CPU>
<Memory RAMSize="2048"/>
<HID Pointing="USBTablet"/>
<Paravirt provider="Default"/>
<Display VRAMSize="18"/>
<VideoCapture fps="25" options="ac_enabled=false"/>
<RemoteDisplay enabled="false"/>
<BIOS>
<IOAPIC enabled="true"/>
</BIOS>
<USB>
<Controllers>
<Controller name="OHCI" type="OHCI"/>
<Controller name="EHCI" type="EHCI"/>
</Controllers>
</USB>
<Network>
<Adapter slot="0" enabled="true" MACAddress="MACAddress" cable="true" type="82540EM">
<NAT/>
</Adapter>
</Network>
<AudioAdapter controller="HDA" driver="DirectSound" enabled="true" enabledIn="false"/>
</Hardware>
<StorageControllers>
<StorageController name="SATA" type="AHCI" PortCount="2" useHostIOCache="false" Bootable="true" IDE0MasterEmulationPort="0" IDE0SlaveEmulationPort="1" IDE1MasterEmulationPort="2" IDE1SlaveEmulationPort="3">
<AttachedDevice type="HardDisk" hotpluggable="false" port="0" device="0">
<Image uuid="{eab23143-54ec-4f7d-822d-a56bf90a58bb}"/>
</AttachedDevice>
<AttachedDevice passthrough="false" type="DVD" hotpluggable="false" port="1" device="0"/>
</StorageController>
</StorageControllers>
</Machine>
</VirtualBox>

Update Build number in App config xml file on build pipeline

I have a build pipeline in Azure DevOps, I need to update the build number in my apconfig exe file that will be $(Build.BuildNumber).
I just tried this way:
Adding a variable name = BuildNumber value = $(Build.BuildNumber).
And in my apconfig.exe file have a key same like <add key="BuildNumber" value="1812201901" />.
Why I have tried like this way: thinking like it will update in the config file if variable name match with the key.
But it is not working. can anyone please help? I have just started in CI/CD.
Update Build number in App config xml file on build pipeline
Just like the Shayki said, using the Replace Tokens extension should be the directly way to resolve this issue.
But since you need to request to get this extension, as workaround, you could also use power shell scripts to resolve this issue, you can check below my test powershell scripts:
$currentDirectory = [IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path)
$appConfigFile = [IO.Path]::Combine($currentDirectory, 'App.config')
$appConfig = New-Object XML
$appConfig.Load($appConfigFile)
foreach($BuildNumber in $appConfig.configuration.add)
{
'name: ' + $BuildNumber.name
'BuildNumber: ' + $BuildNumber.value
$BuildNumber.value = '123456789'
}
$appConfig.Save($appConfigFile)
As result, the app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<add key="BuildNumber" value="123456789" />
</configuration>
Note: Set the powershell scripts at the same folder of the app.config file.
Hope this helps.
You can use the Replace Tokens extension and in the apconfig.exe file put this:
<add key="BuildNumber" value="__BuildNumber__" />
Configure the task to search variables with __ prefix and suffix:
Now the value will be replaced with the value of the BuildNumber variable you configured (equal to Build.BuildNumber).

Set the name of an input control in a jrxml file. Is it possible?

I'd like to set the name of an input control in the jrxml file where it is defined; is that possible?
I know how to set the name of the input control via the Repository Explorer in Jaspersoft Studio, and I know how to set the name of an input control via the Jaspersoft Server.
However, I'd like to set the name of an input control in the jrxml file so that it will be set automatically upon being published to the server. Is there a property to use, similar to the following:
<parameter name="status_date_minimum" class="java.sql.Date">
<property name="some.property.key" vhalue="Minimum Status Date"/>
<defaultValueExpression><![CDATA[java.sql.Date.valueOf(java.time.LocalDate.now().minusYears(10).withMonth(1).withDayOfMonth(1))]]></defaultValueExpression>
</parameter>
As noted by #Siddharth in comments and suggested to me by a co-worker, there is a way to specify the label for the control outside of the user interface.
JasperReports Server associates each report with an XML file that it appears to create around the time it publishes your report to the server. The XML file contains, among other information, the labels for any input controls.
For an example of the XML file, first publish your report to a location on JasperReports Server. For the purpose of this example, the report file name is report.jrxml and the location is path/to/your; JasperReports Server appears to publish your report to path/to/your/report/Main jrxml (per JasperSoft Studio Repository Explorer) or path/to/your/report (per JasperReports Server Web UI).
Second, export your report from JasperReports Server (via the Web UI or via the command line); JasperReports Server will produce a zip file with the following content:
/index.xml
/resources/path/.folder.xml
/resources/path/to/.folder.xml
/resources/path/to/your/.folder.xml
/resources/path/to/your/report.xml
/resources/path/to/your/report_files/main_jrxml.data
main_jrxml.data contains the data from report.jrxml; report.xml contains the labels for any input controls. The content of report.xml may be similar to the following:
<?xml version="1.0" encoding="UTF-8"?>
<reportUnit exportedWithPermissions="true">
<folder>/resources/path/to/your</folder>
<name>report</name>
<version>2</version>
<label>report</label>
<description></description>
<creationDate>2018-03-21T18:12:41.759-04:00</creationDate>
<updateDate>2018-03-21T18:48:35.602-04:00</updateDate>
<mainReport>
<localResource
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exportedWithPermissions="false" dataFile="main_jrxml.data" xsi:type="fileResource">
<folder>/resources/path/to/your/report_files</folder>
<name>main_jrxml</name>
<version>4</version>
<label>Main jrxml</label>
<creationDate>2018-03-21T18:12:41.759-04:00</creationDate>
<updateDate>2018-03-21T18:48:35.410-04:00</updateDate>
<fileType>jrxml</fileType>
</localResource>
</mainReport>
<inputControl>
<localResource
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exportedWithPermissions="false" xsi:type="inputControl">
<folder>/resources/path/to/your/report_files</folder>
<name>status_date_minimum</name>
<version>1</version>
<label>status_date_minimum</label>
<creationDate>2018-03-21T18:48:35.602-04:00</creationDate>
<updateDate>2018-03-21T18:48:35.602-04:00</updateDate>
<type>2</type>
<mandatory>false</mandatory>
<readOnly>false</readOnly>
<visible>true</visible>
<dataType>
<localResource exportedWithPermissions="false" xsi:type="dataType">
<folder>/resources/path/to/your/report_files/status_date_minimum_files</folder>
<name>myDatatype</name>
<version>0</version>
<label>myDatatype</label>
<creationDate>2018-03-21T18:48:35.602-04:00</creationDate>
<updateDate>2018-03-21T18:48:35.602-04:00</updateDate>
<type>3</type>
<strictMin>false</strictMin>
<strictMax>false</strictMax>
</localResource>
</dataType>
</localResource>
</inputControl>
<inputControl>
<localResource
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exportedWithPermissions="false" xsi:type="inputControl">
<folder>/resources/path/to/your/report_files</folder>
<name>status_date_maximum</name>
<version>1</version>
<label>status_date_maximum</label>
<creationDate>2018-03-21T18:48:35.602-04:00</creationDate>
<updateDate>2018-03-21T18:48:35.602-04:00</updateDate>
<type>2</type>
<mandatory>false</mandatory>
<readOnly>false</readOnly>
<visible>true</visible>
<dataType>
<localResource exportedWithPermissions="false" xsi:type="dataType">
<folder>/resources/path/to/your/report_files/status_date_maximum_files</folder>
<name>myDatatype</name>
<version>0</version>
<label>myDatatype</label>
<creationDate>2018-03-21T18:48:35.602-04:00</creationDate>
<updateDate>2018-03-21T18:48:35.602-04:00</updateDate>
<type>3</type>
<strictMin>false</strictMin>
<strictMax>false</strictMax>
</localResource>
</dataType>
</localResource>
</inputControl>
<alwaysPromptControls>true</alwaysPromptControls>
<controlsLayout>1</controlsLayout>
</reportUnit>
You may edit the content of the reportUnit/inputControl/localResource/label element to change the name of the label.
Once edited, you may import the data into the JasperReports Server. If you import through the command line, I recommend importing the directory, not the zip file - it appears that the command line import is picky about the zip format. Also, if you import through the command line, you must restart the JasperReports Server before you may run your changed report.

Powershell: XPath cannot select when element has "xmlns" tag?

I've got a very simple xml, as below:
<?xml version="1.0" encoding="utf-8"?>
<First>
<Second>
<Folder>today</Folder>
<FileCount>10</FileCount>
</Second>
<Second>
<Folder>tomorrow</Folder>
<FileCount>90</FileCount>
</Second>
<Second>
<Folder>yesterday</Folder>
<FileCount>22</FileCount>
</Second>
</First>
Then I have a powershell script to select "Folder" element:
[xml]$xml=Get-Content "D:\m.xml"
$xml.SelectNodes("//Folder")
It outputs:
#text
-----
today
tomorrow
yesterday
No problem. But if I change the xml file to add "xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to "First" like below:
<?xml version="1.0" encoding="utf-8"?>
<First xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Second>
<Folder>today</Folder>
<FileCount>10</FileCount>
</Second>
<Second>
<Folder>tomorrow</Folder>
<FileCount>90</FileCount>
</Second>
<Second>
<Folder>yesterday</Folder>
<FileCount>22</FileCount>
</Second>
</First>
Then, my powershell script outputs nothing.
Why? How to change my powershell script to support this xmlns?
Thanks a lot.
What you added is default namespace. Unlike prefixed namespace, descendant elements inherit ancestor default namespace implicitly, unless otherwise specified (using explicit prefix or local default namespace that points to different URI).
To select element in namespace, you'll need to define prefix that point to the namespace URI and use that prefix properly in your XPath, for example :
$ns = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$ns.AddNamespace("d", $xml.DocumentElement.NamespaceURI)
$xml.SelectNodes("//d:Folder", $ns)