顯示具有 PowerShell 標籤的文章。 顯示所有文章
顯示具有 PowerShell 標籤的文章。 顯示所有文章

2019年4月9日 星期二

Power Shell Command Change Domain Account Password



$tgtDomain = "tw.XXXnet.org"
$tgtUserName = "user_account"


$oldPassword = ConvertTo-SecureString -AsPlainText "abc123" -Force
$newPassword = ConvertTo-SecureString -AsPlainText "123abc" -Force

Set-ADAccountPassword -Server $tgtDomain -Identity $tgtUserName -OldPassword  $oldPassword -NewPassword $newPassword

2019年2月20日 星期三

2018年3月21日 星期三

Execute PowerShell Script

直接在 PowerShell 的環境中
打入 D:\Learning\PowerShell\Ch02\GetFileShares.ps1
或是
先 cd D:\Learning\PowerShell\Ch02\
再打入 .\GetFileShares.ps1 (即便是在現行作用目錄區中,也要用 .\ )

在啟動 PowerShell 環境時
PowerShell -Noexit -command "D:\Learning\PowerShell\Ch02\GetWmiAndQuery.ps1"
參數
-Noexit:為了保持 PowerShell 的執行結果,能保留下來。
-command:為了是在啟動 PowerShell 時,一併載入指定的批次檔案。


PowerShell Scripts 如何執行?

http://pertonchang.blogspot.tw/2009/05/powershell-scripts.html

Run as Administrator

Open Powershell first:
Type PowerShell to enter a PowerShell session.
Once in the session:
Type Start-Process PowerShell -Verb RunAs and press Enter.
That will open a new Powershell process as Administrator.
------- OR -------
To do it all with only one line from the command prompt, just type:
powershell -Command "Start-Process PowerShell -Verb RunAs"

Curl and Invoke-WebRequest

Linux Bash:
Wroking: ***
curl -u "Account:PWD or API Token" 'http://FQDN:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'

Return:
Jenkins-Crumb:***************************

curl -X POST -u "Account:PWD or API Token" -H "Jenkins-Crumb:***************************" http://FQDN:8080/view/Operation/view/2_Stage/job/****/buildWithParameters?token=****&cause=trigger+by+shavlik+POC



PowerShell:

Start-Sleep -s 180
$JenkinsURL = "http://FQDN:8080"
$JobName = "view/Operation/view/2_Stage/job/****"
$JobToken = "****************t"
$Auth = "Account:PWD or API Token"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($Auth)
$Base64bytes = [System.Convert]::ToBase64String($Bytes)
$Headers = @{ "Authorization" = "Basic $Base64bytes"}
$CrumbIssuer = "$JenkinsURL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,`":`",//crumb)"
$Crumb = Invoke-WebRequest -UseBasicParsing $CrumbIssuer -Headers $Headers
Write-Host $Crumb

$Regex = '^Jenkins-Crumb:([A-Z0-9]*)'
$Matches = @([regex]::matches($crumb, $regex, 'IgnoreCase'))
$RegCrumb = $Matches.Groups[1].Value
$Headers.Add("Jenkins-Crumb", "$RegCrumb")
Write-Host $Headers

$FullURL = "$JenkinsURL/$JobName/buildWithParameters?token=$JobToken"
Write-Host $FullURL
Invoke-WebRequest -UseBasicParsing $FullURL -Method POST -Headers $Headers

<End>

Refer:
Enable the URL job trigger:
https://www.nczonline.net/blog/2015/10/triggering-jenkins-builds-by-url/

CSRF Protection Explained
https://support.cloudbees.com/hc/en-us/articles/219257077-CSRF-Protection-Explained

Trigger Jenkins Builds Using PowerShell
https://www.smartfile.com/blog/trigger-jenkins-builds-using-powershell/

PowerShell Command
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/start-sleep?view=powershell-6


Docker Command

#1 pull images $docker pull chusiang/takaojs1607 #2 list images $docker images #3.1 run docker $docker run -it ### bash #3.2 run do...