\n Hi, and welcome to the PowerShell forum! \n\n\nDon’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask! \n\n\nUse a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which. \n\n\nDon’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…\n <\/blockquote>\n<\/aside>\n","upvoteCount":0,"datePublished":"2021-04-26T15:50:19.000Z","url":"https://community.spiceworks.com/t/lookup-machine-name-and-open-corresponding-folder/798041/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Thanks for the help with this! Its very close to what I needed. I made a few changes but getting some error regarding the copy. Want it to copy from the $shareinfo path that includes $computername to a local directory C:\\TEST. What I have below copies the folder with the machine name, but the destination ends up empty “C:\\TEST”. Also looks like there are a few errors.<\/p>\n
$env:computername\n$computername = $env:computername\n$shareinfo = \"\\\\192.168.0.22\\Shared\\Test\\$computername\"\n$files = Get-childitem $someFolder\nforeach($item in $files){\n copy-item $shareinfo -destination \"C:\\TEST\"\n}\n<\/code><\/pre>\nThe error I get is this one (See below) which I am confused about. Error is because that the folder “COMPUTERNAME” exists for some reason. But it does not exist when the script starts. Not sure why its upset. Goal is to just create it once and then copy everything from $shareinfo path to C:\\TEST overwriting all files.<\/p>\n
*ERROR:<\/p>\n
copy-item : An item with the specified name C:\\Bogus\\TEST\\COMPUTERNAME already exists.<\/p>\n
At line:6 char:5<\/p>\n
\ncopy-item $shareinfo -destination “C:\\TEST”<\/li>\n \n<\/code><\/pre>\n<\/li>\nCategoryInfo : ResourceExists: (C:\\Bogus\\TEST\\COMPUTERNAME:String) [Copy-Item], IOException<\/li>\n FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.CopyItemCommand<\/li>\n<\/ul>","upvoteCount":0,"datePublished":"2021-04-27T13:50:55.000Z","url":"https://community.spiceworks.com/t/lookup-machine-name-and-open-corresponding-folder/798041/6","author":{"@type":"Person","name":"zackbrandow","url":"https://community.spiceworks.com/u/zackbrandow"}},{"@type":"Answer","text":"if the folder does not exists, it can not read it and not copy it.<\/p>\n
copy-item says the file already exists, if you want to overwrite it you can use the ‘-force’ parameter<\/p>\n
copy-item $shareinfo -destination \"C:\\TEST\" -Force\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2021-04-27T14:06:53.000Z","url":"https://community.spiceworks.com/t/lookup-machine-name-and-open-corresponding-folder/798041/7","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"Thanks I should have figured that would be needed. I also added -Recurse at the end. All files are copying now based on machine and folder name! Ill be able to use this script for a few different things. I appreciate the help!<\/p>\n
$env:computername\n$computername = $env:computername\n$shareinfo = \"\\\\192.168.0.22\\Shared\\Test\\$computername\"\n$files = Get-childitem $someFolder\nforeach($item in $files){\n copy-item $shareinfo -destination \"C:\\TEST\" - Force -Recurse\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2021-04-27T16:45:28.000Z","url":"https://community.spiceworks.com/t/lookup-machine-name-and-open-corresponding-folder/798041/8","author":{"@type":"Person","name":"zackbrandow","url":"https://community.spiceworks.com/u/zackbrandow"}}]}}
Neally
(Neally)
April 26, 2021, 3:50pm
4
Zack6729:
We’re happy to HELP but not a script writing service.what have you tried where are you stuck?
If you post code, please use the ‘Insert Code’ button. Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…