Initial commit
This commit is contained in:
39
.gitignore
vendored
Normal file
39
.gitignore
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# --- Geheimnisse & Lokale Konfiguration ---
|
||||
.env
|
||||
.env.local
|
||||
config/local.yaml
|
||||
|
||||
# Betriebssysteme
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might be created in the root of a FAT file system
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
|
||||
# Editoren / IDEs
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*~
|
||||
|
||||
# Logs und temporäre Dateien
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# --- Build-Ausgaben, Executables & Cache ---
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dmg
|
||||
*.iso
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
4565
Function_Convert-WindowsImage.ps1
Normal file
4565
Function_Convert-WindowsImage.ps1
Normal file
File diff suppressed because it is too large
Load Diff
58
Function_MW-CreateProfileFolder.ps1
Normal file
58
Function_MW-CreateProfileFolder.ps1
Normal file
@@ -0,0 +1,58 @@
|
||||
FUNCTION MW-CreateProfileFolder {
|
||||
<#
|
||||
THis function creates a root folder for Roaming Profiles with the appropriate file permissions
|
||||
You need to define the admin group name that can access the folder,
|
||||
if no Admingroup Parameter is defined the local Admin group is used
|
||||
|
||||
Example:
|
||||
|
||||
MW-CreateProfileFolder -folder C:\Profiles
|
||||
will create the folder, set the appropriate folder permissions on C:\Profiles with the local admin account
|
||||
and will share it as Profiles$
|
||||
#>
|
||||
|
||||
Param ($folder,
|
||||
$adminGroup)
|
||||
|
||||
if ($adminGroup -eq $null){
|
||||
Write-host "no admin group defined, using builtin group"
|
||||
$objSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544")
|
||||
$adminGroup = ( $objSID.Translate([System.Security.Principal.NTAccount]) ).Value
|
||||
}
|
||||
|
||||
# Create folder if not existent
|
||||
IF (!(Test-path $folder)) {MD $folder}
|
||||
|
||||
$DefaultAccessGroup = "authenticated users"
|
||||
|
||||
#share folder
|
||||
$Sharename = "$($folder.split("\")[-1])" + "`$"
|
||||
Write-host "trying to create a share with the name $Sharename"
|
||||
if (Get-SmbShare $sharename -ea SilentlyContinue){
|
||||
write-host "share is already existent, will not create it"
|
||||
} ELSE {
|
||||
New-SmbShare -Path $folder -Name $sharename -FullAccess $DefaultAccessGroup
|
||||
}
|
||||
|
||||
|
||||
# remove inheritence
|
||||
$acl = Get-Acl $Folder
|
||||
$acl.SetAccessRuleProtection($true,$true)
|
||||
$acl |Set-Acl
|
||||
|
||||
# remove all rights
|
||||
$acl = Get-Acl $Folder
|
||||
$acl.Access | % {$acl.purgeaccessrules($_.IdentityReference)}
|
||||
# add new acl
|
||||
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule $adminGroup ,"Fullcontrol", "ContainerInherit,ObjectInherit", "None","Allow"
|
||||
$acl.AddAccessRule($rule)
|
||||
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule "SYSTEM","Fullcontrol", "ContainerInherit,ObjectInherit", "None","Allow"
|
||||
$acl.AddAccessRule($rule)
|
||||
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule "Creator Owner","Fullcontrol", "ContainerInherit,ObjectInherit", "InheritOnly","Allow"
|
||||
$acl.AddAccessRule($rule)
|
||||
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule $DefaultAccessGroup,"AppendData, ReadAndExecute", "None", "None","Allow"
|
||||
$acl.AddAccessRule($rule)
|
||||
$acl | set-acl
|
||||
|
||||
|
||||
} #EndFUNCTION MW-CreateProfileFolder
|
||||
23
Function_MW-ShowUEVPKGXRegistry.ps1
Normal file
23
Function_MW-ShowUEVPKGXRegistry.ps1
Normal file
@@ -0,0 +1,23 @@
|
||||
FUNCTION MW-ShowUEVPKGXRegistry {
|
||||
<#
|
||||
This functions shows the actual registry values in a PKGX file (UEV)
|
||||
The parameter is the path to the PKGX file
|
||||
Example
|
||||
|
||||
MW-ShowPKGXRegistry "C:\UEV\Join\SettingsPackages\MicrosoftWordpad6\MicrosoftWordpad6.pkgx"
|
||||
#>
|
||||
|
||||
|
||||
Param ($PKGXFile)
|
||||
$stream = Export-UevPackage $PKGXFile
|
||||
$data = $stream.split("`n")
|
||||
$matches = $null
|
||||
foreach ($line in $data){
|
||||
if ($line -match 'HKCU(.*)" Action="(.*)">(.*)<'){
|
||||
Write-host "REgkey: $($matches[1]) `t`t $($matches[3])"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} #EndFUNCTION MW-ShowUEVPKGXRegistry
|
||||
34
Function_StartCountdown.ps1
Normal file
34
Function_StartCountdown.ps1
Normal file
@@ -0,0 +1,34 @@
|
||||
Function Start-Countdown {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Provide a graphical countdown if you need to pause a script for a period of time
|
||||
.PARAMETER Seconds
|
||||
Time, in seconds, that the function will pause
|
||||
.PARAMETER Messge
|
||||
Message you want displayed while waiting
|
||||
.EXAMPLE
|
||||
Start-Countdown -Seconds 30 -Message Please wait while Active Directory replicates data...
|
||||
.NOTES
|
||||
Author: Martin Pugh
|
||||
Twitter: @thesurlyadm1n
|
||||
Spiceworks: Martin9700
|
||||
Blog: www.thesurlyadmin.com
|
||||
|
||||
Changelog:
|
||||
2.0 New release uses Write-Progress for graphical display while couting
|
||||
down.
|
||||
1.0 Initial Release
|
||||
.LINK
|
||||
http://community.spiceworks.com/scripts/show/1712-start-countdown
|
||||
#>
|
||||
|
||||
Param(
|
||||
[Int32]$Seconds = 10,
|
||||
[string]$Message = "Pausing for 10 seconds..."
|
||||
)
|
||||
ForEach ($Count in (1..$Seconds))
|
||||
{ Write-Progress -Id 1 -Activity $Message -Status "Waiting for $Seconds seconds, $($Seconds - $Count) left" -PercentComplete (($Count / $Seconds) * 100)
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
Write-Progress -Id 1 -Activity $Message -Status "Completed" -PercentComplete 100 -Completed
|
||||
} #End Function Start-Countdown
|
||||
62
Function_TK_AzStorageAccountName.ps1
Normal file
62
Function_TK_AzStorageAccountName.ps1
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
|
||||
|
||||
Function TK_AzStorageAccountName {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_AzStorageAccountName
|
||||
.DESCRIPTION
|
||||
Create a unique storage account name for aAzure
|
||||
.PARAMETER StrToHash
|
||||
String for the Hash eg. your-company-name
|
||||
.PARAMETER CharsToUse
|
||||
Character to use
|
||||
.EXAMPLE
|
||||
TK_AzStorageAccountName -StrToHash "Login-Consultants" -CharsToUse 12 (max. 64)
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 13.03.2020 | v0.1 | Initial script
|
||||
Last change : 13.03.2020 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position = 0)][String]$StrToHash,
|
||||
[Parameter(Mandatory=$true, Position = 1)][Int]$CharsToUse
|
||||
)
|
||||
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
$stringAsStream = [System.IO.MemoryStream]::new()
|
||||
$writer = [System.IO.StreamWriter]::new($stringAsStream)
|
||||
$writer.write($StrToHash)
|
||||
$writer.Flush()
|
||||
$stringAsStream.Position = 0
|
||||
[string]$strHash = Get-FileHash -InputStream $stringAsStream | Select-Object Hash
|
||||
|
||||
if ([Int]$CharsToUse -gt 64) {
|
||||
[Int]$CharsToUse = 64
|
||||
}
|
||||
|
||||
Write-Host $strHash.Substring(7,[Int]$CharsToUse).ToLower()
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
} #EndFunction TK_AzStorageAccountName
|
||||
|
||||
# Example function call
|
||||
TK_AzStorageAccountName -StrToHash "Login-Consultants" -CharsToUse 12
|
||||
56
Function_TK_CleanupDirectory.ps1
Normal file
56
Function_TK_CleanupDirectory.ps1
Normal file
@@ -0,0 +1,56 @@
|
||||
Function TK_CleanupDirectory {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_CleanupDirectory
|
||||
.DESCRIPTION
|
||||
Delete all files and subfolders in one specific directory, but do not delete the main folder itself
|
||||
.PARAMETER Directory
|
||||
This parameter contains the full path to the directory that needs to cleaned (for example 'C:\Temp')
|
||||
.EXAMPLE
|
||||
TK_CleanupDirectory -Directory "C:\Temp"
|
||||
Deletes all files and subfolders in the directory 'C:\Temp'
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 15.05.2017 | v0.1 | Initial script
|
||||
Last change : 15.05.2018 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position = 0)][String]$Directory
|
||||
)
|
||||
|
||||
begin {
|
||||
[string]$FunctionName = $PSCmdlet.MyInvocation.MyCommand.Name
|
||||
Write-Verbose "START FUNCTION - $FunctionName"
|
||||
}
|
||||
|
||||
process {
|
||||
if ( Test-Path $Directory ) {
|
||||
try {
|
||||
Remove-Item "$Directory\*.*" -force -recurse | Out-Null
|
||||
Remove-Item "$Directory\*" -force -recurse | Out-Null
|
||||
Write-Verbose "Successfully deleted all files and subfolders in the directory $Directory"
|
||||
} catch {
|
||||
Write-Verbose "An error occurred trying to delete files and subfolders in the directory $Directory (exit code: $($Error[0]))!"
|
||||
Exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Verbose "The directory $Directory does not exist."
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Verbose "END FUNCTION - $FunctionName"
|
||||
}
|
||||
} #EndFunction TK_CleanupDirectory
|
||||
56
Function_TK_CompressDirectory.ps1
Normal file
56
Function_TK_CompressDirectory.ps1
Normal file
@@ -0,0 +1,56 @@
|
||||
Function TK_CompressDirectory {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_CompressDirectory
|
||||
.DESCRIPTION
|
||||
Execute the process compress.exe
|
||||
.PARAMETER Directory
|
||||
his parameter contains the full path to the directory that needs to be compressed (for example C:\temp)
|
||||
.EXAMPLE
|
||||
TK_CompressDirectory -Directory "C:\temp"
|
||||
Compacts the directory 'C:\temp'
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 26.07.2017 | v0.1 | Initial script
|
||||
Last change : 26.07.2018 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position = 0)][String]$Directory
|
||||
)
|
||||
|
||||
begin {
|
||||
[string]$FunctionName = $PSCmdlet.MyInvocation.MyCommand.Name
|
||||
Write-Verbose "START FUNCTION - $FunctionName" $LogFile
|
||||
}
|
||||
|
||||
process {
|
||||
Write-Verbose "Compress files in the directory $Directory" $LogFile
|
||||
if ( Test-Path $Directory ) {
|
||||
try {
|
||||
$params = " /C /S /I /Q /F $($Directory)\*"
|
||||
start-process "$WinDir\System32\compact.exe" $params -WindowStyle Hidden -Wait
|
||||
Write-Verbose "Successfully compressed all files in the directory $Directory"
|
||||
} catch {
|
||||
Write-Verbose "An error occurred trying to compress the files in the directory $Directory (exit code: $($Error[0]))!"
|
||||
Exit 1
|
||||
}
|
||||
} else {
|
||||
Write-verbose "The directory $Directory does not exist. Nothing to do"
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Verbose "END FUNCTION - $FunctionName"
|
||||
}
|
||||
} #EndFunction TK_CompressDirectory
|
||||
41
Function_TK_Confirm-DomainAdmin.ps1
Normal file
41
Function_TK_Confirm-DomainAdmin.ps1
Normal file
@@ -0,0 +1,41 @@
|
||||
function TK_Confirm-DomainAdmin {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Confirm Domain Admin
|
||||
.DESCRIPTION
|
||||
Check if user is domain admin
|
||||
.PARAMETER UserName
|
||||
user to check, if not given current user is used
|
||||
.EXAMPLE
|
||||
TK_Confirm-DomainAdmin -UserName Thomas
|
||||
Check if "Thomas" is domain admin
|
||||
.EXAMPLE
|
||||
TK_Confirm-DomainAdmin
|
||||
Check if current user is domain admin
|
||||
#>
|
||||
|
||||
[cmdletbinding()]
|
||||
param (
|
||||
$UserName = $env:USERNAME
|
||||
)
|
||||
begin {
|
||||
$domainadmins = (Get-ADGroupMember 'domain admins').samaccountname
|
||||
}
|
||||
process {
|
||||
foreach ($user in $UserName) {
|
||||
if ($user -in $domainadmins) {
|
||||
Write-Verbose "$User is a member of the domain admins group"
|
||||
$domainadmin = $true
|
||||
}
|
||||
else {
|
||||
Write-Verbose "$User is not a member of the domain admins group"
|
||||
$domainadmin = $false
|
||||
}
|
||||
|
||||
[pscustomobject]@{
|
||||
User = $user
|
||||
DomainAdmin = $domainadmin
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
82
Function_TK_CopyAzureVHDToAzureBlob.ps1
Normal file
82
Function_TK_CopyAzureVHDToAzureBlob.ps1
Normal file
@@ -0,0 +1,82 @@
|
||||
Function TK_CopyVHDToBlob {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Copy / Download a managed Azure Disk to Azure Storage account
|
||||
.DESCRIPTION
|
||||
Copy / Download a managed Azure Disk to Azure Storage account
|
||||
.PARAMETER SubscriptionID
|
||||
Azure Subscription ID eg. 11111111-2222-3333-4444-555555555555
|
||||
.PARAMETER ResourceGroupName
|
||||
The name of the ResourceGroup where the disk is stored eg. my-resources
|
||||
.PARAMETER ManagedDiskName
|
||||
The Name of the managed disk eg. test01_OsDisk_1_729ca8fexxxxxx849c2a8d89d21119db
|
||||
.PARAMETER DestStorageAccName
|
||||
The Name of the destination storage account eg. mystorage
|
||||
.PARAMETER DestStorageAccKey
|
||||
The access key for that storage account eg.
|
||||
.PARAMETER StorageContainerName
|
||||
The Name of the destination container in that storage account eg. myimages
|
||||
.PARAMETER VHDFileName
|
||||
Name of the VHD file eg. myimage.vhd
|
||||
.EXAMPLE
|
||||
TK_CopyVHDToBlob -SubscriptionID xxxx -ResourceGroupName "my-resources"" -ManagedDiskName "test01_=OsDisk_1_xxx" -DestStorageAccName "mystorage" -DestStorageAccKey "abcxxxx==" -StorageContainerName "myimages" -VHDFileName "myimage.vhd"
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 23.08.2019 | v0.1 | Initial script
|
||||
Last change : 23.08.2019 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory = $true, Position = 0)][String]$SubscriptionID,
|
||||
[Parameter(Mandatory = $true, Position = 1)][String]$ResourceGroupName,
|
||||
[Parameter(Mandatory = $true, Position = 2)][String]$ManagedDiskName,
|
||||
[Parameter(Mandatory = $true, Position = 3)][String]$DestStorageAccName,
|
||||
[Parameter(Mandatory = $true, Position = 4)][String]$DestStorageAccKey,
|
||||
[Parameter(Mandatory = $true, Position = 5)][String]$StorageContainerName,
|
||||
[Parameter(Mandatory = $true, Position = 6)][String]$VHDFileName
|
||||
)
|
||||
|
||||
begin {
|
||||
Connect-AzAccount
|
||||
}
|
||||
|
||||
process {
|
||||
Select-AzSubscription -SubscriptionId $SubscriptionID
|
||||
$sas = Grant-AzDiskAccess -ResourceGroupName $ResourceGroupName -DiskName $ManagedDiskName -DurationInSecond 3600 -Access Read
|
||||
|
||||
$destContext = New-AzStorageContext –StorageAccountName $DestStorageAccName -StorageAccountKey $DestStorageAccKey
|
||||
$blobcopy = Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $StorageContainerName -DestContext $destContext -DestBlob $VHDFileName
|
||||
|
||||
while (($blobCopy | Get-AzStorageBlobCopyState).Status -eq "Pending") {
|
||||
Start-Sleep -s 30
|
||||
$blobCopy | Get-AzStorageBlobCopyState
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
} #EndFunction TK_CopyVHDToBlob
|
||||
|
||||
# Usage Example
|
||||
$HLSubscriptionID = "11111111-2222-3333-4444-555555555555"
|
||||
$HLResourceGroupName = "myresources"
|
||||
$HLManagedDiskName = "test01_OsDisk_1_xxxxxxxxxxxxxxxdb"
|
||||
$HLDestStorageAccName = "mystorage"
|
||||
$HLDestStorageAccKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=="
|
||||
$HLStorageContainerName = "myimages"
|
||||
$HLVHDFileName = "myimage.vhd"
|
||||
|
||||
# Function Call
|
||||
TK_CopyVHDToBlob -SubscriptionID $HLSubscriptionID -ResourceGroupName $HLResourceGroupName -ManagedDiskName $HLManagedDiskName -DestStorageAccName $HLDestStorageAccName -DestStorageAccKey $HLDestStorageAccKey -StorageContainerName $HLStorageContainerName -VHDFileName $HLVHDFileName
|
||||
56
Function_TK_CreateDirectory.ps1
Normal file
56
Function_TK_CreateDirectory.ps1
Normal file
@@ -0,0 +1,56 @@
|
||||
Function TK_CreateDirectory {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_CreateDirectory
|
||||
.DESCRIPTION
|
||||
Create a new directory
|
||||
.PARAMETER Directory
|
||||
This parameter contains the name of the new directory including the full path (for example C:\Temp\MyNewFolder).
|
||||
.EXAMPLE
|
||||
TK_CreateDirectory -Directory "C:\Temp\MyNewFolder"
|
||||
Creates the new directory "C:\Temp\MyNewFolder"
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 26.07.2018 | v0.1 | Initial script
|
||||
Last change : 26.07.2018 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position = 0)][String]$Directory
|
||||
)
|
||||
|
||||
begin {
|
||||
[string]$FunctionName = $PSCmdlet.MyInvocation.MyCommand.Name
|
||||
Write-Verbose "START FUNCTION - $FunctionName"
|
||||
}
|
||||
|
||||
process {
|
||||
Write-verbose "Create directory $Directory"
|
||||
if ( Test-Path $Directory ) {
|
||||
Write-Verbose "The directory $Directory already exists."
|
||||
} else {
|
||||
try {
|
||||
New-Item -ItemType Directory -Path $Directory -force | Out-Null
|
||||
Write-Verbose "Successfully created the directory $Directory."
|
||||
} catch {
|
||||
Write-Error "An error occurred trying to create the directory $Directory (exit code: $($Error[0]))!"
|
||||
Exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Verbose "END FUNCTION - $FunctionName"
|
||||
}
|
||||
} #EndFunction TK_CreateDirectory
|
||||
64
Function_TK_CreateFolderFromCSV.ps1
Normal file
64
Function_TK_CreateFolderFromCSV.ps1
Normal file
@@ -0,0 +1,64 @@
|
||||
Function TK_CreateFolderFromCSV {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_CreateFolderFromCSV
|
||||
.DESCRIPTION
|
||||
Create user folders from CSV file
|
||||
|
||||
Example CSV
|
||||
user,password,realname
|
||||
homer,Password!,Homer Simpson
|
||||
bart,Password!,Bart Simpson
|
||||
.PARAMETER CSVFile
|
||||
Full path to the CSV file eg. C:\Temp\userlist.csv
|
||||
.PARAMETER TargetPath
|
||||
Root path for folder creation eg. C:\Users
|
||||
.EXAMPLE
|
||||
TK_CreateFolderFromCSV -CSVFile "C:\Temp\userlist.csv" - TargetPath "C:\Users"
|
||||
.LINK
|
||||
https://github.com/thomaskrampe/PowerShell/blob/master/User%20Profiles/TK_CreateUserFolderFromCSV.ps1
|
||||
.NOTES
|
||||
Author : Thomas Krampe | thomas.krampe@myctx.net
|
||||
Version : 1.0
|
||||
Creation date : 21.02.2019 | v0.1 | Initial script
|
||||
Last change : 21.02.2019 | v1.0 | Add script documentation
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
THOMAS KRAMPE, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTIAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF THOMAS KRAMPE HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)][String]$CSVFile,
|
||||
[Parameter(Mandatory=$true)][String]$TargetPath
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
$CSVSource = Import-CSV -Path $CSVFile -Delimiter ","
|
||||
|
||||
foreach ($CSVObject in $CSVSource) {
|
||||
$CreateFolder = $TargetPath + "\" + $($CSVObject.User)
|
||||
Write-Verbose "Creating folder $CreateFolder."
|
||||
New-Item -ItemType directory -Path $CreateFolder | Out-Null
|
||||
if ( $(Try { Test-Path $CreateFolder.trim() } Catch { $false }) ) {
|
||||
Write-Verbose "Folder $CreateFolder created successful."
|
||||
}
|
||||
Else {
|
||||
Write-Error "Creating folder $CreateFolder failed." -targetobject $_ -Category WriteError -RecommendedAction "Maybe missing permissions."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
}
|
||||
} #EndFunction TK_CreateFolderFromCSV
|
||||
56
Function_TK_DeleteDirectory.ps1
Normal file
56
Function_TK_DeleteDirectory.ps1
Normal file
@@ -0,0 +1,56 @@
|
||||
Function TK_DeleteDirectory {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_DeleteDirectory
|
||||
.DESCRIPTION
|
||||
Delete a directory
|
||||
.PARAMETER Directory
|
||||
This parameter contains the full path to the directory which needs to be deleted (for example C:\Temp\MyFolder).
|
||||
.EXAMPLE
|
||||
TK_DeleteDirectory -Directory "C:\Temp\MyFolder"
|
||||
Deletes the directory "C:\Temp\MyFolder"
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 26.07.2018 | v0.1 | Initial script
|
||||
Last change : 26.07.2018 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position = 0)][String]$Directory
|
||||
)
|
||||
|
||||
begin {
|
||||
[string]$FunctionName = $PSCmdlet.MyInvocation.MyCommand.Name
|
||||
Write-Verbose "START FUNCTION - $FunctionName"
|
||||
}
|
||||
|
||||
process {
|
||||
Write-Verbose "Delete directory $Directory"
|
||||
if ( Test-Path $Directory ) {
|
||||
try {
|
||||
Remove-Item $Directory -force -recurse | Out-Null
|
||||
Write-Verbose "Successfully deleted the directory $Directory"
|
||||
} catch {
|
||||
Write-Error "An error occurred trying to delete the directory $Directory (exit code: $($Error[0]))!"
|
||||
Exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Verbose "The directory $Directory does not exist. Nothing to do"
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Verbose "END FUNCTION - $FunctionName"
|
||||
}
|
||||
} #EndFunction TK_DeleteDirectory
|
||||
56
Function_TK_DeleteFile.ps1
Normal file
56
Function_TK_DeleteFile.ps1
Normal file
@@ -0,0 +1,56 @@
|
||||
Function TK_DeleteFile {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_DeleteFile
|
||||
.DESCRIPTION
|
||||
Delete files
|
||||
.PARAMETER File
|
||||
This parameter contains the full path to the file that needs to be deleted (for example C:\Temp\MyFile.txt).
|
||||
.EXAMPLE
|
||||
TK_DeleteFile -File "C:\Temp\*.txt"
|
||||
Deletes all files in the directory "C:\Temp" that have the file extension *.txt. *.txt. Files stored within subfolders of 'C:\Temp' are NOT deleted
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 26.07.2018 | v0.1 | Initial script
|
||||
Last change : 26.07.2018 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position = 0)][String]$File
|
||||
)
|
||||
|
||||
begin {
|
||||
[string]$FunctionName = $PSCmdlet.MyInvocation.MyCommand.Name
|
||||
Write-Verbose "START FUNCTION - $FunctionName"
|
||||
}
|
||||
|
||||
process {
|
||||
Write-Verbose "Delete the file '$File'"
|
||||
if ( Test-Path $File ) {
|
||||
try {
|
||||
Remove-Item "$File" | Out-Null
|
||||
Write-Verbose "Successfully deleted the file '$File'"
|
||||
} catch {
|
||||
Write-Error "An error occurred trying to delete the file '$File' (exit code: $($Error[0]))!"
|
||||
Exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Verbose "The file '$File' does not exist. Nothing to do"
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Verbose "END FUNCTION - $FunctionName"
|
||||
}
|
||||
} #EndFunction TK_DeleteFile
|
||||
35
Function_TK_Get-CurrentWeek.ps1
Normal file
35
Function_TK_Get-CurrentWeek.ps1
Normal file
@@ -0,0 +1,35 @@
|
||||
function TK_Get-CurrentWeek {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Get current calendar week
|
||||
|
||||
.DESCRIPTION
|
||||
Get current calendar week
|
||||
|
||||
.EXAMPLE
|
||||
$CurrentWeek = TK_Get-CurrentWeek
|
||||
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 26.07.2018 | v0.1 | Initial script
|
||||
Last change : 07.09.2018 | v1.0 | Create the script header
|
||||
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
|
||||
.RETURN
|
||||
Current week number
|
||||
#>
|
||||
|
||||
$CurrentWeek = [System.Globalization.DateTimeFormatInfo]::CurrentInfo.Calendar.GetWeekOfYear([datetime]::Now,0,0)
|
||||
|
||||
Return $CurrentWeek
|
||||
} #Endfunction TK_Get-CurrentWeek
|
||||
37
Function_TK_IsAdmin.ps1
Normal file
37
Function_TK_IsAdmin.ps1
Normal file
@@ -0,0 +1,37 @@
|
||||
function TK_IsAdmin {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_IsAdmin
|
||||
.DESCRIPTION
|
||||
Check if the user running this script has admin permissions
|
||||
.EXAMPLE
|
||||
TK_IsAdmin
|
||||
.RETURN
|
||||
$True or $False
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.1
|
||||
Creation date : 26.07.2018 | v0.1 | Initial script
|
||||
Last change : 26.07.2018 | v1.1 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
|
||||
}
|
||||
|
||||
end {
|
||||
}
|
||||
|
||||
} #Endfunction TK_IsAdmin
|
||||
70
Function_TK_LoadModule.ps1
Normal file
70
Function_TK_LoadModule.ps1
Normal file
@@ -0,0 +1,70 @@
|
||||
Function TK_LoadModule {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_LoadModule
|
||||
.DESCRIPTION
|
||||
Import a Powershell module from disk, if not present install from powershell gallery.
|
||||
.PARAMETER ModuleName
|
||||
The name of the PowerShell module
|
||||
.EXAMPLE
|
||||
TK_LoadModule -ModuleName AzureAD
|
||||
Import module if possible. Otherwise try to install from local or, if not available local, from PowerShell Gallery
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 05.08.2019 | v0.1 | Initial script
|
||||
Last change : 06.08.2019 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
|
||||
Param(
|
||||
[Parameter(Mandatory = $true, Position = 0)][String]$ModuleName
|
||||
)
|
||||
|
||||
begin {
|
||||
[string]$FunctionName = $PSCmdlet.MyInvocation.MyCommand.Name
|
||||
Write-Verbose "START FUNCTION - $FunctionName"
|
||||
}
|
||||
|
||||
process {
|
||||
# If module is already imported there is nothing to do.
|
||||
if (Get-Module | Where-Object { $_.Name -eq $ModuleName }) {
|
||||
Write-Verbose "Module $ModuleName is already imported."
|
||||
}
|
||||
else {
|
||||
|
||||
# If module is not imported, but available on disk then import
|
||||
if (Get-Module -ListAvailable | Where-Object { $_.Name -eq $ModuleName }) {
|
||||
Import-Module $ModuleName -Verbose
|
||||
}
|
||||
else {
|
||||
|
||||
# If module is not imported, not available on disk, but is in online gallery then install and import
|
||||
if (Find-Module -Name $ModuleName | Where-Object { $_.Name -eq $ModuleName }) {
|
||||
Install-Module -Name $ModuleName -Force -Verbose -Scope CurrentUser
|
||||
Import-Module $ModuleName -Verbose
|
||||
}
|
||||
else {
|
||||
|
||||
# If module is still not available then abort with exit code 1
|
||||
Write-Warning "Module $ModuleName not imported, not local available and not in online gallery, exiting."
|
||||
EXIT 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Verbose "END FUNCTION - $FunctionName"
|
||||
}
|
||||
} #EndFunction TK_LoadModule
|
||||
96
Function_TK_ReadFromINI.ps1
Normal file
96
Function_TK_ReadFromINI.ps1
Normal file
@@ -0,0 +1,96 @@
|
||||
Function TK_ReadFromINI {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_ReadFromINI
|
||||
.DESCRIPTION
|
||||
Get values from INI file
|
||||
|
||||
Example INI
|
||||
-----------
|
||||
[owner]
|
||||
name=Thomas Krampe
|
||||
organization=MyCTX
|
||||
|
||||
[informations]
|
||||
hostname=sqlserver
|
||||
ipaddress=192.168.1.2
|
||||
|
||||
.PARAMETER filePath
|
||||
Full path to the INI file eg. C:\Temp\server.ini
|
||||
.EXAMPLE
|
||||
$INIValues = TK_ReadFromINI -filePath "C:\Temp\server.ini"
|
||||
|
||||
You can then access values like this:
|
||||
$Server = $INIValues.informations.server
|
||||
$Organization = $INIValues.owner.organization
|
||||
|
||||
.LINK
|
||||
https://github.com/thomaskrampe/PowerShell/blob/master/User%20Profiles/TK_ReadFromINI.ps1
|
||||
.NOTES
|
||||
Author : Thomas Krampe | thomas.krampe@myctx.net
|
||||
Version : 1.0
|
||||
Creation date : 21.02.2019 | v0.1 | Initial script
|
||||
Last change : 21.02.2019 | v1.0 | Add script documentation
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
THOMAS KRAMPE, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTIAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF THOMAS KRAMPE HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)][String]$filePath
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
|
||||
$anonymous = "NoSection"
|
||||
$ini = @{}
|
||||
switch -regex -file $filePath
|
||||
{
|
||||
"^\[(.+)\]$" # Section
|
||||
{
|
||||
$section = $matches[1]
|
||||
$ini[$section] = @{}
|
||||
$CommentCount = 0
|
||||
}
|
||||
|
||||
"^(;.*)$" # Comment
|
||||
{
|
||||
if (!($section)) {
|
||||
$section = $anonymous
|
||||
$ini[$section] = @{}
|
||||
}
|
||||
$value = $matches[1]
|
||||
$CommentCount = $CommentCount + 1
|
||||
$name = "Comment" + $CommentCount
|
||||
$ini[$section][$name] = $value
|
||||
}
|
||||
|
||||
"(.+?)\s*=\s*(.*)" # Key
|
||||
{
|
||||
if (!($section)) {
|
||||
$section = $anonymous
|
||||
$ini[$section] = @{}
|
||||
}
|
||||
$name,$value = $matches[1..2]
|
||||
$ini[$section][$name] = $value
|
||||
}
|
||||
}
|
||||
return $ini
|
||||
|
||||
}
|
||||
|
||||
end {
|
||||
}
|
||||
} #EndFunction TK_ReadFromINI
|
||||
101
Function_TK_RemoveWVDHostPool.ps1
Normal file
101
Function_TK_RemoveWVDHostPool.ps1
Normal file
@@ -0,0 +1,101 @@
|
||||
Function TK_RemoveWVDHostPool {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_RemoveWVDHostPool
|
||||
.DESCRIPTION
|
||||
Delete a Windows Virtual Desktop RDS Host Pool in Azure
|
||||
.PARAMETER TenantName
|
||||
The Name of the WVD Tenant (you can get this with the Get-RdsTenant cmdlet)
|
||||
.PARAMETER HostPoolName
|
||||
The Name of the host pool (you can get this with the Get-RdsHostPool -TenantName xxx cmdlet)
|
||||
.EXAMPLE
|
||||
TK_RemoveWVDHostPool -TenantName MyTenant -HostPoolName MyHostPool
|
||||
This call remove the Application Group as well as the session host server associated to the Host Pool and finally the hpst pool itself.
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 15.08.2019 | v0.1 | Initial script
|
||||
Last change : 15.08.2019 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory = $true, Position = 0)][String]$TenantName,
|
||||
[Parameter(Mandatory = $true, Position = 1)][String]$HostPoolName
|
||||
)
|
||||
|
||||
begin {
|
||||
[string]$FunctionName = $PSCmdlet.MyInvocation.MyCommand.Name
|
||||
Write-Verbose "START FUNCTION - $FunctionName"
|
||||
|
||||
[string]$ModuleName = "Microsoft.RDInfra.RDPowerShell"
|
||||
|
||||
# If module is already imported there is nothing to do.
|
||||
if (Get-Module | Where-Object { $_.Name -eq $ModuleName }) {
|
||||
Write-Verbose "Module $ModuleName is already imported."
|
||||
}
|
||||
else {
|
||||
|
||||
# If module is not imported, but available on disk then import
|
||||
if (Get-Module -ListAvailable | Where-Object { $_.Name -eq $ModuleName }) {
|
||||
Import-Module $ModuleName -Verbose
|
||||
}
|
||||
else {
|
||||
|
||||
# If module is not imported, not available on disk, but is in online gallery then install and import
|
||||
if (Find-Module -Name $ModuleName | Where-Object { $_.Name -eq $ModuleName }) {
|
||||
Install-Module -Name $ModuleName -Verbose
|
||||
Import-Module $ModuleName -Verbose
|
||||
}
|
||||
else {
|
||||
|
||||
# If module is still not available then abort with exit code 1
|
||||
Write-Warning "Module $ModuleName not imported, not local available and not in online gallery, exiting."
|
||||
EXIT 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Login to the Windows Virtual Desktop Tenant
|
||||
Add-RdsAccount -DeploymentUrl "https://rdbroker.wvd.microsoft.com"
|
||||
}
|
||||
|
||||
process {
|
||||
# Do some pre-checks
|
||||
[string]$TenantCheck = (Get-RdsTenant).TenantName
|
||||
|
||||
If ($TenantName -ne $TenantCheck) {
|
||||
Write-Error "Tenant name mismatch. Please verify the tenant name and try again."
|
||||
Exit 1
|
||||
}
|
||||
|
||||
[string]$HostPoolCheck = (Get-RdsHostPool -TenantName $TenantName).HostPoolName
|
||||
|
||||
If ($HostPoolName -ne $HostPoolCheck) {
|
||||
Write-Error "Host pool name mismatch. Please verify the host pool name and try again."
|
||||
Exit 1
|
||||
}
|
||||
|
||||
# Remove Application Group associated to the Host Pool
|
||||
Get-RdsAppGroup -TenantName $TenantName -HostPoolName $HostPoolName | Remove-RdsAppGroup
|
||||
# Remove Session Host servers associated to the Host Pool
|
||||
Get-RdsSessionHost -TenantName $TenantName -HostPoolName $HostPoolName | Remove-RdsSessionHost
|
||||
# Remove the Host Pool
|
||||
Get-RdsHostPool -TenantName $TenantName -HostPoolName $HostPoolName | Remove-RdsHostPool
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
} #EndFunction TK_RemoveWVDHostPool
|
||||
|
||||
|
||||
67
Function_TK_SendMail.ps1
Normal file
67
Function_TK_SendMail.ps1
Normal file
@@ -0,0 +1,67 @@
|
||||
Function TK_SendMail {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_SendMail
|
||||
.DESCRIPTION
|
||||
Send an e-mail to one or more recipients.
|
||||
.PARAMETER Sender
|
||||
This parameter contains the e-mail address of the sender (e.g. mymail@mydomain.com).
|
||||
.PARAMETER Recipients
|
||||
This parameter contains the e-mail address or addresses of the recipients (e.g. "<name>@mycompany.com" or "<name>@mycompany.com", "<name>@mycompany.com")
|
||||
.PARAMETER Subject
|
||||
This parameter contains the subject of the e-mail
|
||||
.PARAMETER Text
|
||||
This parameter contains the body of the e-mail
|
||||
.PARAMETER SMTPServer
|
||||
This parameter contains the name or the IP-address of the SMTP server (e.g. 'smtp.mycompany.com')
|
||||
.EXAMPLE
|
||||
TK_SendMail -Sender "me@mycompany.com" -Recipients "someone@mycompany.com" -Subject "Something important" -Text "This is the text for the e-mail" -SMTPServer "smtp.mycompany.com"
|
||||
Sends an e-mail to one recipient
|
||||
.EXAMPLE
|
||||
TK_SendMail -Sender "me@mycompany.com" -Recipients "someone@mycompany.com","someoneelse@mycompany.com" -Subject "Something important" -Text "This is the text for the e-mail" -SMTPServer "smtp.mycompany.com"
|
||||
Sends an e-mail to two recipients
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 26.07.2018 | v0.1 | Initial script
|
||||
Last change : 26.07.2018 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position = 0)][String]$Sender,
|
||||
[Parameter(Mandatory=$true, Position = 1)][String[]]$Recipients,
|
||||
[Parameter(Mandatory=$true, Position = 2)][String]$Subject,
|
||||
[Parameter(Mandatory=$true, Position = 3)][String]$Text,
|
||||
[Parameter(Mandatory=$true, Position = 4)][String]$SMTPServer
|
||||
)
|
||||
|
||||
begin {
|
||||
[string]$FunctionName = $PSCmdlet.MyInvocation.MyCommand.Name
|
||||
Write-Verbose "START FUNCTION - $FunctionName"
|
||||
}
|
||||
|
||||
process {
|
||||
try {
|
||||
Send-MailMessage -From $Sender -to $Recipients -subject $Subject -body $Text -smtpServer $SMTPServer -BodyAsHtml
|
||||
Write-Verbose "E-mail successfully sent."
|
||||
Exit 0
|
||||
} catch {
|
||||
Write-Error "An error occurred trying to send the e-mail (exit code: $($Error[0]))!"
|
||||
Exit 1
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Verbose "END FUNCTION - $FunctionName"
|
||||
}
|
||||
} #EndFunction TK_SendMail
|
||||
86
Function_TK_WriteLog.ps1
Normal file
86
Function_TK_WriteLog.ps1
Normal file
@@ -0,0 +1,86 @@
|
||||
function TK_WriteLog {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Write text to log file
|
||||
.DESCRIPTION
|
||||
Write text to this script's log file
|
||||
.PARAMETER InformationType
|
||||
This parameter contains the information type prefix. Possible prefixes and information types are:
|
||||
I = Information
|
||||
S = Success
|
||||
W = Warning
|
||||
E = Error
|
||||
- = No status
|
||||
.PARAMETER Text
|
||||
This parameter contains the text (the line) you want to write to the log file. If text in the parameter is omitted, an empty line is written.
|
||||
.PARAMETER LogFile
|
||||
This parameter contains the full path, the file name and file extension to the log file (e.g. C:\Logs\MyApps\MylogFile.log)
|
||||
.EXAMPLE
|
||||
TK_WriteLog -$InformationType "I" -Text "Copy files to C:\Temp" -LogFile "C:\Logs\MylogFile.log"
|
||||
Writes a line containing information to the log file
|
||||
.EXAMPLE
|
||||
TK_WriteLog -$InformationType "E" -Text "An error occurred trying to copy files to C:\Temp (error: $($Error[0]))" -LogFile "C:\Logs\MylogFile.log"
|
||||
Writes a line containing error information to the log file
|
||||
.EXAMPLE
|
||||
TK_WriteLog -$InformationType "-" -Text "" -LogFile "C:\Logs\MylogFile.log"
|
||||
Writes an empty line to the log file
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 26.07.2018 | v0.1 | Initial script
|
||||
Last change : 07.09.2018 | v1.0 | Fix some minor typos
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position = 0)][ValidateSet("I","S","W","E","-",IgnoreCase = $True)][String]$InformationType,
|
||||
[Parameter(Mandatory=$true, Position = 1)][AllowEmptyString()][String]$Text,
|
||||
[Parameter(Mandatory=$true, Position = 2)][AllowEmptyString()][String]$LogFile
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
$DateTime = (Get-Date -format dd-MM-yyyy) + " " + (Get-Date -format HH:mm:ss)
|
||||
|
||||
if ( $Text -eq "" ) {
|
||||
Add-Content $LogFile -value ("")
|
||||
} Else {
|
||||
Add-Content $LogFile -value ($DateTime + " " + $InformationType.ToUpper() + " - " + $Text)
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
}
|
||||
|
||||
|
||||
} #EndFunction TK_WriteLog
|
||||
|
||||
#region Log handling
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
# Log handling
|
||||
# To use the function above in your own script, make sure that you prepare your log file directory.
|
||||
# -------------------------------------------------------------------------------------------------
|
||||
$LogDir = "C:\_Logs"
|
||||
$ScriptName = "CitrixCloudAutomation"
|
||||
$DateTime = Get-Date -uformat "%Y-%m-%d_%H-%M"
|
||||
$LogFileName = "$ScriptName"+"$DateTime.log"
|
||||
$LogFile = Join-path $LogDir $LogFileName
|
||||
|
||||
# Create the log directory if it does not exist
|
||||
if (!(Test-Path $LogDir)) { New-Item -Path $LogDir -ItemType directory | Out-Null }
|
||||
|
||||
# Create new log file (overwrite existing one)
|
||||
New-Item $LogFile -ItemType "file" -force | Out-Null
|
||||
#endregion
|
||||
|
||||
108
Function_TK_WriteToEventLog.ps1
Normal file
108
Function_TK_WriteToEventLog.ps1
Normal file
@@ -0,0 +1,108 @@
|
||||
Function TK_WriteToEventLog {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
TK_WriteToEventLog
|
||||
.DESCRIPTION
|
||||
Write an entry into the Windows event log. New event logs as well as new event sources are automatically created.
|
||||
.PARAMETER EventLog
|
||||
This parameter contains the name of the event log the entry should be written to (e.g. Application, Security, System or a custom one)
|
||||
.PARAMETER Source
|
||||
This parameter contains the source (e.g. 'MyScript')
|
||||
.PARAMETER EventID
|
||||
This parameter contains the event ID number (e.g. 3000)
|
||||
.PARAMETER Type
|
||||
This parameter contains the type of message. Possible values are: Information | Warning | Error
|
||||
.PARAMETER Message
|
||||
This parameter contains the event log description explaining the issue
|
||||
.EXAMPLE
|
||||
TK_WriteToEventLog -EventLog "System" -Source "MyScript" -EventID "3000" -Type "Error" -Message "An error occurred"
|
||||
Write an error message to the System event log with the source 'MyScript' and event ID 3000. The unknown source 'MyScript' is automatically created
|
||||
.EXAMPLE
|
||||
TK_WriteToEventLog -EventLog "Application" -Source "Something" -EventID "250" -Type "Information" -Message "Information: action completed successfully"
|
||||
Write an information message to the Application event log with the source 'Something' and event ID 250. The unknown source 'Something' is automatically created
|
||||
.EXAMPLE
|
||||
TK_WriteToEventLog -EventLog "MyNewEventLog" -Source "MyScript" -EventID "1000" -Type "Warning" -Message "Warning. There seems to be an issue"
|
||||
Write an warning message to the event log called 'MyNewEventLog' with the source 'MyScript' and event ID 1000. The unknown event log 'MyNewEventLog' and source 'MyScript' are automatically created
|
||||
.NOTES
|
||||
Author : Thomas Krampe | t.krampe@loginconsultants.de
|
||||
Version : 1.0
|
||||
Creation date : 26.07.2018 | v0.1 | Initial script
|
||||
Last change : 26.07.2018 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[parameter(mandatory=$True)]
|
||||
[ValidateNotNullorEmpty()]
|
||||
[String]$EventLog,
|
||||
[parameter(mandatory=$True)]
|
||||
[ValidateNotNullorEmpty()]
|
||||
[String]$Source,
|
||||
[parameter(mandatory=$True)]
|
||||
[Int]$EventID,
|
||||
[parameter(mandatory=$True)]
|
||||
[ValidateNotNullorEmpty()]
|
||||
[String]$Type,
|
||||
[parameter(mandatory=$True)]
|
||||
[ValidateNotNullorEmpty()]
|
||||
[String]$Message
|
||||
)
|
||||
|
||||
begin {
|
||||
[string]$FunctionName = $PSCmdlet.MyInvocation.MyCommand.Name
|
||||
Write-Verbose "START FUNCTION - $FunctionName"
|
||||
}
|
||||
|
||||
process {
|
||||
# Check if the event log exist. If not, create it.
|
||||
Write-Verbose "Check if the event log $EventLog exists. If not, create it"
|
||||
if ( !( [System.Diagnostics.EventLog]::Exists( $EventLog ) ) ) {
|
||||
Write-Verbose "The event log '$EventLog' does not exist."
|
||||
try {
|
||||
New-EventLog -LogName $EventLog -Source $EventLog
|
||||
Write-Verbose "The event log '$EventLog' was created successfully"
|
||||
} catch {
|
||||
Write-Verbose "An error occurred trying to create the event log '$EventLog' (error: $($Error[0]))!"
|
||||
|
||||
}
|
||||
} else {
|
||||
Write-Verbose "The event log '$EventLog' already exists."
|
||||
}
|
||||
|
||||
# Check if the event source exist. If not, create it.
|
||||
Write-Verbose "Check if the event source '$Source' exists. If not, create it."
|
||||
if ( !( [System.Diagnostics.EventLog]::SourceExists( $Source ) ) ) {
|
||||
Write-Verbose "The event source '$Source' does not exist."
|
||||
try {
|
||||
[System.Diagnostics.EventLog]::CreateEventSource( $Source, $EventLog )
|
||||
Write-Verbose "The event source '$Source' was created successfully."
|
||||
} catch {
|
||||
Write-Verbose "An error occurred trying to create the event source '$Source' (error: $($Error[0]))!"
|
||||
}
|
||||
} else {
|
||||
Write-verbose "The event source '$Source' already exists."
|
||||
}
|
||||
|
||||
# Write the event log entry
|
||||
Write-Verbose "Write the event log entry."
|
||||
try {
|
||||
Write-EventLog -LogName $EventLog -Source $Source -eventID $EventID -EntryType $Type -message $Message
|
||||
Write-Verbose "The event log entry was written successfully."
|
||||
} catch {
|
||||
Write-Verbose "An error occurred trying to write the event log entry (error: $($Error[0]))!"
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Verbose "END FUNCTION - $FunctionName"
|
||||
}
|
||||
} #EndFunction TK_WriteToEventLog
|
||||
22
Function_TK_check-even-odd.ps1
Normal file
22
Function_TK_check-even-odd.ps1
Normal file
@@ -0,0 +1,22 @@
|
||||
Function TK_check-even-odd ($num) {[bool]!($num%2)}
|
||||
|
||||
# Example script using the function above
|
||||
$Computers = "LAB5003XA01", "LAB5003XA02", "LAB5003XA03", "LAB5003XA04", "LAB5003XA05"
|
||||
|
||||
foreach ($computer in $computers) {
|
||||
if ($computer -like "LAB5003XA*") {
|
||||
[int]$ComputerNum = $computer.Substring($computer.Length - 2)
|
||||
|
||||
if((TK_check-even-odd $computerNum) -eq $true) {
|
||||
#even hostname ending
|
||||
"Do something for even computer: {0}" -f $computer
|
||||
}
|
||||
else {
|
||||
#odd hostname ending
|
||||
"Do something for odd computer: {0}" -f $computer
|
||||
}
|
||||
}
|
||||
else {
|
||||
"Computer does not meet naming standards: {0}" -f $computer
|
||||
}
|
||||
}
|
||||
66
ModifyProxySettings.ps1
Normal file
66
ModifyProxySettings.ps1
Normal file
@@ -0,0 +1,66 @@
|
||||
#requires -runasadministrator
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
Modify proxy settings for the current user.
|
||||
|
||||
.DESCRIPTION
|
||||
Modify proxy settings for the current user modifying the windows registry.
|
||||
|
||||
.EXAMPLE
|
||||
Get the proxy settings for the current user
|
||||
|
||||
PS D:\> get-proxy
|
||||
ProxyServer ProxyEnable
|
||||
----------- -----------
|
||||
0
|
||||
|
||||
.EXAMPLE
|
||||
Set the proxy server for the current user. Test the address and if the TCP Port is open before applying the settings.
|
||||
proxy squid.server.com 3128
|
||||
set-proxy -server "yourproxy.server.com" -port 3128
|
||||
|
||||
.EXAMPLE
|
||||
Remove the current proxy settings for the user.
|
||||
|
||||
.NOTES
|
||||
Author Paolo Frigo, https://www.scriptinglibrary.com
|
||||
#>
|
||||
|
||||
function Get-Proxy (){
|
||||
Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' | Select-Object ProxyServer, ProxyEnable
|
||||
}
|
||||
|
||||
function Set-Proxy {
|
||||
[CmdletBinding()]
|
||||
[Alias('proxy')]
|
||||
[OutputType([string])]
|
||||
Param
|
||||
(
|
||||
# server address
|
||||
[Parameter(Mandatory = $true,
|
||||
ValueFromPipelineByPropertyName = $true,
|
||||
Position = 0)]
|
||||
$server,
|
||||
# port number
|
||||
[Parameter(Mandatory = $true,
|
||||
ValueFromPipelineByPropertyName = $true,
|
||||
Position = 1)]
|
||||
$port
|
||||
)
|
||||
#Test if the TCP Port on the server is open before applying the settings
|
||||
If ((Test-NetConnection -ComputerName $server -Port $port).TcpTestSucceeded) {
|
||||
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyServer -Value "$($server):$($port)"
|
||||
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -Value 1
|
||||
Get-Proxy #Show the configuration
|
||||
}
|
||||
Else {
|
||||
Write-Error -Message "The proxy address is not valid: $($server):$($port)"
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-Proxy (){
|
||||
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyServer -Value ""
|
||||
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -Value 0
|
||||
}
|
||||
|
||||
50
_TemplateForYourOwnFunctions.ps1
Normal file
50
_TemplateForYourOwnFunctions.ps1
Normal file
@@ -0,0 +1,50 @@
|
||||
Function ShortURL {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Name of the Function
|
||||
.DESCRIPTION
|
||||
Short Function description
|
||||
.PARAMETER Param1
|
||||
Parameter description
|
||||
.PARAMETER Param2
|
||||
Parameter ... description
|
||||
.EXAMPLE
|
||||
Usage example
|
||||
.NOTES
|
||||
Author : Name | E-Mail
|
||||
Version : 1.0
|
||||
Creation date : 31.12.2018 | v0.1 | Initial script
|
||||
Last change : 31.12.2018 | v1.0 | Release
|
||||
|
||||
IMPORTANT NOTICE
|
||||
----------------
|
||||
THIS SCRIPT IS PROVIDED "AS IS" WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.
|
||||
LOGIN CONSULTANTS, SHALL NOT BE LIABLE FOR TECHNICAL OR EDITORIAL ERRORS OR OMISSIONS CONTAINED
|
||||
HEREIN, NOT FOR DIRECT, INCIDENTAL, CONSEQUENTIAL OR ANY OTHER DAMAGES RESULTING FROM FURNISHING,
|
||||
PERFORMANCE, OR USE OF THIS SCRIPT, EVEN IF LOGIN CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY
|
||||
OF SUCH DAMAGES IN ADVANCE.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position = 0)][String]$longurl
|
||||
)
|
||||
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
|
||||
$url ="http://t13k.de/yourls-api.php?signature=9695dd257c&action=shorturl&format=simple&url=$longurl"
|
||||
$request = Invoke-WebRequest $url
|
||||
$request.Content
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
} #EndFunction ShortURL
|
||||
|
||||
ShortURL "https://www.example.com"
|
||||
Reference in New Issue
Block a user