more ps1 scripts

This commit is contained in:
Gramzon
2025-02-03 14:16:10 +01:00
parent 3f8a8fc637
commit 112f47e21e
4 changed files with 105 additions and 0 deletions
@@ -0,0 +1,33 @@
# In this scrip we will add the created shared folder for installfiles to the dfsnamespace infrait\files on SRV1
# Define the remote computer name
$remoteComputerName = "srv1"
# Define the share name
$shareName = "InstallFiles"
# Define the folderName
$folderName = "installfiles"
# Define the ShareFolderPath
$ShareFolderPath = "C:\shares\$folderName"
# Define the DFSNamespace
$DFSNamespace = "InfraIT\Files"
$dfsfolder = "\\$remoteComputerName\$shareName"
# DFS Target Path
$DFSTargetPath = "\\$remoteComputerName\$shareName"
# Create a new PowerShell session to the remote server
$session = New-PSSession -ComputerName $remoteComputerName
# Add the folder to the DFS Namespace and add new dfsn folder target
Invoke-Command -Session $session -ScriptBlock {
param($DFSNamespace, $folderName, $DFSTargetPath)
# Add the folder to the DFS Namespace
New-DfsnFolder -Path "$DFSNamespace\$folderName" -TargetPath $DFSTargetPath -ErrorAction SilentlyContinue
New-DfsnFoldertarget -Path "$DFSNamespace\$folderName" -TargetPath $DFSTargetPath -ErrorAction SilentlyContinue
Write-Host "Folder added to DFS Namespace"
} -ArgumentList $DFSNamespace, $folderName, $DFSTargetPath
@@ -0,0 +1,24 @@
# In this script we will create a file share on the remote server to store the installation files.
$remoteComputerName = "srv1"
# Create a new POwerShell Session to the remote server
$session = New-PSSession -ComputerName $remoteComputerName
# Define the directory to create on the remote server
$newDirectory = "C:\shares\installfiles"
# Create the new directory on the remote server
Invoke-Command -Session $session -ScriptBlock {
param($newDirectory)
If(-not (Test-Path $newDirectory)) {
# Create the new directory if it does not exist
New-Item -Path $newDirectory -ItemType Directory
Write-Host "Directory created at $newDirectory"
} else {
Write-Host "Directory already exists at $newDirectory"
}
} -ArgumentList $newDirectory
# Close the PowerShell session
Remove-PSSession -Session $session
@@ -0,0 +1,20 @@
# Define the URL of the file to download
$fileURL = "https://www.7-zip.org/a/7z2409-x64.msi"
# Define the path to save the file
$destinationPath = "C:\shares\installfiles\7z2409-x64.msi"
# Define the remote server name
$remoteServerName = "srv1"
# Script block to download the file
$scriptBlock = {
param($fileURL, $destinationPath)
# Use invoke-webrequest to download the file
Invoke-WebRequest -Uri $fileURL -OutFile $destinationPath
Write-Host "File downloaded to $destinationPath"
}
# Execute the script block on the remote server
Invoke-Command -ComputerName $remoteServerName -ScriptBlock $scriptBlock -ArgumentList $fileURL, $destinationPath
@@ -0,0 +1,28 @@
# In this script we will create a file share
$remoteComputerName = "srv1"
# define the directory path
$directoryPath = "C:\shares\installfiles"
# Define the share name
$shareName = "InstallFiles"
# Create a new PowerShell session to the remote server
$session = New-PSSession -ComputerName $remoteComputerName
# Share The folder and set NTFS Permissions
Invoke-Command -Session $session -ScriptBlock {
param($directoryPath, $shareName)
# Create the new directory if it does not exist
If(-not (Test-Path $directoryPath)) {
New-Item -Path $directoryPath -ItemType Directory
Write-Host "Directory created at $directoryPath"
} else {
Write-Host "Directory already exists at $directoryPath"
}
# Share the folder
New-SmbShare -Name $shareName -Path $directoryPath -FullAccess "Everyone"
Write-Host "Folder shared as $shareName"
} -ArgumentList $directoryPath, $shareName