Author Posts

May 16, 2016 at 4:22 am

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

$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"


May 16, 2016 at 4:31 am

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

May 16, 2016 at 4:58 am

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.