Issues Running PowerShell Script from Command Prompt to Copy Files to Desktop

0
16
Asked By TechieNinja42 On

Hey everyone! I'm trying to execute a PowerShell script that copies two .bat files to user desktops, but I'm running into a problem when I try to run it from the command prompt. The script works perfectly when executed directly in PowerShell, but it doesn't do anything when I run it from the command prompt, unless I hardcode the desktop path. I'm using it for deployment through Intune, which is why I need it to work for all users. I'm wondering if there's a specific way to enable access to environment variables when executing from the command prompt. Any insights would be greatly appreciated!

3 Answers

Answered By DebbieDev On

Definitely check that when you're running your PowerShell script from the command prompt, it's executed in the correct context. You might want to look into tools like the PSAppDeployToolkit to streamline your deployments instead of just relying on PowerShell for everything. It could save you a lot of hassle!

Answered By HelpfulUser123 On

If you're experiencing issues with paths, adding some debugging to check if your source path exists can help. You can use a simple test like `if (Test-Path K:...) { "Found" } else { "Not found" }` before the copy command. Also, consider using `$env:USERPROFILEDesktop` for user-specific paths, which might be more reliable.

Answered By CodeWizard88 On

It sounds like you're hitting a common issue when deploying scripts with Intune. When running scripts via Intune, the execution context is usually SYSTEM, which means it doesn't have access to user-specific paths as you'd expect from a regular user environment. To get around this, you either need to copy files to the public desktop or adjust the execution behavior in Intune depending on whether you're targeting SYSTEM or USER. You've got the right idea about using `CommonDesktopDirectory` or `Desktop` based on the context.

SuperScripter99 -

Exactly! Just make sure you don't mix the contexts. Stick to one or the other for reliable results.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.