title: How to get a specific path with PowerShell
body: <p>I am very new using powershell, I would like to do the following script:</p>
  
  <pre><code>Copy-Item -Path args[0]\index.html -Destination args[0]\print.html
  Get-Content args[0]\print.html | %{$_ -replace "root","print"}
  </code></pre>
  
  <p>What I want to do is to make a copy of <code>index.html</code> and call it <code>print.html</code>.
  then I want to get the content of that <code>print.html</code> (at the same path as above) and replace all "root" for "print".</p>
  
  <p>The problem I have is that PowerShell doesn't recognize args[0] with <code>Get-Content</code>, so I need a way to pass that path dynamically and not hardcoded as the path might change depending of the user.</p>
  
  <p>This is the error:</p>
  
  <pre>
  Get-Content : An object at the specified path args[0]\print.html does not
  exist, or has been filtered by the -Include or -Exclude parameter.
  At C:\Users\Gabriel\Documents\officine\prepare-print-page.ps1:2 char:1
  + Get-Content args[0]\print.html | %{$_ -replace "root","print"}
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (System.String[]:String[]) [Get-Content], Exception
      + FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.GetContentCommand
  </pre>
  
  <hr>
  
  <p>Update:</p>
  
  <p>OK, sorry I was not very clear, I have seen other stackoverflow post and I found about param so now my script look like this:</p>
  
  <pre><code>param ([string]$path)
  Copy-Item $path\index.html -Destination $path\print.html
  Get-Content $path\print.html | %{$_ -replace "root","print"}
  </code></pre>
  
  <p>and on my js file when I build my app I pass the argument like this:</p>
  
  <pre><code>`prepare-print-page.ps1 ${outputPath}`
  </code></pre>
  
  <p>the outputPath variable holds the path where the index.html is, which looks like this: C:\Users\Gabriel\Documents\myapp\build</p>
  
  <p>but it not copying and creating the print.html, I am basically trying to do the same as this bash file:</p>
  
  <pre><code>#!/bin/bash
  
  # Duplicate the index page (which contains all the React scripts) and
  # rename the id of the main element from "root" to "print". index.jsx
  # will then render the correct component.
  
  echo "Generating print.html in directory $1 ..."
  cp $1/index.html $1/print.html
  sed -i.bak 's/id="root"/id="print"/g' $1/print.html
  rm $1/print.html.bak
  </code></pre>