Skip to content

Instantly share code, notes, and snippets.

View mkht's full-sized avatar

mkht

  • Japan
  • 11:33 (UTC +09:00)
View GitHub Profile
Push-Location $PSScriptRoot
$Info = Get-Content 'info.txt' -Raw | ConvertFrom-Csv -Delimiter "`t" -WarningAction SilentlyContinue
$Mac = (Get-NetAdapter -Physical | ? {$_.MediaType -eq '802.3'} | select -First 1 -ExpandProperty MacAddress) -replace '-', ':'
$NewName = $Info | ? {$_.MACアドレス -eq $Mac} | select -First 1 -ExpandProperty コンピュータ名
$CurrentName = $env:COMPUTERNAME
if((Get-WmiObject Win32_ComputerSystem).PartOfDomain){
Write-Warning 'AD参加済みのPCです'
}
elseif([string]::IsNullOrEmpty($NewName)){
Write-Warning '"info.txt"からPC名が取得できませんでした'
@mkht
mkht / ChatGPT.ps1
Created March 4, 2023 19:19
ChatGPTへ質問するPowerShellコード(Windows PowerShell 5.1対応版)
# まず ChatGPT を使うための各種パラメータを指定します。
$Token = 'ここにAPIキーを入れてください'
$Uri = 'https://api.openai.com/v1/chat/completions'
$PostBody = @{
model = 'gpt-3.5-turbo'
}
# 次に質問する文章を決めます。
$PostBody.messages = @(
@{
function Compress-Png {
[CmdletBinding()]
param (
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[string]$InputFile,
[Parameter(Mandatory, Position = 1)]
[string]$OutFile
)
@mkht
mkht / Convert-DomainListToByteArray.ps1
Created May 8, 2021 18:40
Encodes a list of domain names into the format specified in Section 4.1.4 of "Domain Names - Implementation And Specification" (RFC 1035).
<#
.SYNOPSIS
Convert domain name list to byte array
.DESCRIPTION
Encodes a list of domain names into the format specified in Section 4.1.4 of "Domain Names - Implementation And Specification" (RFC 1035).
.EXAMPLE
PS C:\> Convert-DomainListToByteArray ('foo.example.com', 'example.com')
.PARAMETER DomainList
Specifies a List of domains
.INPUTS
@mkht
mkht / Send-ARPRequest.psm1
Last active March 25, 2021 15:07
Send-ARPRequest
# Original code is written by earthdiver1
# https://qiita.com/earthdiver1/items/0b9c85a5f2c90ba51f7e
# Modified by mkht
function Send-ARPRequest {
[CmdletBinding(PositionalBinding = $False)]
[Alias('arping')]
Param(
[Parameter(Position = 0)]
[String]$Target, # IP address of the target host
using module PSWebDriver
Describe 'DuckDuckGo' {
BeforeAll {
$Browser = New-PSWebDriver 'Chrome'
}
It 'DuckDuckGoで「PowerShell」を検索' {
#ブラウザを起動
'CollectUpdates.vbs
'This script is written by Microsoft
'https://docs.microsoft.com/en-us/previous-versions/office/office-2013-resource-kit/cc178995(v=office.15)#testing-and-verifying-the-windows-installer-msp-files
Dim oMsi,oFso,oWShell
Dim Patches,SumInfo
Dim patch,record,msp
Dim qView
Dim sTargetFolder,sMessage
function Compress-ScriptBlock {
[CmdletBinding()]
[Alias('minify')]
[OutputType([scriptblock])]
param (
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[scriptblock]
$ScriptBlock
)
$ErrorActionPreference = 'Stop'
cd C:\
$null = New-Item C:\j\k\l -ItemType Directory -Force
$null = Get-ChildItem C:\j\k | Select-Object -First 1
Remove-Item C:\j\k -Recurse -Force
Start-Sleep -Seconds 3
Remove-Item C:\j\k -Recurse -Force
@mkht
mkht / Build-WinPE-ISO.ps1
Created October 6, 2019 14:31
Windows PE 10 バージョン1809の日本語化ISOを作成するスクリプト
<######################################################
# Windows PE 作成スクリプト
#######################################################>
$ErrorActionPreference = 'Stop'
Set-Location $PSScriptRoot
$script:WorkDir = Join-Path $PSScriptRoot '\Work'
if (Test-Path $script:WorkDir -PathType Container -ErrorAction Ignore) {
Remove-Item $script:WorkDir -Force -Recurse
}
$null = New-Item $script:WorkDir -ItemType Directory -Force