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

PowerShell ครั้งที่ 23 Options · View
paedotnet
Posted: Tuesday, March 11, 2008 7:49:26 PM

Rank: มือเทพ
Groups: Member

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

การสั่งให้แสดงไฟล์ .ps1 โดยใช้คำสั่ง start-psjob
ในคำสั่งนี้จะแสดงรายละเอียดต่างๆของ ไฟล์ .ps1 เช่นแสดง  State เพื่อบอกว่าในตอนนี้ไฟล์ .ps1 นี้มีสถานะใด ฯ
ตัวอย่างการใช้งาน
เตรียมไฟล์ .ps1 เช่น test.ps1
จากนั้นย้าย path ในยังไฟล์นี้โดยใช้ cd หรือ Set-Location
แล้วเขียนคำสั่งดังนี้


Start-PSJob "test.ps1"

 
การระบุ Credential ในการเข้าถึง Application
จะใช้คำสั่ง

Get-Credential

หลังจากใช้คำสั่งนี้จะมีหน้าต่าง ให้ใส่ Username,password
ถ้าเราเขียนโค้ดดังนี้


$cc = Get-Credential


แล้วเขียนโค้ด


$cc


ผลลัพธ์จะแสดงชื่อ Username ,password ออกมาโดย password จะอยู่ในรูปแบบการเข้ารหัส
ถ้าเราต้องการแสดง username  เราก็สามารถเขียนได้ดังนี้


$cc.Username
 

แต่ถ้าเราต้องการแสดง password เราเขียนคำสั่งเพื่อแสดง password ก่อนเพราะถ้าเราใช้คำสั่ง


$cc.Password

ผลลัพธ์จะได้  System.Security.SecureString
ในการเขียนคำสั่งเพื่อแสดง password เขียนได้ดังนี้
[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($cc))

 



[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