Powershell accessing to the desktop

Dear expert

Powershell: $env: USERPROFILE\desktop\folder\
now when I run it, it tells me a error that permission denied... ok weird... I don't use right to access my desktop? Now when I try and full path, it works well...

What is the problem?
Who is Participating?
Just to exclude the way-too-obvious:
You remembered to change the $Input variable in line 10 as well?
And made sure that the variable you used is identical in lines 2 and 10 (stranger things than typos have happened)?

Open a new PS console, paste the following:
$SourceFolder = "$env:USERPROFILE\desktop\secret"
Get-ChildItem -Path $SourceFolder -File | Where-Object {-not $_.Extension}

Open in new window

This works just fine for me.
You can't set the $Input variable, so PS will just get the children of the folder you're currently in, which is probably your profile folder. In your profile folder, it will find the "secret" folder (which has no extension), and try to open it as a file (which will fail for the obvious reason that it's not a file).
When you run what exactly?
You need to be more specific about what it is you're trying to do and the exact error message you're getting.
WeTiAuthor Commented:
Hi oBdA

Its a decryption script by calling openssl. the error I get is:

openssl.exe : Can't open C:\Users\weti\desktop\secret for reading, Permission denied

Function Decry {
$Input = "$env:USERPROFILE\desktop\secret"
$Output = "$env:USERPROFILE\desktop\secret"
$UniqueKey = '(stdin)= aef44983e90b10***4af1742a15***8942'
$KeyFile = "$env:USERPROFILE\desktop\secret"
$RandomkeyFileName = Get-Random
$KeyFileExtractPath = "$Env:APPDATA\Microsoft"
openssl.exe enc -aes-256-cbc -salt -d -in $KeyFile -out $KeyFileExtractPath\"$RandomkeyFileName.key" -k $UniqueKey
$ReadKey = Get-Content -Path $KeyFileExtractPath\"$RandomkeyFileName.key"
$AllFiles = Get-ChildItem -Path $Input | ?{$_.Extension -eq $null -or $_.Extension -eq ""}
ForEach ($EachFile in $AllFiles){
$fullPath = $EachFile.FullName
$FileName = $EachFile.Name
    ForEach ($FileNameS in $ReadKey){
        $FileH,$FileN = $FileNameS.split(",",2)
       Write-Host "$FileH" -ForegroundColor Yellow
       Write-Host "$FileName" -ForegroundColor Green
            if($FileH -eq $FileName){
                Write-Host "Decrypted File : $FileN" -ForegroundColor Black -BackgroundColor White
                openssl.exe enc -aes-256-cbc -salt -d -in $fullPath -out $Output\$FileN -k $UniqueKey
Remove-Item $KeyFileExtractPath\"$RandomkeyFileName.key" -Force

Open in new window

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

WeTiAuthor Commented:
Thing is if I directly type:

$Input = 'C:\Users\weti\desktop\secret' This works... now because it will be a network shared script so env: must work tho...
WeTiAuthor Commented:
now I lied... direct input didn't work as well, same problem
Replace $Input with $SourceFolder or whatever. $Input is a default variable.

$input gotchas
WeTiAuthor Commented:
Did, didn't help, same problem. Now I really dont know what the hell is going on... It worked before with direct path...
Shaun VermaakTechnical Specialist/DeveloperCommented:

Open in new window

now I lied... direct input didn't work as well, same problem
WeTiAuthor Commented:
After a restart, things started working well again. With my old option: $env:USERPROFILE
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.