ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Powershell Default User

    IT Discussion
    powershell
    5
    26
    2.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      black3dynamite @Lakshmana
      last edited by

      @lakshmana said in Powershell Default User:

      @dbeato said in Powershell Default User:

      @black3dynamite said in Powershell Default User:

      @lakshmana said in Powershell Default User:

      @dbeato said in Powershell Default User:

      [string]$file = 'C:$env:UserName\fILENAME'
      )

      Get-Item : Cannot find path 'C:$env:Username\Tickets' because it does not exist.

      It should be 'C:\Users\$env:USERNAME\filename'

      That's right...

      Get-Item : Cannot find path 'C:\Users$env:USERNAME\filename' because it does not exist.

      C:\$env:Username\Tickets should be 'C:\Users\$env:USERNAME\Tickets'

      L 1 Reply Last reply Reply Quote 0
      • L
        Lakshmana @black3dynamite
        last edited by

        @black3dynamite said in Powershell Default User:

        @lakshmana said in Powershell Default User:

        @dbeato said in Powershell Default User:

        @black3dynamite said in Powershell Default User:

        @lakshmana said in Powershell Default User:

        @dbeato said in Powershell Default User:

        [string]$file = 'C:$env:UserName\fILENAME'
        )

        Get-Item : Cannot find path 'C:$env:Username\Tickets' because it does not exist.

        It should be 'C:\Users\$env:USERNAME\filename'

        That's right...

        Get-Item : Cannot find path 'C:\Users$env:USERNAME\filename' because it does not exist.

        C:\$env:Username\Tickets should be 'C:\Users\$env:USERNAME\Tickets'

        I have changed already

        1 Reply Last reply Reply Quote 0
        • L
          Lakshmana @dbeato
          last edited by

          @dbeato said in Powershell Default User:

          @lakshmana said in Powershell Default User:

          @scottalanmiller said in Powershell Default User:

          Are you sure that the filename exists?

          The files exists inside that folder and before doing this i have mentioned as in .bat but that has to runned in the all the machine means it should get the current user details so only asked for the same which is not working when tried to execute in the powershell

          So are you running this via a task or when the user logs in?

          This is the powershell which converts into .csv to .xlsx in the machine in the folder mentioned

          L 1 Reply Last reply Reply Quote 0
          • L
            Lakshmana @Lakshmana
            last edited by

            @lakshmana The $env:USERNAME is not working inside string it seems ?Any suggestions ?

            M 1 Reply Last reply Reply Quote 0
            • M
              manxam @Lakshmana
              last edited by manxam

              @lakshmana : It works fine, but you're using the wrong quotes.
              [string]$file = "C:\Users\$env:username\blah"

              Variable names cannot be replaced in a string delimited with '
              $test = 'My variable'
              $this = "This is $test"
              PS > $this
              PS > "This is My Variable"

              L 1 Reply Last reply Reply Quote 0
              • L
                Lakshmana @manxam
                last edited by

                @manxam Thanks now it works in command prompt from the .bat file

                1 Reply Last reply Reply Quote 0
                • 1
                • 2
                • 2 / 2
                • First post
                  Last post