-
Notifications
You must be signed in to change notification settings - Fork 0
/
aa12.ps1
117 lines (101 loc) · 5.21 KB
/
aa12.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 出力エンコーディングをUTF-8に設定
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
try {
# コンピュータの配列を定義
$computers = @(
@{Name="ycsvm103"; User="ycsvm103\administrator"; Password="#YamadaVM03"; Type="Server"},
@{Name="Server2"; User="ServerUser2"; Password="ServerPassword2"; Type="Server"},
@{Name="Server3"; User="ServerUser3"; Password="ServerPassword3"; Type="Server"},
@{Name="delld022"; User="ygijutubu"; Password="YCg-7741315-4"; Type="LicensePC"},
@{Name="LicensePC2"; User="LicensePCUser2"; Password="LicensePCPassword2"; Type="LicensePC"},
@{Name="LicensePC3"; User="LicensePCUser3"; Password="LicensePCPassword3"; Type="LicensePC"}
)
# ClientPCクラスの定義
class ClientPC {
[string] $Type
[array] $AccessibleComputers
ClientPC([string] $type, [array] $computers) {
$this.Type = $type
if ($type -eq "Admin") {
$this.AccessibleComputers = $computers
} else {
$this.AccessibleComputers = $computers | Where-Object {$_.Type -eq "LicensePC"}
}
}
}
# ClientPCクラスのインスタンスを作成
$adminPC = [ClientPC]::new("Admin", $computers)
# 選択したコンピュータ名の変数
$selectedComputerName = "ycsvm103"
# アクセス可能なコンピュータから選択したコンピュータを取得
$selectedComputer = $adminPC.AccessibleComputers | Where-Object {$_.Name -eq $selectedComputerName}
# 選択したコンピュータをファイルに保存
$selectedComputer | Out-File -FilePath 'output.txt' -Encoding 'UTF8'
# 自己署名証明書を作成
$cert = New-SelfSignedCertificate -DnsName "localhost" -CertStoreLocation "cert:\CurrentUser\My" -KeyUsage DigitalSignature -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3")
# ファイルパスを自動で取得
$scriptFilePath = $MyInvocation.MyCommand.Path
# スクリプトにデジタル署名を付ける
Set-AuthenticodeSignature -FilePath $scriptFilePath -Certificate $cert
# Computerクラスの定義
class Computer {
[string] CheckRdpSession() {
return "RDPセッションのチェック中..."
}
[string] GetSessionList() {
return "セッションリストの取得中..."
}
}
# Serverクラスの定義
class Server : Computer {
# Serverクラス固有のプロパティやメソッドをここに追加できます
}
# LicensePCクラスの定義
class LicensePC : Computer {
# LicensePCクラス固有のプロパティやメソッドをここに追加できます
}
# 選択したコンピュータのタイプに基づいて適切なコンピュータクラスのインスタンスを作成
if ($selectedComputer.Type -eq "Server") {
$computer = [Server]::new()
} else {
$computer = [LicensePC]::new()
}
# コンピュータオブジェクトのメソッドを呼び出す
$computer.CheckRdpSession()
$computer.GetSessionList()
}
catch {
Write-Host "An error occurred: $_"
}
# SIG # Begin signature block
# MIIFlgYJKoZIhvcNAQcCoIIFhzCCBYMCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCDltXQPWLEwa/aj
# y5KsS7SR9FNFcpyGbRAx7vNkFmNK1KCCAxIwggMOMIIB9qADAgECAhB6bP6sxNa7
# skL43Vz0ZaqsMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNVBAMMCWxvY2FsaG9zdDAe
# Fw0yNDA2MjExNDI3NDJaFw0yNTA2MjExNDQ3NDJaMBQxEjAQBgNVBAMMCWxvY2Fs
# aG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALsFtsSlCMHyQrWS
# AH2vQ7H9ptAL/SPKbjBWwU3DvXvkcL8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