Initialer Import der Synology Scripts

This commit is contained in:
root
2026-08-05 08:43:57 +02:00
commit 5e32a7c411
404 changed files with 79932 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+63
View File
@@ -0,0 +1,63 @@
Add-Type -AssemblyName PresentationFramework
[xml]$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Proxmox Manager" Height="350" Width="525">
<Grid>
<Button Name="CheckHostsButton" Content="Check Hosts" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="50" Margin="10"/>
<Button Name="ListServersButton" Content="List Servers" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="50" Margin="120,10,0,0"/>
<Button Name="CreateVMButton" Content="Create VM" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="50" Margin="230,10,0,0"/>
<TextBox Name="OutputTextBox" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,70,0,0" Height="200" Width="480"/>
</Grid>
</Window>
"@
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$Window = [Windows.Markup.XamlReader]::Load($reader)
$CheckHostsButton = $Window.FindName("CheckHostsButton")
$ListServersButton = $Window.FindName("ListServersButton")
$CreateVMButton = $Window.FindName("CreateVMButton")
$OutputTextBox = $Window.FindName("OutputTextBox")
# Verbindung zu Proxmox
$ProxmoxServer = "https://proxmox.example.com:8006/api2/json"
$ProxmoxUser = "root@pam"
$ProxmoxPassword = "yourpassword"
$ProxmoxRealm = "pam"
$null = Connect-PVEModule -Server $ProxmoxServer -User $ProxmoxUser -Password $ProxmoxPassword -Realm $ProxmoxRealm
# Event Handler für CheckHostsButton
$CheckHostsButton.Add_Click({
$OutputTextBox.AppendText("Checking Hosts..." + [Environment]::NewLine)
# Hier können Sie den Status Ihrer Proxmox Hosts überprüfen
})
# Event Handler für ListServersButton
$ListServersButton.Add_Click({
$OutputTextBox.AppendText("Listing Servers..." + [Environment]::NewLine)
# Hier können Sie die Liste der Server anzeigen
})
# Event Handler für CreateVMButton
$CreateVMButton.Add_Click({
$OutputTextBox.AppendText("Creating VM from Excel data..." + [Environment]::NewLine)
# Excel-Datei lesen
$excelPath = "C:\path\to\your\vm_data.xlsx"
$vmData = Import-Excel -Path $excelPath
foreach ($vm in $vmData) {
$name = $vm.Name
$memory = $vm.Memory
$cpu = $vm.CPU
$OutputTextBox.AppendText("Creating VM: $name" + [Environment]::NewLine)
New-PVEVM -Node 'pve' -VMID 100 -Name $name -Memory $memory -Sockets $cpu
}
})
$Window.ShowDialog() | Out-Null
+13119
View File
File diff suppressed because it is too large Load Diff
+27
View File
@@ -0,0 +1,27 @@
# Benutzername, Gruppe und Passwort eingeben
$username = Read-Host "Geben Sie den Benutzernamen ein"
$group = Read-Host "Geben Sie den Gruppennamen ein"
$password = Read-Host "Geben Sie das Passwort ein" -AsSecureString
# Konvertiere Passwort in Klartext
$passwordPlainText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
# Liste der Clients
#$clients = @("client1", "client2", "client3", "client4", "client5", "client6", "client7", "client8", "client9", "client10")
$clietns = @("192.168.1.249.")
foreach ($client in $clients) {
# SSH-Verbindung herstellen
$sshSession = New-SSHSession -ComputerName $client -Credential $cred
# Benutzer erstellen
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "sudo useradd -m -s /bin/bash $username"
# Gruppe erstellen und Benutzer hinzufügen
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "sudo groupadd $group"
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "sudo usermod -aG $group $username"
# Passwort setzen
$plaintext = [System.Text.Encoding]::UTF8.GetBytes("$username:$passwordPlainText")
$base64 = [Convert]::ToBase64String($plaintext)
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "echo $base64 | base64 -d | sudo chpasswd"
}
+45
View File
@@ -0,0 +1,45 @@
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Data Entry Form'
$form.Size = New-Object System.Drawing.Size(300,200)
$form.StartPosition = 'CenterScreen'
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,120)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,120)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = 'Please enter the information in the space below:'
$form.Controls.Add($label)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,40)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)
$form.Topmost = $true
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $textBox.Text
$x
}
+21
View File
@@ -0,0 +1,21 @@
$clients = @("192.168.1.249")
foreach ($client in $clients) {
$sshSession = New-SSHSession -ComputerName $client -Credential $cred
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "sudo useradd -m -s /bin/bash username"
}
$groupName = "neue_gruppe"
foreach ($client in $clients) {
$sshSession = New-SSHSession -ComputerName $client -Credential $cred
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "sudo groupadd $groupName"
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "sudo usermod -aG $groupName username"
}
$password = "Passwort123!"
foreach ($client in $clients) {
$sshSession = New-SSHSession -ComputerName $client -Credential $cred
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "username", $securePassword
Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "echo 'username:$password' | sudo chpasswd"
}
+222
View File
@@ -0,0 +1,222 @@
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[ValidateScript({$_.Host -eq 'download.vulnhub.com'})]
[System.Uri]
$VulnhubURI,
[Parameter(Mandatory = $true)]
[ValidateScript({
if (-not (Test-Path $_)) {
throw "Specified path does not exist:`n$_"
}
else {
return $true
}
})]
[String]
$DownloadDirectory,
[Parameter(Mandatory = $true)]
[ValidateScript({
$id = $_
$id -ge 0
if (Invoke-Command -ScriptBlock {qm status $id 2>/dev/null}) {
throw "VM with ID: $id already exists."
}
elseif (Invoke-Command -ScriptBlock {pct status $id 2>/dev/null}) {
throw "Container with ID: $id already exists."
}
else {
return $true
}
})]
[Int]
$VMID,
[Parameter(
Mandatory = $true,
HelpMessage = 'other: unspecified OS; wxp: Windows XP; w2k: Windows 2000; w2k3: Windows 2003; w2k8: Windows 2008; wvista: Windows Vista; win7: Windows 7; win8: Windows 8; win10: Windows 10; l24: Linux Kernel 2.4; l26: Linux Kernel 2.6; solaris: Solaris/OpenSolaris/OpenIndiana kernel'
)]
[ValidateSet('other', 'wxp', 'w2k', 'w2k3', 'w2k8', 'wvista', 'win7','win8', 'win10', 'l24', 'l26', 'solaris')]
[String]
$GuestOSType,
[Parameter(
Mandatory = $true,
HelpMessage = 'Example: local-lvm. This is where the guest boot disk will be stored on the Proxmox node.'
)]
[ValidateScript({
if (-not (pvesm list $_ 2>/dev/null)) {
throw "Storage volume: $_ does not exist."
}
else {
return $true
}
})]
[String]
$VMDiskStorageVolume,
[Parameter(HelpMessage = 'Example: vmbr0')]
[ValidateNotNullOrEmpty()]
[ValidateScript({
if (-not (ip link show $_)) {
throw "Network interface not found."
}
else {
return $true
}
})]
[String]
$NetworkBridge,
[Parameter(HelpMessage = 'Enter an integer between 0 and 4094')]
[ValidateRange(0,4094)]
[Int]
$VlanTag,
[Parameter(HelpMessage = 'Strictly for administrative purposes only.')]
[ValidateNotNullOrEmpty()]
[String]
$VMName,
[Parameter(HelpMessage = 'Example: 2048')]
[Int]
$MemoryMiB
)
begin {
if (-not (which unar)) {
throw "This script requires the program, unar, which is a single archive decompression tool that works on a variety or archive types.`nPlease install that program and re-run the script."
}
function Find-VMDK ($Directory) {
$files = Get-ChildItem $Directory -Recurse
$vmdk = $files | Where-Object {$_.Extension -eq '.vmdk'}
if (-not $vmdk) {
$files | ForEach-Object {
$file = $_
$type = file $file.FullName
$isArchive = $type -like '*archive*' -or $type -like '*compressed*'
if ($isArchive) {
Write-Host "Nested archive found: " -NoNewLine
Write-Host $file.FullName -ForegroundColor Green
$archiveFileFound = $file
}
}
if ($archiveFileFound) {
$subdirectory = "$Directory/temp$(Get-Random)"
unar $archiveFileFound.FullName -o $subdirectory
Find-VMDK -Directory $subdirectory
}
else {
throw "No .vmdk file found and finished recursively checking for archives without results."
}
}
else {
return $vmdk
}
}
if (-not [System.IO.Path]::EndsInDirectorySeparator($DownloadDirectory)) { $DownloadDirectory = $DownloadDirectory + '/' }
$fileName = $VulnhubURI.Segments[-1] # Define the download file name based on the URI provided.
if ($fileName -like '*.iso') { throw "Creating VMs from ISO files not yet implemented." }
$downloadPath = $DownloadDirectory + $fileName
$archiveOutputDirectory = $DownloadDirectory + "temp$(Get-Random)"
$parameterCollection = @()
$parameterCollection += "--ostype $GuestOSType"
$parameterCollection += "--storage $VMDiskStorageVolume"
if ($PSBoundParameters['NetworkBridge']) {
if ($PSBoundParameters['VlanTag']) {
$parameterCollection += "--net0 model=virtio,bridge=$NetworkBridge,firewall=0,tag=$VlanTag"
}
else {
$parameterCollection += "--net0 model=virtio,bridge=$NetworkBridge,firewall=0"
}
}
if ($PSBoundParameters['VMName']) { $parameterCollection += "--name $VMName" }
if ($PSBoundParameters['MemoryMiB']) { $parameterCollection += "--memory $MemoryMiB" }
$parameterString = $parameterCollection -join ' '
}
process {
Write-Host "[+] Downloading VM from Vulnhub. Please be patient...`n" -ForegroundColor Green
wget $VulnhubURI.ToString() -q --show-progress -O $downloadPath
$downloadedVM = Get-ChildItem $downloadPath
try {
Write-Host "[+] Decompressing archive: $downloadedVM to $archiveOutputDirectory`n" -ForegroundColor Green
Write-Host "[!] This may take a while depending on the size of the archive.`n" -ForegroundColor Yellow
unar $downloadedVM.FullName -o $archiveOutputDirectory
}
catch {
throw "Error expanding archive:`n$_"
}
try {
Write-Host "[+] Replacing any whitespace from file paths for compatibility.`n" -ForegroundColor Green
Get-ChildItem $archiveOutputDirectory -Recurse | ForEach-Object { # Arbitrarily try to remove any whitespace in file path, as this has been an issue before
$removeWhiteSpace = $_.FullName -replace ' ', '_'
if ($removeWhiteSpace -ne $_.FullName) {
Move-Item $_.FullName $removeWhiteSpace
}
}
Write-Host "[+] Searching for the .vmdk disk file(s) in $archiveOutputDirectory`n" -ForegroundColor Green
$vmDisk = Find-VMDK -Directory $archiveOutputDirectory
$vmDisk = Find-VMDK -Directory $archiveOutputDirectory # Rediscover the renamed disks
Write-Host "[+] Attempting to convert the VMDK file(s) to QCOW2 to support snapshots.`n" -ForegroundColor Green
$qcow2Disks = @()
$vmDisk | ForEach-Object {
$vmdkfile = $_
$qcow2file = $vmdkfile.FullName -replace 'vmdk', 'qcow2'
$qcow2Disks += $qcow2file
Start-Process qemu-img -ArgumentList "convert -f vmdk -O qcow2 $($vmdkfile.FullName) $qcow2file" -Wait
}
}
catch {
Get-Item $downloadPath, $archiveOutputDirectory | Remove-Item -Recurse -Force # Clean up any artifacts after error.
throw $_
}
try {
Write-Host "[+] Attempting to create the VM with the following command: qm create $VMID $parameterString.`n" -ForegroundColor Green
Start-Process qm -ArgumentList "create $VMID $parameterString" -Wait -RedirectStandardOutput /dev/null
Write-Host "[+] Attempting to import the QCOW2 file(s) as a disk.`n" -ForegroundColor Green
$qcow2Disks | ForEach-Object {
$disk = $_
Write-Host "[+] Running command: qm importdisk $VMID $disk $VMDiskStorageVolume --format qcow2`n" -ForegroundColor Green
Start-Process qm -ArgumentList "importdisk $VMID $disk $VMDiskStorageVolume --format qcow2" -Wait -RedirectStandardOutput /dev/null
}
$iteration = 0
$qcow2Disks | ForEach-Object {
Write-Host "[+] Attempting to attach the disk to the VM's SATA controller.`n" -ForegroundColor Green
Write-Host "[+] Running command: qm set $VMID --sata$iteration $($VMDiskStorageVolume):vm-$VMID-disk-$iteration`n" -ForegroundColor Green
Start-Process qm -ArgumentList "set $VMID --sata$iteration $($VMDiskStorageVolume):vm-$VMID-disk-$iteration" -Wait -RedirectStandardOutput /dev/null
$iteration++
}
Write-Host "[+] Setting sata0 as the boot device.`n" -ForegroundColor Green
Start-Process qm -ArgumentList "set $VMID --boot=`"order=sata0`"" -Wait -RedirectStandardOutput /dev/null
Write-Host "[+] All commands completed successfully`n" -ForegroundColor Green
}
catch {
throw "Command failed with the following error:`n$_"
}
}
end {
if ((Test-Path $downloadPath -ErrorAction SilentlyContinue) -or (Test-Path $archiveOutputDirectory -ErrorAction SilentlyContinue)) {
Write-Host "[+] Removing any files created by the script.`n" -ForegroundColor Green
Remove-Item $downloadPath -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
Remove-Item $archiveOutputDirectory -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
}
}
+24
View File
@@ -0,0 +1,24 @@
Install-Module -Name Corsinvest.ProxmoxVE.Api -Force
Get-Help New-PveNodesQemu -Full
get-help New-PveNodesQemu -Detailed
$ticket = Connect-PveCluster -HostsAndPorts 192.68.1.200:8006,192.168.1.200 -SkipCertificateCheck -ApiToken $Env:PveApiToken
$ret = Get-PveVersion
#Zeigt die PVE Version an
$ret.ToData() |
#Zeigt die PVE Specs an
(Get-PveNodes).ToData() | Select-Object -Property type,node,uptime,status,maxcpu,maxdisk | Out-Default
#Zeigt alle Informationen einer VM an
Get-PveVm -VmIdOrName 3101
#Zeigt alle Snpshots einer VM an
(Get-PveNodesQemuSnapshot -node cc02 -Vmid 102).ToTable()
#oder
(Get-PveVm -VmIdOrName 3101 | Get-PveNodesQemuSnapshot).ToTable()
#new VM anlegen
New-PveNodesQemu -
+45
View File
@@ -0,0 +1,45 @@
Connect-PveCluster -HostsAndPorts 192.168.1.151:8006 -SkipCertificateCheck
Get-PveNode
Get-PveVm
Get-PveAccessDomains
Get-PveAccessRoles
Get-PveNodesAptUpdate
Get-PveNodesDisks
Get-PveNodesStatus
Get-PveVersio
#wert Für NetN
$networkConfig = @{ 1 = [uri]::EscapeDataString("model=virtio,bridge=vmbr0") }
#Netadapter Setting
#Wert für Storage
$storageConfig = @{ 1 = 'local-lvm:32' }
# Storage Setting SATA, IDE, SCSI und VirtIO Block
#Wert für ISO Laufwerk
$bootableIso = @{ 1 = 'local:iso/ubuntu.iso' }
# Sample
#New-PveNodesQemu -Node $node -Vmid 105 -Memory 2048 -ScsiN $storageConfig -IdeN $bootableIso -NetN $networkConfig
#Versions Abfrage
$ret = Get-PveVersion
$ret.Response.data
New-PveNodesQemu -PveTicket $ticket -Vmid 101 -Node "Proxmox-Hyber-V" -Description "Posh Erstellt" -Cores 4 -Memory 1024 -Agent enable -Sata0':'23
New-PveNodesQemu -PveTicket $ticket -Node "Proxmox-Hyber-V" -Vmid 101 -Cores 4
New-PveNodesQemu -PveTicket $ticket -Node "Proxmox-Hyber-V" -Vmid 102 -Cores 4 -Memory "1024"
New-PveNodesQemu -PveTicket $ticket -Node "Proxmox-Hyber-V" -Vmid 103 -Cores 4 -Memory "1024" -SataN $storageConfig
Set-PveNodesQemuConfig -PveTicket $ticket -Node 101 -Acpi:$true -Agent "Enable"
$ticket = (Connect-PveCluster -HostsAndPorts 192.168.1.151:8006 -SkipCertificateCheck | Where-Object Ticket)
$id = Read-Host "Bitte die VM ID eingeben! : "
Set-PveNodesQemuConfig -vmid $id -PveTicket $ticket -kvm:$true -Agent 'Enable' -SataN $storageConfig
get-help Set-PveNodesQemuConfig -Detailed
+75
View File
@@ -0,0 +1,75 @@
<#
Variablenblock
#>
#
$Global:pvecredential = Get-Credential -UserName "root" -Message "Anmeldung am Proxmox"
$pveUsername = ($Global:pvecredential).UserName
$pvePwENcrypt = ConvertFrom-SecureString -SecureString ($Global:pvecredential).Password
$hostpve = Read-Host 'Bitte die IP des Servers eingeben: '
$ticket = (Connect-PveCluster -HostsAndPorts $($hostpve)':8006' -Credentials $Global:pvecred -SkipCertificateCheck | Where-Object Ticket)
$vers = $PSVersionTable.PSVersion.Major
if ($vers -gt '5') {
Write-Host "
Mit Ihrer Version $vers kann das Script ausgeführt werden.
"
}
else {
Write-Host "Mit Ihrer Powershell Version kann dieses Script nicht ausgeführt werden."
}
function newvm {
param (
[Parameter(Mandatory=$true)]
[ValidateSet("SataN","IdeN","ScsiN")]$hddtype
)
$vmid = Read-Host "Geben Sie die VM ID ein : "
$core = Read-Host "Wieviele Core's soll die VM haben : "
$mem = Read-Host "Wieviel RAM soll die VM haben, einbae in MB: "
$hdd = Read-Host "Wie groß soll die Festplatte sein, eingabe in GB: "
$hddtype = Read-Host "Was für ein HDD Typ soll es sein (SataN, Ide, ScsiN): "
$hddlocation = Read-Host "Wo Soll die HDD liegen: "
$storageConfig = @{ 1 = "$($hddlocation):$($hdd)" }
$storageConfig
New-PveNodesQemu -PveTicket $ticket -Vmid $vmid -Description "Posh Erstellt" -Cores $core -Memory $mem -Agent "True" enable -Node "Proxmox-Hyber-V" -$($hddtype) $storageConfig
Write-Host "Function New VM"11
}
function change {
#New-PveNodesQemu -PveTicket $ticket -Vmid 101 -Description "Posh Erstellt" -Cores 4 -Memory 1024 -Agent enable -Sata0':'23 -Node "Proxmox-Hyber-V"
Write-Host "Function Change VM"
}
function delete {
#New-PveNodesQemu -PveTicket $ticket -Vmid 101 -Description "Posh Erstellt" -Cores 4 -Memory 1024 -Agent enable -Sata0':'23 -Node "Proxmox-Hyber-V"
Write-Host "Function delete VM"
}
function Show-CustomMenu
{
param (
[string]$menuname = 'Proxmox VE VM Menü'
)
Clear-Host
Write-Host "================ $menuname ================"
Write-Host "1: Wähle '1' Erstellung einer Neues VM"
Write-Host "2: Wähle '2' Ändern einer VM"
Write-Host "3: Wähle '3' Löschen einer VM"
Write-Host "x: Beenden "
}
# Menue aufrufen und Titel uebergeben
Show-CustomMenu menuname 'Proxmox VE VM Menü'
do {
$choice = Read-Host Show-CustomMenu
switch ($choice) {
1 { newvm -hddtype SataN }
2 { change }
3 { delete }
x { return }
}
} while (
$choice = "X"
)
+44
View File
@@ -0,0 +1,44 @@
#Connection to cluster user and password
Connect-PveCluster -HostsAndPorts 192.168.1.151:8006 -SkipCertificateCheck
PowerShell credential request
Proxmox VE Username and password, username formatted as user@pam, user@pve, user@yourdomain or user (default domain pam).
User: root
Password for user test: ****
#return Ticket, default set $Global:PveTicketLast
#this is useful when connections to multiple clusters are needed use parameter -SkipRefreshPveTicketLast
HostName : 192.168.190.191
Port : 8006
SkipCertificateCheck : True
Ticket : PVE:test@pam:5EFF3CCA::iXhSNb5NTgNUYznf93mBOhj8pqYvAXoecKBHCXa3coYwBWjsWO/x8TO1gIDX0yz9nfHuvY3alJ0+Ew5AouOTZlZl3NODO9Cp4Hl87qnzhsz4wvoYEzvS1NUOTBekt+yAa68jdbhP
OzhOd8ozEEQIK7Fw2lOSa0qBFUTZRoMtnCnlsjk/Nn3kNEnZrkHXRGm46fA+asprvr0nslLxJgPGh94Xxd6jpNDj+xJnp9u6W3PxiAojM9g7IRurbp7ZCJvAgHbA9FqxibpgjaVm4NCd8LdkLDgCROxgYCjI3eR
gjkDvu1P7lLjK9JxSzqnCWWD739DT3P3bW+Ac3SyVqTf8sw==
CSRFPreventionToken : 5EFF3CCA:Cu0NuFiL6CkhFdha2V+HHigMQPk
#Connection to cluster using Api Token
Connect-PveCluster -HostsAndPorts 192.168.190.191:8006,192.168.190.192 -SkipCertificateCheck -ApiToken root@pam!qqqqqq=8a8c1cd4-d373-43f1-b366-05ce4cb8061f
HostName : 192.168.190.191
Port : 8006
SkipCertificateCheck : True
Ticket :
CSRFPreventionToken :
ApiToken : root@pam!qqqqqq=8a8c1cd4-d373-43f1-b366-05ce4cb8061f
#For disable output call Connect-PveCluster > $null
#Get version
$ret = Get-PveVersion
#$ret return a class PveResponse
#Show data
$ret.Response.data
#repoid release keyboard version
#------ ------- -------- -------
#d0ec33c6 15 it 5.4
#Show data 2
$ret.ToTable()
repoid release keyboard version
------ ------- -------- -------
d0ec33c6 15 it 5.4
View File
+2
View File
@@ -0,0 +1,2 @@
tcn 192.168.1.200
Test-Connection 192.168.1.200; 192.168.1.199; 192.168.1.198
File diff suppressed because it is too large Load Diff
+50
View File
@@ -0,0 +1,50 @@
# Parameter
$excelPath = "C:\Pfad\zu\hosts.xlsx"
$isoPath = "C:\Pfad\zu\original.iso"
$tempPath = "C:\Temp\IsoContents"
$newIsoPath = "C:\Pfad\zu\custom.iso"
# Import-Excel Modul laden
Import-Module ImportExcel
# Excel-Daten lesen
$hostsData = Import-Excel -Path $excelPath
# ISO mounten und Dateien kopieren
Mount-DiskImage -ImagePath $isoPath
$disk = Get-DiskImage -ImagePath $isoPath
$volume = Get-Volume -DiskImage $disk
Copy-Item -Path "$($volume.DriveLetter):\*" -Destination $tempPath -Recurse
Dismount-DiskImage -ImagePath $isoPath
# ks.cfg aktualisieren
$ksPath = "$tempPath\ks.cfg"
$configContent = Get-Content -Path $ksPath
foreach ($host in $hostsData) {
$hostname = $host.Hostname
$ip = $host.'IP-Adresse'
$netmask = $host.Netzmaske
$gateway = $host.Gateway
$dns = $host.'DNS-Server'
$username = $host.Benutzername
$password = $host.Passwort
$timezone = $host.Zeitzone
$partitioning = $host.Partitionierung
$configContent = $configContent -replace "<hostname_placeholder>", $hostname
$configContent = $configContent -replace "<ip_placeholder>", $ip
$configContent = $configContent -replace "<netmask_placeholder>", $netmask
$configContent = $configContent -replace "<gateway_placeholder>", $gateway
$configContent = $configContent -replace "<dns_placeholder>", $dns
$configContent = $configContent -replace "<password_placeholder>", $password
$configContent = $configContent -replace "<timezone_placeholder>", $timezone
$configContent = $configContent -replace "<partitioning_placeholder>", $partitioning
}
$configContent | Set-Content -Path $ksPath
# Neue ISO erstellen
& oscdimg -n -m -b"$tempPath\boot\etfsboot.com" $tempPath $newIsoPath
Write-Host "Neue ISO wurde erstellt: $newIsoPath"
+163
View File
@@ -0,0 +1,163 @@
# Import necessary modules
Import-Module Corsinvest.ProxmoxVE.Api
Import-Module ImportExcel
Add-Type -AssemblyName System.Windows.Forms
# Proxmox connection info
$ProxmoxURL = "https://your-proxmox-url:8006"
$ProxmoxUser = "root"
$ProxmoxPassword = "P@ssw0rd"
$ProxmoxRealm = "pam"
# Connect to Proxmox
$credentials = New-Object System.Management.Automation.PSCredential ($ProxmoxUser, (ConvertTo-SecureString $ProxmoxPassword -AsPlainText -Force))
$null = Connect-PveCluster -Server $ProxmoxURL -User $ProxmoxUser -Realm $ProxmoxRealm -Credential $credentials
# Read Excel data
$excelPath = "C:\path\to\depl_systems.xlsx"
$hostsData = Import-Excel -Path $excelPath
# Function to get VMs from Proxmox
function Get-ProxmoxVMs {
$vms = Get-PveVMList
return $vms
}
# Function to check missing VMs
function Get-MissingVMs {
$proxmoxVMs = Get-ProxmoxVMs
$missingVMs = @()
foreach ($host in $hostsData) {
$vmName = $host.'VM-Name'
if ($proxmoxVMs | Where-Object { $_.name -eq $vmName } -eq $null) {
$missingVMs += $host
}
}
return $missingVMs
}
# Function to get node usage
function Get-NodeUsage {
param ($node)
$usage = Get-PveNodeStatus -NodeName $node
return @{
Node = $node
MaxMem = $usage.memory.total
Mem = $usage.memory.used
MaxDisk = $usage.rootfs.total
Disk = $usage.rootfs.used
}
}
# Function to create and start VM
function Create-VM {
param (
$node,
$vmId,
$vmName,
$vmCores,
$vmMemory,
$vmDiskSize,
$isoFile
)
$params = @{
NodeName = $node
VMID = $vmId
Name = $vmName
Cores = $vmCores
Memory = $vmMemory
DiskSize = $vmDiskSize
ISOImage = $isoFile
}
New-PveVM @params
Start-PveVM -NodeName $node -VMID $vmId
Write-Host "VM wurde auf dem Node $node erstellt und gestartet"
}
# Create GUI
$form = New-Object System.Windows.Forms.Form
$form.Text = "Proxmox VM Manager"
$form.Size = New-Object System.Drawing.Size(600, 400)
$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Size = New-Object System.Drawing.Size(560, 300)
$listBox.Location = New-Object System.Drawing.Point(10, 10)
$buttonCheck = New-Object System.Windows.Forms.Button
$buttonCheck.Text = "Check Missing VMs"
$buttonCheck.Size = New-Object System.Drawing.Size(120, 30)
$buttonCheck.Location = New-Object System.Drawing.Point(10, 320)
$buttonCheck.Add_Click({
$missingVMs = Get-MissingVMs
$listBox.Items.Clear()
if ($missingVMs.Count -eq 0) {
$listBox.Items.Add("Es fehlen keine VMs.")
} else {
foreach ($vm in $missingVMs) {
$listBox.Items.Add("$($vm.'VM-Name')")
}
}
})
$buttonDeploy = New-Object System.Windows.Forms.Button
$buttonDeploy.Text = "Deploy Missing VMs"
$buttonDeploy.Size = New-Object System.Drawing.Size(120, 30)
$buttonDeploy.Location = New-Object System.Drawing.Point(140, 320)
$buttonDeploy.Add_Click({
$missingVMs = Get-MissingVMs
if ($missingVMs.Count -eq 0) {
[System.Windows.Forms.MessageBox]::Show("Es fehlen keine VMs.")
return
}
foreach ($hostData in $missingVMs) {
# Create custom ISO for host (implement your own logic)
$customIsoPath = "C:\path\to\custom.iso"
# Upload ISO to Proxmox
$isoUploadPath = "/var/lib/vz/template/iso/custom.iso"
$null = Upload-PveFile -NodeName $bestNode.Node -ContentType iso -FilePath $customIsoPath -Storage local
# Get cluster nodes and their usage
$nodes = Get-PveNode
$nodeUsages = @()
foreach ($node in $nodes) {
$nodeUsages += Get-NodeUsage -node $node.name
}
# Select the best node based on available resources
$bestNode = $nodeUsages | Sort-Object {[math]::Min($_.MaxMem - $_.Mem, $_.MaxDisk - $_.Disk)} -Descending | Select-Object -First 1
Write-Host "Der beste Node zur Erstellung der VM ist: $($bestNode.Node)"
# VM creation parameters
$vmId = $hostData.'VM-ID'
$vmName = $hostData.'VM-Name'
$vmCores = $hostData.'Cores'
$vmMemory = $hostData.'Memory'
$vmDiskSize = $hostData.'Disk-Size'
$isoFile = "local:iso/custom.iso"
# Create and start the VM
Create-VM -node $bestNode.Node -vmId $vmId -vmName $vmName -vmCores $vmCores -vmMemory $vmMemory -vmDiskSize $vmDiskSize -isoFile $isoFile
}
[System.Windows.Forms.MessageBox]::Show("Alle fehlenden VMs wurden erstellt.")
})
$form.Controls.Add($listBox)
$form.Controls.Add($buttonCheck)
$form.Controls.Add($buttonDeploy)
# Load existing VMs into the listbox
$listBox.Items.Clear()
$vms = Get-ProxmoxVMs
foreach ($vm in $vms) {
$listBox.Items.Add($vm.name)
}
$form.ShowDialog()
+23
View File
@@ -0,0 +1,23 @@
# Verbindung zu Linux-System herstellen
$session = New-PSSession -HostName "192.168.1.249" -UserName "root" -Password "P@ssw0rd"
# Benutzer anlegen
Invoke-Command -Session $session -ScriptBlock {
sudo useradd -m -s /bin/bash michael
}
# Gruppe anlegen
Invoke-Command -Session $session -ScriptBlock {
sudo groupadd global
}
# Benutzer zur Gruppe hinzufügen
Invoke-Command -Session $session -ScriptBlock {
sudo usermod -aG global michael
}
# Passwort für den Benutzer setzen
$password = ConvertTo-SecureString "<Passwort>" -AsPlainText -Force
Invoke-Command -Session $session -ScriptBlock {
echo "<Benutzername>:<Passwort>" | sudo chpasswd
}
+50
View File
@@ -0,0 +1,50 @@
# Import necessary modules
Import-Module Corsinvest.ProxmoxVE.Api
Import-Module ImportExcel
# Proxmox connection info
$ProxmoxURL = "https://your-proxmox-url:8006"
$ProxmoxUser = "root"
$ProxmoxPassword = "P@ssw0rd"
$ProxmoxRealm = "pam"
# Connect to Proxmox
$credentials = New-Object System.Management.Automation.PSCredential ($ProxmoxUser, (ConvertTo-SecureString $ProxmoxPassword -AsPlainText -Force))
$null = Connect-PveCluster -Server $ProxmoxURL -User $ProxmoxUser -Realm $ProxmoxRealm -Credential $credentials
# Read Excel data
$excelPath = "/path/to/depl_systems.xlsx"
$hostsData = Import-Excel -Path $excelPath
# Function to get VMs from Proxmox
function Get-ProxmoxVMs {
$vms = Get-PveVM
return $vms
}
# Function to check missing VMs
function Get-MissingVMs {
$proxmoxVMs = Get-ProxmoxVMs
$missingVMs = @()
foreach ($host in $hostsData) {
$vmName = $host.'VM-Name'
if ($proxmoxVMs | Where-Object { $_.name -eq $vmName } -eq $null) {
$missingVMs += $host
}
}
return $missingVMs
}
# Function to get node usage
function Get-NodeUsage {
param ($node)
$usage = Get-PveNodeStatus -NodeName $node
return @{
Node = $node
MaxMem = $usage.memory.total
Mem = $usage.memory.used
MaxDisk = $usage.rootfs.total
+26
View File
@@ -0,0 +1,26 @@
# Verbindung zu Linux-System herstellen
$session = New-PSSession -HostName 192.168.1.151 -UserName 'root' -Password 'P@ssw0rd'
# Benutzer anlegen
Invoke-Command -Session $session -ScriptBlock {
sudo useradd -m -s /bin/bash ADMInst
}
# Gruppe anlegen
Invoke-Command -Session $session -ScriptBlock {
sudo groupadd deploy
}
# Benutzer zur Gruppe hinzufügen
Invoke-Command -Session $session -ScriptBlock {
sudo usermod -aG deploy ADMInst
}
# Passwort für den Benutzer setzen
$password = ConvertTo-SecureString "<Passwort>" -AsPlainText -Force
Invoke-Command -Session $session -ScriptBlock {
echo "<Benutzername>:<Passwort>" | sudo chpasswd
}
# Sitzung schließen
Remove-PSSession $session