Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Powershell for network path Expand / Collapse
Author
Message
Posted Wednesday, September 5, 2012 1:33 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:06 PM
Points: 7,125, Visits: 12,720
Scott Newman-212556 (9/5/2012)
You need to change the provider when the job runs. It's running under the sqlserver:/ provider. Just do a cd c: at the top of your script and it will now accept the unc path.

Scott

Hmm, that was not necessary for me. My test was successful with only a single command like so:

Copy-Item "\\server\path\file.extension" -Destination "C:\localpath\localfilename.extension"


For the record I am using 2008 R2 Build 10.50.2806.


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1354852
Posted Thursday, September 13, 2012 4:45 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, November 25, 2013 7:37 AM
Points: 14, Visits: 55
"cd c:" works! Thanks!!
Post #1358970
Posted Thursday, September 13, 2012 6:56 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:06 PM
Points: 7,125, Visits: 12,720
bwperrin (9/13/2012)
"cd c:" works! Thanks!!

What build are you on?


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1359001
Posted Sunday, July 28, 2013 7:11 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, September 12, 2014 8:38 PM
Points: 1, Visits: 26
sgnewman (9/5/2012)
You need to change the provider when the job runs. It's running under the sqlserver:/ provider. Just do a cd c: at the top of your script and it will now accept the unc path.

Scott


Nailed it! This is the only place I've been able to find on the whole internets that has the solution. This has been driving me crazy for days! I chose to use the newer PowerShell command "Set-Location c:" instead, which does the same thing.

opc.three (9/13/2012)
bwperrin (9/13/2012)
"cd c:" works! Thanks!!

What build are you on?


I'm willing to bet it worked for the guy using SQL 2012. Our powershell scripts were all working perfectly fine running as SQL agent jobs in SQL 2008 R2. We upgraded to SQL 2012 and all of our powershell scripts that performed file copy or moves would fail with "invalid path". Scott knew exactly what is happening now in SQL 2012.

Thanks Scott!
Post #1478362
Posted Sunday, July 28, 2013 7:35 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Today @ 9:47 AM
Points: 4, Visits: 927
You're very welcome.

Scott
Post #1478364
Posted Sunday, July 28, 2013 9:00 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:06 PM
Points: 7,125, Visits: 12,720
It must have had something to do with the switch in SQL Agent 2008 to 2012 from them dropping us into a mini-shell versus dropping us into a full blown PowerShell.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1478374
Posted Sunday, July 28, 2013 9:05 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Today @ 9:47 AM
Points: 4, Visits: 927
More than likely. I've just gotten into the habit of just calling powershell directly in a cmd line from the job server instead of putting it into a powershell job step just because of niggly little issues like this.

Scott
Post #1478375
Posted Sunday, July 28, 2013 9:12 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:06 PM
Points: 7,125, Visits: 12,720
That's what I do too, and recommend on 2008 R2 but I was hopeful with the change in the approach to PowerShell steps introduced in 2012 that the user experience would have improved to the point where I would not need to do that anymore. Using powershell.exe some of my command lines have become pretty gnarly with all the parameters I pass to my scripts. However, since I do not run 2012 as a primary platform in production just yet my knowledge is limited to some specialized instances I have rolled out plus some local testing. I have not rolled my generic maintenance routines to a 2012 environment just yet to see how they would react if I converted them to use PowerShell steps.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1478376
Posted Sunday, July 28, 2013 9:19 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:06 PM
Points: 7,125, Visits: 12,720
ryan 8226 (7/28/2013)
I chose to use the newer PowerShell command "Set-Location c:" instead, which does the same thing.

By the way, cd is not a different, older command than Set-Location, it's an alias, so they're one in the same:



There are a bunch of built-in aliases in your default PowerShell session, cd being just one of many. Type alias at a PowerShell prompt to see them all:



You can also define new aliases of you own as well using New-Alias in case you are interested. Check the help for complete details:



__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato


  Post Attachments 
3.jpg (149 views, 17.08 KB)
4.jpg (149 views, 80.20 KB)
5.jpg (149 views, 107.83 KB)
Post #1478377
Posted Tuesday, September 30, 2014 4:53 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, October 1, 2014 4:58 PM
Points: 321, Visits: 1,495
This was a huge help. It solved my problem.
Post #1621400
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse