PSDrives, UNCs, expanding variables!

Home Forums Scripting PowerShell PSDrives, UNCs, expanding variables!

Viewing 1 post (of 1 total)
  • Author
  • #161479

    Hi Guys!

    What I’m trying to achieve seems very simple. I’m trying to use a PSDrive to plop the contents of a variable into a remote file on a server (obviously this will expand out to many servers once I have it tested). The file path is expanded from the Server Name which is in the variable $SName – and the filename is “servername.ini”. A credential for a known Domain Admin user has been placed in $A.

    I created and used the drive using the following:

    New-PSDrive -Name U -Path “\$SNameC$” -Credential $A

    Set-Location U:
    $IniFile | Set-Content -Path “$SName.ini”

    The issue I have is that in the “Set-Content” command, the path of “U” is expanded three times so that I get the following error message:

    Set-Content : Could not find a part of the path

    Can anyone tell me what I’m doing wrong in creating and/or referencing this PSDrive?

    Sorry for being a n00b… TIA.

    p.s. I have also tried the obvious ‘set-Content -Path “U:$SName.ini” ‘ instead of using “Set-Location”.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.