Reputation: 65
I just wrote this code:
Get-ChildItem 'R:\Source\Path' |
Where-Object { $_.Name -notlike '*_*' } |
Select-Object -ExpandProperty Name > 'C:\Destination\Path\Test.txt' |
Clear-Host
Invoke-Item 'C:\Destination\Path\Test.txt'
which worked perfectly. I saved the code and then closed power shell. When I reopened powershell and ran this specific program, it produced the following error message:
File C:\Users\Galen\Powershell Code\InvokeItem.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170. + CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnauthorizedAccess
I am the administrator on this computer. What happened?
Upvotes: 0
Views: 1405
Reputation: 1034
What is your ExecutionPolicy set to ?
PS C:\Users\Me\Desktop> ExecutionPolicy
If it's Restricted , then it runs PowerShell in Interactive mode only which is why it ran before.
If you are an admin, then try setting it to Unrestricted and execute your script
PS C:\Users\Me\Desktop> Set-ExecutionPolicy Unrestricted
More Info - Using the Set-ExecutionPolicy
Upvotes: 1