Powershell Script not working after saving as .ps1

Welcome Forums General PowerShell Q&A Powershell Script not working after saving as .ps1

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
2 years, 10 months ago.

  • Author
    Posts
  • #38017

    Participant
    Points: 0
    Rank: Member

    Hi All,

    I have Powershell code, I have tested it by pasting the code with Powershell
    it ran without error.
    But, when I have saved it as .PS1 file and trying to run it's not working, I am receiving error

    $path = “C:\Users\beeraval\desktop\Powershell_work\Source.xlsx”
    $Excel = New-Object -ComObject excel.application
    $Excel.visible = $True
    $Workbook = $excel.Workbooks.open($path)
    $Worksheet = $Workbook.WorkSheets.item(“MBR Metrics”)
    $worksheet.activate()
    $path1 = “C:\Users\beeraval\desktop\Powershell_work\loaa.xlsx”
    $Excel1 = New-Object -ComObject excel.application
    $Excel1.visible = $True
    $Workbook1 = $excel1.Workbooks.open($path1)
    $Worksheet1 = $Workbook1.WorkSheets.item(“Loaa Data”)
    $worksheet1.activate()
    $range = $WorkSheet.Range(“D:D“).EntireColumn.Delete()
    $range = $WorkSheet.Range(“A4:AM206“)
    $range.Copy() | out-null
    $Worksheet1 = $Workbook1.WorkSheets.item(“Loaa Data”)
    $Range1 = $Worksheet1.Range(“A4“)
    $Worksheet1.Paste($range1)
    $workbook1.Save()

    Any help is appreciated

  • #38021

    Participant
    Points: 25
    Rank: Member

    What is the error you're receiving?

  • #38029

    Participant
    Points: 26
    Rank: Member

    I guess you're having the extensions in explorer hidden? And that's why the ps1 file doesn't run?

  • #38032

    Participant
    Points: 25
    Rank: Member

    It's possible the execution policy is restricting it from running.

  • #38033

    Participant
    Points: 26
    Rank: Member

    Without knowing the actual error message, it's only guessing from our side...

  • #38080

    Participant
    Points: 0
    Rank: Member

    Hi All, Thank you for your response. I should have mentioned my error clearly.

    I was able to resolve my error once I have saved my Code using Powershell ISE.

    Its running fine now.

    -Vishal

The topic ‘Powershell Script not working after saving as .ps1’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort