How can you set focus to an inputbox with PowerShell? - powershell

I'm using the following PowerShell 2.0 code to grab input from a vb inputbox:
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$name = [Microsoft.VisualBasic.Interaction]::InputBox("What is your name?", "Name", "bob")
Sometimes when I run it the input box appears behind the active window. Is there a way to make the input box top most? Or an easy way to get its handle and just use setforegroundwindow?
Thanks!!

I'm not sure how to do this easily considering that the InputBox call is modal so you can't easily try to find the window handle and do a set-foreground on that window (unless you attempt to use a background job). Rather than use this VisualBasic text input box, how about a "roll your own" implementation using WPF/XAML. It is pretty easy but it does require WPF which is installed by PowerShell 2.0 if necessary.
$Xaml = #'
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window"
Title="Name" Height="137" Width="444" MinHeight="137" MinWidth="100"
FocusManager.FocusedElement="{Binding ElementName=TextBox}"
ResizeMode="CanResizeWithGrip" >
<DockPanel Margin="8">
<StackPanel DockPanel.Dock="Bottom"
Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Name="OKButton" Width="60" IsDefault="True"
Margin="12,12,0,0" TabIndex="1" >_OK</Button>
<Button Width="60" IsCancel="True" Margin="12,12,0,0"
TabIndex="2" >_Close</Button>
</StackPanel>
<StackPanel >
<Label x:Name="Label" Margin="-5,0,0,0" TabIndex="3">Label:</Label>
<TextBox x:Name="TextBox" TabIndex="0" />
</StackPanel>
</DockPanel>
</Window>
'#
if ([System.Threading.Thread]::CurrentThread.ApartmentState -ne 'STA')
{
throw "Script can only be run if PowerShell is started with -STA switch."
}
Add-Type -Assembly PresentationCore,PresentationFrameWork
$xmlReader = [System.Xml.XmlReader]::Create([System.IO.StringReader] $Xaml)
$form = [System.Windows.Markup.XamlReader]::Load($xmlReader)
$xmlReader.Close()
$window = $form.FindName("Window")
$window.Title = "My App Name"
$label = $form.FindName("Label")
$label.Content = "What is your name?"
$textbox = $form.FindName("TextBox")
$okButton = $form.FindName("OKButton")
$okButton.add_Click({$window.DialogResult = $true})
if ($form.ShowDialog())
{
$textbox.Text
}
This could be rather easily wrapped up into a Read-GuiText function.

If you set a default value for the input box it kind of makes it "modal", something like this:
$response = [Microsoft.VisualBasic.Interaction]::InputBox("Do you want to include servers in MANUAL REBOOT group ? If YES, please type: Include MANUAL reboot group","Warning!!!","")

