# PowerShell Scripts not running

**URL:** <https://forums.powershell.org/t/powershell-scripts-not-running/6459>\
**Category:** PowerShell Help\
**Created:** [May 15, 2016, 10:52pm UTC](https://forums.powershell.org/t/powershell-scripts-not-running/6459 "2016-05-15T22:52:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darthmalkav](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@darthmalkav](https://forums.powershell.org/u/darthmalkav)\
**Post date:** [May 15, 2016, 10:52pm UTC](https://forums.powershell.org/t/powershell-scripts-not-running/6459/1 "2016-05-15T22:52:19Z")

</div>

I have written a bit of script to speed up on directory making and copying a file into one of them. it works fine in ISE (and PowerGUI)

How ever i can not get in to run by right clicking the PS1 file. I’ve even created a shortcut pointing to both PS and the PS1 file and changed the Reg setting to allow one click running of PS1 files.

All that happens in a PS box opens then closes straight away.

Here is a copy of what I’ve written

========================================

#Written by Jay O’Donnell to help Automate PCexport Extrarates 05/2016

#Variables  
$currentuser = [environment]::UserName  
$CustomerID = Read-Host -prompt “CustomerID”  
$ProductID = Read-Host -Prompt “Product Number”  
$Year = Read-Host -Prompt “Year”  
$Month = Read-Host -Prompt “Month”

#Mapps in the G drive if it has fallen off

(  
New-PSDrive -name “G” -PSProvider FileSystem -Root “\alliesfile01\Gdrive”  
)

#Create the directories for both input and out put files

(  
New-Item -itemType Directory -Path “C:\Users$currentuser\Desktop$CustomerID$ProductID”  
)  
(  
New-Item -itemType Directory -Path “C:\Users$currentuser\Desktop\export$year$Month$CustomerID$ProductID”

```
     )            

```

#Copies and renames the Modle file in to a formated Control file with in new input directory

(  
copy-Item “G:\paf\apps\APIexport\current\exe\EXTRACT.MDL” -Destination C:\Users$currentuser\Desktop$CustomerID$ProductID  
)  
(  
rename-item “C:\Users$currentuser\Desktop$CustomerID$ProductID\EXTRACT.MDL” -newname Change$CustomerID$ProductID.CTL

```
	)

```

(  
Read-Host “Press ENTER”

```
)

```

---

<div class="post-metadata">

**Author:** ![random-commandline](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@random-commandline](https://forums.powershell.org/u/random-commandline)\
**Post date:** [May 15, 2016, 11:01pm UTC](https://forums.powershell.org/t/powershell-scripts-not-running/6459/2 "2016-05-15T23:01:38Z")

</div>

It is closing because your execution policy is not set to run scripts.  
Check your policy via ‘Get-ExecutionPolicy’. If it is set to ‘Restricted,’ you can temporarily allow scripts to run via the following.

```
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
& \\path\to\script.ps1
```

---

<div class="post-metadata">

**Author:** ![darthmalkav](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@darthmalkav](https://forums.powershell.org/u/darthmalkav)\
**Post date:** [May 15, 2016, 11:28pm UTC](https://forums.powershell.org/t/powershell-scripts-not-running/6459/3 "2016-05-15T23:28:15Z")

</div>

That was the 1st thing i tried as the GP for my Organisation is “not configured” I’ve updated it to unrestricted now.

I’ll try adding in the file path though.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:41pm UTC](https://forums.powershell.org/t/powershell-scripts-not-running/6459/4 "2024-05-16T20:41:24Z")

</div>

Closed on May 16, 2024, 8:41pm UTC


