7

what im trying do to, is get radarr to delete the movie requested from the web client after it moves it to the persons folder so if default path is D:\Movies\ then just log it, if it goes any where else other then D:\Movies\ then it will remove it from the Client.

looking for some guidance as i am completely new to powershell.

$movie_path = $env:radarr_moviefile_relativepath
$default_path = "D:\Movies\"

$RADARRIP="localhost"
$RADARRPORT="7878"
$RADARRAPIKEY="******"

$Logfile = "C:\Custom Scripts\Radarr.log"

Function LogWrite
{
   Param ([string]$logstring)

   Add-content $Logfile -value $logstring
}

if ($default_path == $movie_path)
{
LogWrite $movie_path $radarr_movie_id "added to server"
LogWrite " "
}
else
{
Invoke-WebRequest -Uri http://$RADARRIP:$RADARRPORT/api/movie/$radarr_movie_id" -X GET -H "X-Api-Key: $RADARRAPIKEY -k
LogWrite $movie_path $radarr_movie_id "added to server"
LogWrite $radarr_movie_id "selected movie from server"
Invoke-WebRequest -Uri http://$RADARRIP:$RADARRPORT/api/movie/$radarr_movie_id" -X DELETE -H "X-Api-Key: $RADARRAPIKEY -k
LogWrite $radarr_movie_id "movie removed from list"
LogWrite " "
}

Errors

+ Invoke-WebRequest -Uri http://$RADARRIP:$RADARRPORT/api/movie/$radarr ...
+                               ~~~~~~~~~~
Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name.
At \\WIN-TQS12RTGKSQ\Custom Scripts\radarr.ps1:29 char:31
+ Invoke-WebRequest -Uri http://$RADARRIP:$RADARRPORT/api/movie/$radarr ...
+                               ~~~~~~~~~~
Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidVariableReferenceWithDrive
user3698349
  • 89
  • 1
  • 1
  • 6

3 Answers3

12

tl;dr

  • Replace $RADARRIP:$RADARRPORT with ${RADARRIP}:$RADARRPORT (or ${RADARRIP}:${RADARRPORT}

  • Placing {...} around a variable name disambiguates it from surrounding characters, which is necessary here because : would be considered part of the name.


When you use an unquoted compound string as a command argument, PowerShell implicitly treats it as an expandable string, i.e. as if it had been passed enclosed in double quotes ("...")

This answer provides a comprehensive overview of expandable strings (string interpolation) in PowerShell.

The relevant aspect is that a : following a variable reference such as $RADARRIP is considered part of that variable reference: the part between $ and : is considered the name of a (PowerShell) drive, and what follows the : is expected to be the name or path of an item in that drive; that is, the variable reference is interpreted as an instance of PowerShell's namespace variable notation.

Therefore, PowerShell must explicitly be told that the : following $RADARRIP is not part of the variable reference, for which you have several options:

  • The most PowerShell-idiomatic option is to use {...} to delineate the variable name:
Invoke-WebRequest -Uri http://${RADARRIP}:$RADARRPORT/api/movie/$radarr_movie_id ...
  • Alternatively, use `, PowerShell's escape character, to escape the : in order to treat it as a literal, but note that this approach can fail with certain characters other than :, e.g., a, because `-escaping them could accidentally turn them into an escape sequence :
Invoke-WebRequest -Uri http://$RADARRIP`:$RADARRPORT/api/movie/$radarr_movie_id ...
  • Finally, quoting : selectively works too; however, note that such compound strings only work if the first component is unquoted (see this answer):
Invoke-WebRequest -Uri http://$RADARRIP':'$RADARRPORT/api/movie/$radarr_movie_id ...

mklement0
  • 382,024
  • 64
  • 607
  • 775
0

If you are using anaconda, this worked for me:

conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/ python3 -m pip install tensorflow

Verify install:

python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Visit: https://www.tensorflow.org/install/pip#windows-wsl2

-1

No errors, Completed had to simplify it

$movie_path = $env:radarr_movie_path
$movie_id = $env:radarr_movie_id
$movie_name = $env:radarr_movie_title

function Get-TimeStamp {

    return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)

}

Function LogWrite
{
   Param ([string]$logstring)

   Add-content $Logfile -value $logstring
}

$Logfile = "C:\Custom Scripts\Radarr.log"


if ($movie_path.contains("D:\Movies\"))
{
LogWrite "$(Get-TimeStamp) | $movie_path | $movie_id | added to server"
}
else
{
Invoke-WebRequest -Uri http://127.0.0.1:7878/api/movie/"$movie_id"?apikey=YourAPIkey -Method Delete
LogWrite "$(Get-TimeStamp) | $movie_path | $movie_id | $movie_name | movie removed from list"
}
user3698349
  • 89
  • 1
  • 1
  • 6
  • I apologize mklement0 if you do not accept people posting there finished product that could possibly help people in the future, breaking things down seeing how things work i have and will always post my completed code to share with everyone if i ask a question on a website/forum once i take all suggestions in i will post final project to encourage people to manipulate my code to benefit them – user3698349 May 05 '20 at 16:26
  • 2
    It's not a matter of _accepting_ whether you post your own answer, it's about reaching a _shared understanding_: I've tried to argue why my answer is more likely to be of use to future readers, and that it would therefore make sense to _accept it_. That doesn't preclude you posting your own answer, though - again - it seems very particular to you. What's more, your answer is confusing, since the offending `:` is no longer part of it. – mklement0 May 05 '20 at 16:56
  • 1
    In summary: -1 for posting a solution that doesn't address the original problem (as prominently reflected in the question's title), and for making confusing changes to the details of the original code. In general, the value of SO isn't in posting _complete_ solutions with aspects that are _incidental_ to the problem: it is about _focused_ questions with only as much code as necessary to describe the problem, and similarly focused answers. – mklement0 May 05 '20 at 17:02