Sub SetInputBoxFocus()
System.Threading.Thread.Sleep(300)
Microsoft.VisualBasic.AppActivate("Title)
''Console.WriteLine("Setting focus ") '"
End Sub
Dim strPW as String = ""
Dim tsStartInfo As New System.Threading.ThreadStart(AddressOf SetInputBoxFocus)
Dim tBackgroundJob As New System.Threading.Thread(tsStartInfo)
tBackgroundJob.Start()
strPW = Microsoft.VisualBasic.InputBox("Prompt: ", "Title", "", -1, -1)
tBackgroundJob = Nothing
tsStartInfo = Nothing

Related

Cannot make Powershell work for windows notification

I want to test notification in Powershell
I tried solution found on SO with https://gist.github.com/altrive/72594b8427b2fff16431
no error but no notification (I checked Background apps is on).
Then I tried this snippet (taken here https://michael-casey.com/2019/05/12/schedule-windows-notifications-with-powershell/) but I get error Exception calling "LoadXml" with "1" argument(s): "Exception from HRESULT: 0xC00CE558" and can't see how to fix it :
function test {
$app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
$Template = [Windows.UI.Notifications.ToastTemplateType]::ToastImageAndText01
$ToastTemplate = ([Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($Template).GetXml())
$ToastTemplate = #"
<toast launch="app-defined-string">
<visual>
<binding template="ToastGeneric">
<text>Prevent Eye Strain</text>
<text>Take a 20 second break</text>
</binding>
</visual>
</toast>
"#
$ToastXml = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument
$ToastXml.LoadXml($ToastTemplate.OuterXml)
$notify = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app)
$notify.Show($ToastXml)
#source: https://gist.github.com/Windos/9aa6a684ac583e0d38a8fa68196bc2dc
}

ListBox Alternating Shading PowerShell

I seem to be stuck trying to add a bit of style to my form. I have a ListBox and I want to add alternate shading to every other row. Is this even possible? I tried looking at the $ListBox.Items property and below that I don't see anything for background options. Any ideas?
$ListBox = New-Object System.Windows.Forms.ListBox
$ListBox.Size = '325,95'
$ListBox.Location = '345,25'
$ListBox.Items.Add("Checking...") > $null
The only way to do this in with the ListBox control in Windows Forms is by hijacking the actual drawing of each row.
First, change the DrawMode property of the ListBox:
$ListBox.DrawMode = [System.Windows.Forms.DrawMode]::OwnerDrawFixed
This will allow us to override graphic rendering of the items via the DrawItem event.
Now all we need is to define the function that will draw the items. I found this great example in C# on doing alternate row colors without affecting selected items.
Luckily, C# is easily ported to PowerShell:
$ListBox.add_DrawItem({
param([object]$s, [System.Windows.Forms.DrawItemEventArgs]$e)
if ($e.Index -gt -1)
{
Write-Host "Drawing item at index $($e.Index)"
<# If the item is selected set the background color to SystemColors.Highlight
or else set the color to either WhiteSmoke or White depending if the item index is even or odd #>
$color = if(($e.State -band [System.Windows.Forms.DrawItemState]::Selected) -eq [System.Windows.Forms.DrawItemState]::Selected){
[System.Drawing.SystemColors]::Highlight
}else{
if($e.Index % 2 -eq 0){
[System.Drawing.Color]::WhiteSmoke
}else{
[System.Drawing.Color]::White
}
}
# Background item brush
$backgroundBrush = New-Object System.Drawing.SolidBrush $color
# Text color brush
$textBrush = New-Object System.Drawing.SolidBrush $e.ForeColor
# Draw the background
$e.Graphics.FillRectangle($backgroundBrush, $e.Bounds)
# Draw the text
$e.Graphics.DrawString($s.Items[$e.Index], $e.Font, $textBrush, $e.Bounds.Left, $e.Bounds.Top, [System.Drawing.StringFormat]::GenericDefault)
# Clean up
$backgroundBrush.Dispose()
$textBrush.Dispose()
}
$e.DrawFocusRectangle()
})
Et voila:
By the looks of your code, you aren't using XAML, but I wanted to add this anyways as an alternative approach.
You can set this by setting up a style trigger by writing XAML as your front end code for the UI and specifying the setter properties within the trigger. Then within your ListBox control, you can specify the name of the style that you created on the ItemContanerStyle property and specify an AlertnationCount of 2 so it highlights each row with the colors you specified.
My example below shows how it works as you add text to the list box.
#Build the GUI
[xml]$xaml = #"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window" Title="Initial Window" WindowStartupLocation = "CenterScreen"
Width = "313" Height = "800" ShowInTaskbar = "True" Background = "lightgray">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel >
<StackPanel.Resources>
<Style x:Key="AlternatingRowStyle" TargetType="{x:Type Control}" >
<Setter Property="Background" Value="LightBlue"/>
<Setter Property="Foreground" Value="Black"/>
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="White"/>
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<TextBox IsReadOnly="True" TextWrapping="Wrap">
Type something and click Add
</TextBox>
<TextBox x:Name = "inputbox"/>
<Button x:Name="button1" Content="Add"/>
<Button x:Name="button2" Content="Remove"/>
<Expander IsExpanded="True">
<ListBox x:Name="listbox" SelectionMode="Extended" AlternationCount="2"
ItemContainerStyle="{StaticResource AlternatingRowStyle}"/>
</Expander >
</StackPanel>
</ScrollViewer >
</Window>
"#
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$Window=[Windows.Markup.XamlReader]::Load( $reader )
 
#region Connect to Controls
Write-Verbose "Connecting to controls"
$xaml.SelectNodes("//*[#*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach {
New-Variable -Name $_.Name -Value $Window.FindName($_.Name) -Force
}
#endregion Connect to Controls
$Window.Add_SourceInitialized({
#Have to have something initially in the collection
$Script:observableCollection = New-Object System.Collections.ObjectModel.ObservableCollection[string]
$listbox.ItemsSource = $observableCollection
$inputbox.Focus()
})
 
#Events
$button1.Add_Click({
$observableCollection.Add($inputbox.text)
$inputbox.Clear()
})
$button2.Add_Click({
ForEach ($item in #($listbox.SelectedItems)) {
$observableCollection.Remove($item)
}
}) 
$Window.ShowDialog() | Out-Null

Get Output of a PowerShell Script in a HTA

I am trying to call a powershell script from HTML Application [HTA] as :
Set WshShell = CreateObject("WScript.Shell")
Set retVal = WshShell.Exec("powershell.exe C:\PS_Scripts\test.ps1")
Where the test.ps1 just has the process count returning
return (Get-Process).Count
I want to get the output of this powershell script and then store it in a local variable or display on HTA. How can this be done ?
I tried using :
retVal.StdIn.Close()
result = retVal.StdOut.ReadAll()
alert(result)
But the printed result value is null.
Please help me how to achieve this.
This works for me:
test.ps1:
(Get-Process).Count | Out-File c:\temp\output.txt -Encoding ascii
test.hta:
<head>
<title>HTA Test</title>
<HTA:APPLICATION
APPLICATIONNAME="HTA Test"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximize"
</head>
<script language="VBScript">
Sub TestSub
Set WshShell = CreateObject("WScript.Shell")
return = WshShell.Run("powershell.exe -ExecutionPolicy Unrestricted -File test.ps1", 0, true)
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("c:\temp\output.txt", 1)
text = file.ReadAll
alert(text)
file.Close
End Sub
</script>
<body>
<input type="button" value="Run Script" name="run_button" onClick="TestSub"><p>
</body>
This is another example showing you how to get the output result in a textarea while you execute a powhershell file with a HTA !
<html>
<head>
<title>Execution a powershell file with HTA by Hackoo</title>
<HTA:APPLICATION
APPLICATIONNAME="Execution a powershell file with HTA by Hackoo"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximize"
ICON="Winver.exe"
SCROLL="no"
/>
<script language="VBScript">
Option Explicit
Sub Run_PS_Script()
ExampleOutput.value = ""
btnClick.disabled = True
document.body.style.cursor = "wait"
btnClick.style.cursor = "wait"
Dim WshShell,Command,PSFile,return,fso,file,text,Temp
Set WshShell = CreateObject("WScript.Shell")
Temp = WshShell.ExpandEnvironmentStrings("%Temp%")
Command = "cmd /c echo Get-WmiObject Win32_Process ^| select ProcessID,ProcessName,Handle,commandline,ExecutablePath ^| Out-File %temp%\output.txt -Encoding ascii > %temp%\process.ps1"
PSFile = WshShell.Run(Command,0,True)
return = WshShell.Run("powershell.exe -ExecutionPolicy Unrestricted -File %temp%\process.ps1", 0, true)
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile(Temp &"\output.txt", 1)
text = file.ReadAll
ExampleOutput.Value=text
file.Close
document.body.style.cursor = "default"
btnClick.style.cursor = "default"
btnClick.disabled = False
End Sub
</script>
</head>
<body bgcolor="123456">
<textarea id="ExampleOutput" style="width:100%" rows="37"></textarea>
<br>
<center><input type="button" name="btnClick" value="Run powershell script file " onclick="Run_PS_Script()"></center>
</body>
</html>
You can use the Exec method of WScript.Shell to avoid intermediate files. Unfortunately it opens a new window when it runs, but the code is much cleaner and gives you access to the StdOut and StdErr streams. Paste this into an .HTA file (with header and body if desired) to test:
<script language="Javascript">
var proc; //global scope
function execWithStatus(cmdLine){//Can't run minimized with Exec. Can't capture StdOut/StdErr with Run.
proc = new ActiveXObject("WScript.Shell").Exec(cmdLine);
setTimeout("writeOutLine()",100);//pause for 100 ms to allow StdOut to stream some data
proc.StdIn.Close();//must close input to complete a powershell command
}
function writeOutLine(){
if(!proc.StdErr.AtEndOfStream) {txtResults.value += "ERROR: " + proc.StdErr.ReadAll() + "\n";}
if(!proc.StdOut.AtEndOfStream) {txtResults.value += proc.StdOut.ReadLine() + "\n";writeOutLine();}
}
</script>
<textarea id=txtCmd style="width:90%" rows=1>
powershell.exe -noninteractive -command return (Get-Process).Count</textarea>
<button onclick="execWithStatus(txtCmd.value)">Run</button>
<br><textarea id=txtResults style="width:100%" rows=20></textarea>
Part of your problem may have been that Exec isn't blocking waiting for StdOut to start filling up. Adding the timer corrected that issue for me.

How to Insert Record and Upload file using the FreeASPUpload Script

I want to Insert record and upload file at the same time, right now im using FreeASPUpload Script. When i submit the form it returns this error
Cannot use the generic Request collection after calling BinaryRead
Here is the Full Source Code of my page
<%
option explicit
Response.Expires = -1
Server.ScriptTimeout = 600
Session.CodePage = 65001
%>
<!-- #include file="UploadClass.asp" -->
<%
Dim uploadsDirVar
uploadsDirVar = server.MapPath("Files_Uploaded")
function OutputForm()
%>
<form name="frmSend" method="POST" enctype="multipart/form-data" accept-charset="utf-8" action="form.asp" onSubmit="return onSubmitForm();">
<input type="hidden" name="ApplicationForm" value="Insert" />
Name: <input type="text" name="name_insert" value="" size="30" />
<B>File names:</B><br>
File 1: <input name="attach1" type="file" size=35><br>
<br>
<input style="margin-top:4" type="submit" value="Submit">
</form>
<%
end function
function TestEnvironment()
Dim fso, fileName, testFile, streamTest
TestEnvironment = ""
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(uploadsDirVar) then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
exit function
end if
fileName = uploadsDirVar & "\test.txt"
on error resume next
Set testFile = fso.CreateTextFile(fileName, true)
If Err.Number<>0 then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
exit function
end if
Err.Clear
testFile.Close
fso.DeleteFile(fileName)
If Err.Number<>0 then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."
exit function
end if
Err.Clear
Set streamTest = Server.CreateObject("ADODB.Stream")
If Err.Number<>0 then
TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."
exit function
end if
Set streamTest = Nothing
end function
function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey
Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)
' If something fails inside the script, but the exception is handled
If Err.Number<>0 then Exit function
SaveFiles = ""
ks = Upload.UploadedFiles.keys
if (UBound(ks) <> -1) then
SaveFiles = "<B>Files uploaded:</B> "
for each fileKey in Upload.UploadedFiles.keys
SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
next
else
SaveFiles = "No file selected for upload or the file name specified in the upload form does not correspond to a valid file in the system."
end if
SaveFiles = SaveFiles & "<br>Enter a number = " & Upload.Form("enter_a_number") & "<br>"
SaveFiles = SaveFiles & "Checkbox values = " & Upload.Form("checkbox_values") & "<br>"
SaveFiles = SaveFiles & "List values = " & Upload.Form("list_values") & "<br>"
SaveFiles = SaveFiles & "Text area = " & Upload.Form("t_area") & "<br>"
end function
%>
<HTML>
<HEAD>
<TITLE>Test Free ASP Upload 2.0</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
BODY {background-color: white;font-family:arial; font-size:12}
</style>
<script>
function onSubmitForm() {
var formDOMObj = document.frmSend;
if (formDOMObj.attach1.value == "")
alert("Please press the Browse button and pick a file.")
else
return true;
return false;
}
</script>
</HEAD>
<BODY>
<br><br>
<div style="border-bottom: #A91905 2px solid;font-size:16">Upload files to your server</div>
<%
Dim diagnostics
if Request.ServerVariables("REQUEST_METHOD") <> "POST" then
diagnostics = TestEnvironment()
if diagnostics<>"" then
response.write "<div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;"">"
response.write diagnostics
response.write "<p>After you correct this problem, reload the page."
response.write "</div>"
else
response.write "<div style=""margin-left:150"">"
OutputForm()
response.write "</div>"
end if
else
response.write "<div style=""margin-left:150"">"
OutputForm()
response.write SaveFiles()
response.write "<br><br></div>"
end if
%>
</BODY>
</HTML>
<!-- #include file="ADOVBS.inc" -->
<%
'=======================================================================================
' CONNECT DATABASE
'=======================================================================================
Dim objConn, objRs
Set objConn = CreateObject("ADODB.Connection")
Set objRs = CreateObject("ADODB.Recordset")
objConn.open"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& server.MapPath("db/Job_database.mdb") &";Mode=ReadWrite|Share Deny None;Persist Security Info=False"
If Request("ApplicationForm") = "Insert" Then
Set InsCom=Server.CreateObject("ADODB.Command")
InsCom.ActiveConnection=objConn
InsName = Trim(request("name_insert"))
InsName = replace(InsName,"'","''")
InsCom.CommandText = "Insert into applications(aname)Values(?)"
InsCom.Parameters.Append InsCom.CreateParameter("#name_insert", adVarChar, adParamInput, 255, InsName)
InsCom.Execute
End If
%>
I have been searching for this problem, but couldn't make it work. although what i found is that i have to use the Form Collection provided by FreeASPUpload. therefore i change
If Request("ApplicationForm") = "Insert" Then
to this
If Upload.Form("ApplicationForm") = "Insert" Then
But it also returns an error, that says: Variable is undefined: 'Upload'
If i change the Request method, it only Uploads the file not inserts the record
If Request.QueryString("ApplicationForm") = "Insert" Then
What i understands is that my insert query is in wrong place or so...
Please help me solve this problem.. thanks
I haven't used AspFreeUpload much so I'm guessing a bit here.
It would appear that using the Request object isn't an option so you're stuck with having to use the Upload.Form. As your code stands, the Upload object is only defined and set within the context of your SaveFiles function.
Try moving your database insert code to within the SaveFiles function. This would mean cutting everything from the line
Dim objConn, objRs
to
InsCom.Execute
and pasting it just before 'End Function'
You may also need to move your include adovbs.inc directive to somewhere before the function was called. The most logical place would be on the line immediately below your other include directive = for uploadclass.asp

How to use InsertAfter with PowerShell

I have some xml files where I want to insert the contents of one xml file into another. I thought I'd use LastChild and the InsertAfter method to accomplish this. So far it's not working for me.
Here is the parent.xml file:
<manifest>
<manifestExecution>
<assetDetail>
<fileAsset fileAssetGuid="parentguid1">
<parentfile1 />
</fileAsset>
<fileAsset fileAssetGuid="parentguid2">
<parentfile2 />
</fileAsset>
</assetDetail>
</manifestExecution>
</manifest>
And here is the child.xml file:
<manifest>
<manifestExecution>
<assetDetail>
<fileAsset fileAssetGuid="childguid1">
<childfile1 />
</fileAsset>
</assetDetail>
</manifestExecution>
</manifest>
What I want to do is select the fileAsset node(s) from child.xml and insert into parent.xml after the last fileAsset node in parent.xml.
Here is my test code:
$parent = [xml] (Get-Content d:\temp\parent.xml)
$parentnode = $parent.manifest.manifestExecution.assetDetail
$child = [xml] (Get-Content d:\temp\child.xml)
$childnode = $child.manifest.manifestExecution.assetDetail.InnerXml
$parentnode.InsertAfter($childnode, $parentnode.LastChild)
Here is the error msg I'm getting:
Cannot convert argument "0", with value: "<fileAsset fileAssetGuid="childguid1"> <childfile1 /></fileAsset>", for "InsertAfter" to type "System.Xml.XmlNode": "Cannot conver
t the "<fileAsset fileAssetGuid="childguid1"><childfile1 /></fileAsset>" value of type "System.String" to type "System.Xml.XmlNode"."
At line:5 char:24
+ $parentnode.InsertAfter <<<< ($childnode, $parentnode.LastChild)
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
What am I doing wrong?
You need to iterate through $childnode's children, remove them from their parent, and import them into the new document context ($child and $parent are different XmlDocument instances) before appending to $parentnode.
This will append all fileAsset nodes from $childnode into $parentnode.
$parent = [xml](get-content d:\temp\parent.xml)
$parentnode = $parent.manifest.manifestexecution.assetdetail
$child = [xml](get-content d:\temp\child.xml)
$childnode = $child.manifest.manifestexecution.assetdetail
while ($childnode.haschildnodes) {
$cn = $childnode.firstchild
$cn = $childnode.removechild($cn)
$cn = $parentnode.ownerdocument.importnode($cn, $true)
$parentnode.appendchild($cn)
}
Fortunately, most of these methods return the same XmlNode or a new version of it, so the body of the while loop could chained together like this:
$parentnode.appendchild( $parentnode.ownerdocument.importnode( $childnode.removechild( $childnode.firstchild ), $true ))
InsertAfter(newChild,referenceChild) could also work, but would be done a little differently since it also needs a reference to the the node that it will be inserted after.
your first problem is that you're not getting an XML element, but a string. You need to get an XML node from your XML document, but the shorthand method you're using is guessing you want a string. Usually you can force it by explicitly casting it over to [System.Xml.XmlElement], but that doesn't always work. You can reliably get an element using "SelectSingleNode".
You've not hit your second problem yet, but it's just around the corner. Once you've got XML, it still won't work because it's from a different XML document, so you need to "Import" the node. You'll want to tweak this to get the XML to align the way you envision, but the code works.
$parentString = #"
<manifest>
<manifestExecution>
<assetDetail>
<fileAsset fileAssetGuid="parentguid1">
<parentfile1 />
</fileAsset>
<fileAsset fileAssetGuid="parentguid2">
<parentfile2 />
</fileAsset>
</assetDetail>
</manifestExecution>
</manifest>
"#
$childString = #"
<manifest>
<manifestExecution>
<assetDetail>
<fileAsset fileAssetGuid="childguid1">
<childfile1 />
</fileAsset>
</assetDetail>
</manifestExecution>
</manifest>
"#
$parent = [xml] ($parentString)
$parentnode = $parent.manifest.manifestExecution.assetDetail
$child = [xml] ($childString)
$xpath = '/manifest/manifestExecution/assetDetail'
$childnode = $child.SelectSingleNode($xpath)
Write-Host("So the child is $($childnode.OuterXML)")
$importedNode = $parent.ImportNode($childNode,$true)
Write-Host("And after importing: $($importedNode.OuterXML)")
$parentnode.InsertAfter($importednode, $parentnode.LastChild)
Write-Host("To finally yield: $($parent.OuterXML)")
Also, you may find you can use something like your original code if you cast it to XmlElement properly.
$childnode = [System.Xml.XmlElement]$child.manifest.manifestExecution.assetDetail.InnerXml