Copy Item to All User Profiles

This topic contains 4 replies, has 3 voices, and was last updated by  Brandon 2 weeks, 2 days ago.

  • Author
    Posts
  • #85222

    Brandon
    Participant

    Greetings,

    I am not only new around here, but new to PowerShell and have been enjoying the community and learning experience, thus far. I am hoping somebody here can assist! I have been musing around how to copy an XML file from Roaming\AppData in the user profile to all domain users that have logged into the PC, but I am not having much luck. Hoping I could get some help with this and learn something in the process.

    This works to prompt for computer name and copies the file, but only for one user (again, I need all user profiles on the machine to get this file) :

    Param (
    [Parameter(Mandatory=$true)][string]$computername,
    [Parameter(Mandatory=$true)][string]$username
    )

    Copy-Item -LiteralPath C:\Users\btorvick\AppData\Roaming\SAP\Common\SAPUILandscape.xml -Destination \\$computername\C$\Users\$username\AppData\Roaming\SAP\Common -Verbose

    I tried omitting $username, then using either *, %username%, or %userprofile% but no luck. I am close to figuring this out, or completely above my head here?

    Thanks,

    -Brandon

  • #85228

    random commandline
    Participant

    I don't have my domain environment available; but off the top of my head, something like this should work after gathering computer accounts from Active Directory and combined with Invoke-Command.

    $source = 'C:\Users\btorvick\AppData\Roaming\SAP\Common\SAPUILandscape.xml'
    
    Get-ChildItem C:\Users | ForEach-Object {
        Copy-Item -LiteralPath $source -Destination "$($_.FullName)\AppData\Roaming\SAP\Common" -Verbose
    }
    
    • #85258

      Brandon
      Participant

      Hi "Random Commandline" — thanks for taking the time to think about this, I appreciate the input.

      On the real, I am only following you about half-way on what you wrote and suggested above. As I mentioned in the original post, I am really new to PS and working through the basics. Can you clarify more on what you mean by gathering AD computer with the Invoke cmd?

      The way I am thinking about it, is to create a CSV with a header and computers names to run the script against...

      Thanks,

      -Brandon

  • #85232

    Olaf Soyk
    Participant

    Sounds for me like a perfect task for a Group Policy, don't you think?

    • #85261

      Brandon
      Participant

      Hi Olaf —

      To provide a bit of context here... Technically this should be done with an SAP Gui Installation server through a custom package build, not through GPO or PS. Our Basis Admin is not able to work on this, leaving me to pick up the pieces; trying to find a "dirty" means to an end. Ultimately, yes, I could put up a GPO policy but I find the value in learning how to do this is PS as GPO's aren't always the right answer.

      Figured this is a great to forum to inquire!

      Thanks,

      -Brandon

You must be logged in to reply to this topic.