Author Posts

June 10, 2015 at 7:29 am

I'm working on a script to copy all changelogs to a central location.
I'm using this command:

# backup all initial configs and changelogs
$servers = @('accumedic')
foreach ($server in $servers) {
$svrname2 = $server + "_changelog.txt"
# write-host $svrname2 -- this works
test-path \\$server\C`$\$svrname2 -- this returns false
copy \\$server\C`$\$svrname2 \\mls-storage2\software\changelogs

How do I make this copy command work??
copy \\$server\C`$\$svrname2 \\mls-storage2\software\changelogs

The file and path DO exist.

I get this error:

At D:\software\Scripts\backup_changelogs.ps1:11 char:5
+ copy <<<< \\$server\C`$\$svrname2 \\mls-storage2\software\changelogs + CategoryInfo : ObjectNotFound: (\\accumedic\C$\accumedic_changelog.txt:String) [Copy-Item], ItemNotFoundExcepti on + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand Thank you, Tom

June 10, 2015 at 7:54 am

So you've verified that \\accumedic\C$\accumedic_changelog.txt exists? Because the shell appears to feel pretty strongly that it doesn't.

June 10, 2015 at 7:56 am

I know that file exists because I created it myself and I can see it in the C:\ of accumedic.
Why does Powershell think it does not exist??
Is it because I'm running the script on my local domain computer??
How do I make Powershell behave?? 🙂 🙂
Thank you, Tom

June 10, 2015 at 7:59 am

Well, I guess I'm asking, can you hit Windows+R, type in \\accumedic\C$\accumedic_changelog.txt, and have the file open? From the same computer that you're using to run PowerShell?

And if that works, are you running PowerShell on the same machine, using the same user account?

PowerShell just asks the OS to open the file; it's the OS that's saying it can't find the file. PowerShell is just passing along the bad news.

June 10, 2015 at 8:00 am

You need to concantenate a string. Personally, I like using string format:

$servers = @("accumedic")
foreach ($server in $servers) {
    $path = "\\{0}\C$\{0}_changelog.txt" -f $server
    if (test-path $path) {
        Copy-Item $path \\mls-storage2\software\changelogs

There are many ways to do, but you just need to build a string that contains the variable:

$servers = @("accumedic")
foreach ($server in $servers) {
    #String Format
    "\\{0}\C$\{0}_changelog.txt" -f $server
    #Standard concantenation
    "\\" + $server + "\C$\" + $server + "_changelog.txt"



June 10, 2015 at 8:36 am

@Don — OIC — Now I'm getting closer.
I have realized that running this script from another server where I'm logged in as administrator will make it work, now to get the other servers worked into the script and so forth.
It won't work from my local computer.
Thank you, Tom

June 10, 2015 at 9:32 am

Well, most of the time it works from one of the servers where I'm logged in as administrator, but it does not work for SOME servers???????????
Thank you, Tom

June 10, 2015 at 10:19 am

Well... look, I think this might be a misunderstanding about how file shares work.

C$ is an Admin share. It won't usually show up in Explorer – it's hidden. And it's usually permission only for Administrators. So \\server won't usually show it; \\server\c$ should work. And if that doesn't work in Explorer, it isn't going to work in PowerShell, but it's a little tough for me to help you fix that from here.

June 10, 2015 at 10:23 am

I know C$ is an Admin share, the puzzling thing is the Administrator account can get at it on some of the servers but not on other servers.
I must compare C: between the ones that work and the ones that don't work, which may point me toward getting things sussed.
Thank you, Tom

June 10, 2015 at 10:26 am

It's likely either a permission problem, or your credential isn't being recognized by the server. And yeah – comparing working vs not working is definitely the right step. Good luck!

June 11, 2015 at 10:12 am

File and Printer Sharing had to be enabled on the network adapters of the servers that were initially not accessible, then the script worked correctly as expected.
Thank you, Tom