.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

powershell ครั้งที่ 21 Options · View
paedotnet
Posted: Thursday, February 21, 2008 4:51:51 AM

Rank: มือเทพ
Groups: Member

Joined: 12/6/2007
Posts: 354
Location: bkk

การตั้งค่า  สำหรับการรันไฟล์ .ps1
ปกติแล้ว ไฟล์ .ps1 ยังไม่สามารถรันได้โดยผ่าน โปรแกรม powershell สังเกตุได้ว่าถ้ามีการเรียกใช้งาน ไฟล์ .ps1 จะมี error เป็นตัวอักษรสีแดงขึ้นมาดังนี้
hello.ps1 cannot be loaded because the execution of scripts is disabled on  this system...
เหตุผลที่ไม่สามารถรันไฟล์ .ps1 ได้เนื่องจากว่าทางระบบได้กำหนด execution policy เป็นแบบ Restricted ( ค่า default) ดังนั้นถ้าต้องการที่จะรัน script ไฟล์ .ps1 ได้ก็ต้องกำหนด
executionpolicy ให้เป็น unrestricted ดังนี้
1. check ก่อน ว่าระบบนั้นเป็น ชนิดใดโดยใช้คำสั่ง


Get-ExecutionPolicy


2. ถ้าเป็น restricted ก็ทำการเปลียนให้เป็นแบบ unrestricted ดังนี้


 Set-ExecutionPolicy Unrestricted


3. หลังจากที่เปลี่ยนแล้วให้ลองตรวจสอบดูอีกที่โดยใช้คำสั่ง


Get-ExecutionPolicy


4. ถ้าเป็น Unrestricted แล้วก็สามารถทีจะรัน ไฟล์ .ps1 ได้ ( ให้ปิดโปรแกรม แล้วเปิดใหม่อีกที)

เครื่องหมาย > และ >> ต่างกันยังไง
เครื่องหมาย > เป็นการสร้างไฟล์ใหม่หรือว่าถ้ามีไฟล์อยู่แล้วจะเขียนทับข้อมูลเดิม
ส่วนเครื่องหมาย >> จะเป็นการเขียนต่อท้ายข้อมูลเดิม
เช่น
"hello" > test.txt  # จะสร้างไฟล์ที่ชื่อ test.txt ใหม่
"aaa" >> test.txt # จะใช้ไฟล์เดิมที่สร้างไว้แล้วจะมีคำว่า aaa ต่อท้าย hello


 



[With great power comes great responsibility]
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by