Search code examples
powershellemailbatch-filegoogle-drive-apimirror

Sending out batch file email to run a powershell script to update users folder


I am wanting to send out a file that others in my company can use to update a local folder from a Google Drive folder.

I have a PowerShell 7 script that works on my local computer:

robocopy "C:\Users\(insert username)\AppData\Roaming\Dynamo\Dynamo Revit\2.13\packages" "G:\Shared drives\(Insert Drive Name)\STANDARDS\DYNAMO\Packages\2.13\packages" /mir

I tried making a batch file using %appdata% to send out but it would just create a new folder in the folder containing the script. I then read that powershell doesn't use %appdata%

I tried using "$env:appdata" to locate the local file but nothing would happen. Can anyone help me with the proper syntax?

Here is the script I was trying:

robocopy "G:\Shared drives\(insert drive name)\STANDARDS\DYNAMO\Packages\2.13\packages" "$env:appdata\..\Roaming\Dynamo\Dynamo Revit\2.13\packages" /mir

Thanks


Solution

  • This ...

    robocopy "G:\Shared drives\(insert drive name)\STANDARDS\DYNAMO\Packages\2.13\packages" "$env:appdata\..\Roaming\Dynamo\Dynamo Revit\2.13\packages" /mir
    

    ... is not a valid path.

    $env:appdata evaluates to the following:

    (Get-ChildItem -Directory -Path $env:APPDATA).Parent
    # Results
    <#
    Mode                 LastWriteTime         Length Name                                                                                               
    ----                 -------------         ------ ----                                                                                               
    d-----          9/7/2022   9:18 AM                Roaming                                                                                            
    d-----          9/7/2022   9:18 AM                Roaming 
    #>
    
    Get-ChildItem -Directory -Path $env:APPDATA
    # Results
    <#
        Directory: C:\Users\WDAGUtilityAccount\AppData\Roaming
    
    
    Mode                 LastWriteTime         Length Name                                                                                               
    ----                 -------------         ------ ----                                                                                               
    d-----          9/7/2022   9:18 AM                Adobe                                                                                              
    d---s-         9/21/2022   6:50 PM                Microsoft 
    #>
    
    Get-ChildItem -Directory -Path "$env:APPDATA\..\Credentials"
    # Results
    <#
    Get-ChildItem : Cannot find path 'C:\Users\WDAGUtilityAccount\AppData\Credentials' because it does not exist.
    At line:1 char:1
    #>
    
    Get-ChildItem -Directory -Path "$env:APPDATA\*\Credentials"
    # Results
    <#
    
    Mode                 LastWriteTime         Length Name                                                                                               
    ----                 -------------         ------ ----                                                                                               
    d---s-          9/7/2022   9:18 AM                Credentials 
    #>