PowerShell Scripts not running

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of darthmalkav darthmalkav 6 months, 3 weeks ago.

  • Author
    Posts
  • #39122
    Profile photo of darthmalkav
    darthmalkav
    Participant

    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"

    )

  • #39128
    Profile photo of random commandline
    random commandline
    Participant

    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
    
  • #39133
    Profile photo of darthmalkav
    darthmalkav
    Participant

    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.

You must be logged in to reply to this topic.