Anlage des Repos
This commit is contained in:
11
examples/PowerShell/AccessTests/AccessRights-test.ps1
Normal file
11
examples/PowerShell/AccessTests/AccessRights-test.ps1
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
$file = [System.io.File]::Open("E:\test.txt", 'Open', 'Read', 'ReadWrite')
|
||||
#$reader = New-Object System.IO.StreamReader($file)
|
||||
#$text = $reader.ReadToEnd()
|
||||
#$reader.Close()
|
||||
$file.Close()
|
||||
|
||||
Write-Host $file.CanRead
|
||||
Write-Host $file.CanWrite
|
||||
Write-Host $file.CanSeek
|
||||
Write-Host $file.CanTimeout
|
||||
61
examples/PowerShell/AccessTests/AccessRights.ps1
Normal file
61
examples/PowerShell/AccessTests/AccessRights.ps1
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
Set-Variable -name file -Value E:\test.pdf
|
||||
|
||||
function checkFileStatus1($filePath)
|
||||
{
|
||||
write-host (get-Date) "[ACTION][FILECHECK] Checking if" $filePath "is locked"
|
||||
$fileInfo = New-Object System.IO.FileInfo $filePath
|
||||
|
||||
try
|
||||
{
|
||||
$fileStream = $fileInfo.Open( [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read )
|
||||
write-host (get-Date) "[ACTION][FILEAVAILABLE]" $filePath
|
||||
#$fileInfo.close()
|
||||
#$fileInfo.dispose()
|
||||
|
||||
|
||||
|
||||
return $true
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
write-host (get-Date) "[ACTION][FILELOCKED] $filePath is locked"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
function checkFileStatus2($filePath)
|
||||
{
|
||||
write-host (get-Date) "[ACTION][FILECHECK] Checking if" $filePath "is locked"
|
||||
$fileInfo = New-Object System.IO.FileInfo $filePath
|
||||
|
||||
try
|
||||
{
|
||||
$fileStream = $fileInfo.Open( [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read )
|
||||
#$fileStream = $fileInfo.Open()
|
||||
write-host (get-Date) "[ACTION][FILEAVAILABLE]" $filePath
|
||||
$fileInfo.close()
|
||||
$fileInfo.dispose()
|
||||
#$fileStream = $fileInfo.Open( [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read )
|
||||
|
||||
|
||||
return $true
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
write-host (get-Date) "[ACTION][FILELOCKED] $filePath is locked"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
checkFileStatus2 -filePath $file
|
||||
# checkFileStatus1 -filePath $file
|
||||
@@ -0,0 +1,5 @@
|
||||
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”) -or -NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”) -or -not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Domain Admins"))
|
||||
{
|
||||
Write-Warning “You do not have sufficient permissions to run this script!`nPlease re-run this script as an Administrator!”
|
||||
Break
|
||||
}
|
||||
1447
examples/PowerShell/CsvSqlimport.ps1
Normal file
1447
examples/PowerShell/CsvSqlimport.ps1
Normal file
File diff suppressed because it is too large
Load Diff
BIN
examples/PowerShell/ImportCsvSqlAll.zip
Normal file
BIN
examples/PowerShell/ImportCsvSqlAll.zip
Normal file
Binary file not shown.
Binary file not shown.
BIN
examples/PowerShell/New-Subfolder-inExchangeMailbox/Webhilfe.zip
Normal file
BIN
examples/PowerShell/New-Subfolder-inExchangeMailbox/Webhilfe.zip
Normal file
Binary file not shown.
4
examples/PowerShell/Repair-Windows.ps1
Normal file
4
examples/PowerShell/Repair-Windows.ps1
Normal file
@@ -0,0 +1,4 @@
|
||||
Dism /Online /Cleanup-Image /ScanHealth
|
||||
Dism /Online /Cleanup-Image /CheckHealth
|
||||
Dism /Online /Cleanup-Image /RestoreHealth
|
||||
sfc /scannow
|
||||
10
examples/PowerShell/Restart-windreamClient.ps1
Normal file
10
examples/PowerShell/Restart-windreamClient.ps1
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
$IndexService = New-Object -ComObject "WMIndexServer.WMIdxSvControl"
|
||||
$IndexService.Shutdown
|
||||
$IndexService.Start
|
||||
$IndexService = $NULL
|
||||
|
||||
$ControlCenter = New-Object -ComObject "Wmcc.ControlCenter"
|
||||
$ControlCenter.StartVFSService(0)
|
||||
$ControlCenter.StartVFSService(1)
|
||||
$ControlCenter = $NULL
|
||||
30
examples/PowerShell/Select-FileDialog.ps1
Normal file
30
examples/PowerShell/Select-FileDialog.ps1
Normal file
@@ -0,0 +1,30 @@
|
||||
# Note: store in your profile for easy use
|
||||
# Example use:
|
||||
# $file = Select-FileDialog -Title "Select a file" -Directory "D:\scripts" -Filter "Powershell Scripts|(*.ps1)"
|
||||
|
||||
function Select-FileDialog
|
||||
{
|
||||
param([string]$Title,[string]$Directory,[string]$Filter="All Files (*.*)|*.*")
|
||||
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
|
||||
$objForm = New-Object System.Windows.Forms.OpenFileDialog
|
||||
$objForm.InitialDirectory = $Directory
|
||||
$objForm.Filter = $Filter
|
||||
$objForm.Title = $Title
|
||||
$Show = $objForm.ShowDialog()
|
||||
If ($Show -eq "OK")
|
||||
{
|
||||
Return $objForm.FileName
|
||||
}
|
||||
Else
|
||||
{
|
||||
Write-Error "Operation cancelled by user."
|
||||
}
|
||||
}
|
||||
|
||||
$file = Select-FileDialog -Title "Select a file" -Directory "D:\scripts" -Filter "Powershell Scripts (*.ps1)|*.ps1"
|
||||
|
||||
#multiple file category arguments should not include extra space:
|
||||
#-Filter “Text files (*.txt) | *.txt | All files (*.*) | *.*”
|
||||
#does not work — only show *.* filter.
|
||||
#-Filter “Text files (*.txt)|*.txt|All files (*.*)|*.*”
|
||||
#works.
|
||||
162
examples/PowerShell/SimpleForm.ps1
Normal file
162
examples/PowerShell/SimpleForm.ps1
Normal file
@@ -0,0 +1,162 @@
|
||||
#Generated Form Function
|
||||
function GenerateForm {
|
||||
########################################################################
|
||||
# Code Generated By: SAPIEN Technologies PrimalForms v1.0.1.0
|
||||
# Generated On: 25/01/2009 14:50
|
||||
# Generated By: administrator
|
||||
########################################################################
|
||||
|
||||
#region Import the Assembles
|
||||
[reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) | Out-Null
|
||||
[reflection.assembly]::loadwithpartialname(“System.Drawing”) | Out-Null
|
||||
#endregion
|
||||
|
||||
#region Generated Form Objects
|
||||
$form1 = New-Object System.Windows.Forms.Form
|
||||
$DisplayFile_Window = New-Object System.Windows.Forms.RichTextBox
|
||||
$SelectFile_Window = New-Object System.Windows.Forms.RichTextBox
|
||||
$SelectFile = New-Object System.Windows.Forms.Button
|
||||
$groupBox1 = New-Object System.Windows.Forms.GroupBox
|
||||
$Displayfile = New-Object System.Windows.Forms.Button
|
||||
$openFileDialog1 = New-Object System.Windows.Forms.OpenFileDialog
|
||||
#endregion Generated Form Objects
|
||||
|
||||
#———————————————-
|
||||
#Generated Event Script Blocks
|
||||
#———————————————-
|
||||
#Provide Custom Code for events specified in PrimalForms.
|
||||
$EnteredText=
|
||||
{
|
||||
$ifile = $SelectFile_Window.Text
|
||||
}
|
||||
|
||||
$Displayfile_OnClick=
|
||||
{
|
||||
If(!$ifile -eq $False)
|
||||
{
|
||||
$iFileGC = Get-content $ifile
|
||||
$iFileContents = [string]::join([environment]::NewLine,$iFileGC)
|
||||
$DisplayFile_Window.Text = $iFileContents
|
||||
}
|
||||
Else {$DisplayFile_Window.Text = “No file selected”}
|
||||
|
||||
}
|
||||
|
||||
$SelectFile_OnClick=
|
||||
{
|
||||
$openFileDialog1.ShowDialog()
|
||||
$ifile = $openFileDialog1.FileName
|
||||
$SelectFile_Window.Text = $ifile
|
||||
}
|
||||
|
||||
#———————————————-
|
||||
#region Generated Form Code
|
||||
$form1.Text = ‘My 1st Primal Form’
|
||||
$form1.Name = ‘form1’
|
||||
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
|
||||
$System_Drawing_Size = New-Object System.Drawing.Size
|
||||
$System_Drawing_Size.Height = 299
|
||||
$System_Drawing_Size.Width = 436
|
||||
$form1.ClientSize = $System_Drawing_Size
|
||||
|
||||
$DisplayFile_Window.WordWrap = $False
|
||||
$DisplayFile_Window.Name = ‘DisplayFile_Window’
|
||||
$DisplayFile_Window.Text = ”
|
||||
$DisplayFile_Window.DataBindings.DefaultDataSourceUpdateMode = 0
|
||||
$System_Drawing_Point = New-Object System.Drawing.Point
|
||||
$System_Drawing_Point.X = 10
|
||||
$System_Drawing_Point.Y = 64
|
||||
$DisplayFile_Window.Location = $System_Drawing_Point
|
||||
$DisplayFile_Window.ReadOnly = $True
|
||||
$System_Drawing_Size = New-Object System.Drawing.Size
|
||||
$System_Drawing_Size.Height = 223
|
||||
$System_Drawing_Size.Width = 409
|
||||
$DisplayFile_Window.Size = $System_Drawing_Size
|
||||
$DisplayFile_Window.TabIndex = 3
|
||||
|
||||
$form1.Controls.Add($DisplayFile_Window)
|
||||
|
||||
$SelectFile_Window.Multiline = $False
|
||||
$SelectFile_Window.WordWrap = $False
|
||||
$SelectFile_Window.Name = ‘SelectFile_Window’
|
||||
$SelectFile_Window.Text = ”
|
||||
$SelectFile_Window.DataBindings.DefaultDataSourceUpdateMode = 0
|
||||
$System_Drawing_Point = New-Object System.Drawing.Point
|
||||
$System_Drawing_Point.X = 12
|
||||
$System_Drawing_Point.Y = 35
|
||||
$SelectFile_Window.Location = $System_Drawing_Point
|
||||
$SelectFile_Window.EnableAutoDragDrop = $True
|
||||
$System_Drawing_Size = New-Object System.Drawing.Size
|
||||
$System_Drawing_Size.Height = 23
|
||||
$System_Drawing_Size.Width = 293
|
||||
$SelectFile_Window.Size = $System_Drawing_Size
|
||||
$SelectFile_Window.TabIndex = 1
|
||||
$SelectFile_Window.add_TextChanged($EnteredText)
|
||||
|
||||
$form1.Controls.Add($SelectFile_Window)
|
||||
|
||||
$SelectFile.TabIndex = 0
|
||||
$System_Drawing_Size = New-Object System.Drawing.Size
|
||||
$System_Drawing_Size.Height = 23
|
||||
$System_Drawing_Size.Width = 27
|
||||
$SelectFile.Size = $System_Drawing_Size
|
||||
$SelectFile.Name = ‘SelectFile’
|
||||
$SelectFile.UseVisualStyleBackColor = $True
|
||||
|
||||
$SelectFile.Text = ‘…’
|
||||
$System_Drawing_Point = New-Object System.Drawing.Point
|
||||
$System_Drawing_Point.X = 311
|
||||
$System_Drawing_Point.Y = 34
|
||||
$SelectFile.Location = $System_Drawing_Point
|
||||
|
||||
$SelectFile.DataBindings.DefaultDataSourceUpdateMode = 0
|
||||
$SelectFile.add_Click($SelectFile_OnClick)
|
||||
|
||||
$form1.Controls.Add($SelectFile)
|
||||
|
||||
$groupBox1.Name = ‘groupBox1’
|
||||
|
||||
$groupBox1.Text = ‘Select file to view’
|
||||
$System_Drawing_Size = New-Object System.Drawing.Size
|
||||
$System_Drawing_Size.Height = 284
|
||||
$System_Drawing_Size.Width = 426
|
||||
$groupBox1.Size = $System_Drawing_Size
|
||||
$System_Drawing_Point = New-Object System.Drawing.Point
|
||||
$System_Drawing_Point.X = 3
|
||||
$System_Drawing_Point.Y = 12
|
||||
$groupBox1.Location = $System_Drawing_Point
|
||||
$groupBox1.TabStop = $False
|
||||
$groupBox1.DataBindings.DefaultDataSourceUpdateMode = 0
|
||||
$groupBox1.TabIndex = 5
|
||||
|
||||
$form1.Controls.Add($groupBox1)
|
||||
$Displayfile.TabIndex = 0
|
||||
$System_Drawing_Size = New-Object System.Drawing.Size
|
||||
$System_Drawing_Size.Height = 23
|
||||
$System_Drawing_Size.Width = 75
|
||||
$Displayfile.Size = $System_Drawing_Size
|
||||
$Displayfile.Name = ‘Displayfile’
|
||||
$Displayfile.UseVisualStyleBackColor = $True
|
||||
|
||||
$Displayfile.Text = ‘Display file’
|
||||
$System_Drawing_Point = New-Object System.Drawing.Point
|
||||
$System_Drawing_Point.X = 341
|
||||
$System_Drawing_Point.Y = 22
|
||||
$Displayfile.Location = $System_Drawing_Point
|
||||
|
||||
$Displayfile.DataBindings.DefaultDataSourceUpdateMode = 0
|
||||
$Displayfile.add_Click($Displayfile_OnClick)
|
||||
|
||||
$groupBox1.Controls.Add($Displayfile)
|
||||
|
||||
$openFileDialog1.FileName = ‘openFileDialog1’
|
||||
|
||||
#endregion Generated Form Code
|
||||
|
||||
#Show the Form
|
||||
$form1.ShowDialog()| Out-Null
|
||||
|
||||
} #End Function
|
||||
|
||||
#Call the Function
|
||||
GenerateForm
|
||||
4
examples/PowerShell/Start-MSTSC.ps1
Normal file
4
examples/PowerShell/Start-MSTSC.ps1
Normal file
@@ -0,0 +1,4 @@
|
||||
function Start-RDP ($computername)
|
||||
{
|
||||
Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "/v:$computername"
|
||||
}
|
||||
2672
examples/PowerShell/Taschenrechner.ps1
Normal file
2672
examples/PowerShell/Taschenrechner.ps1
Normal file
File diff suppressed because it is too large
Load Diff
BIN
examples/PowerShell/cleancode-powershell-v1_2_08.zip
Normal file
BIN
examples/PowerShell/cleancode-powershell-v1_2_08.zip
Normal file
Binary file not shown.
28
examples/PowerShell/copy_webdav.ps1
Normal file
28
examples/PowerShell/copy_webdav.ps1
Normal file
@@ -0,0 +1,28 @@
|
||||
$REMOTE='https://webdav.example.com/';
|
||||
$REMOTEFOLDER = 'folder';
|
||||
$USERNAME = '';
|
||||
$PASSWORD = '';
|
||||
|
||||
# Define custom auth header
|
||||
$authH = @{Authorization='Basic {0}' -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("${USERNAME}:${PASSWORD}")))};
|
||||
|
||||
# Define custom WebRequest function to allow WebDav-Methods PROPFIND and MKCOL
|
||||
# With PowerShell 6 use "Invoke-RestMethod -CustomMethod" instead
|
||||
function Invoke-CustomRequest($Method, $Url){
|
||||
$req = [net.webrequest]::create($Url);
|
||||
$req.Headers['Authorization'] = $authH.Authorization;
|
||||
$req.Headers['Depth'] = '1';
|
||||
$req.Method = $Method;
|
||||
$reader = [System.IO.StreamReader]::new($req.GetResponse().GetResponseStream());
|
||||
$props = $reader.ReadToEnd();
|
||||
return $props;
|
||||
}
|
||||
|
||||
# Clean up all files on remote: List all files on root (PROPFIND), XPath to find hrefs then call DELETE for each
|
||||
Invoke-CustomRequest -Method 'PROPFIND' -Url $REMOTE/$REMOTEFOLDER/ | Select-Xml -XPath "//*[local-name()='href']" | % { $_.Node.'#text' } | % { Invoke-CustomRequest -Method "DELETE" -Url "$REMOTE/$_" }
|
||||
|
||||
# Create all directories: find all directories with relative paths and call MKCOL to create on remote
|
||||
Get-ChildItem -Directory -Recurse | % {$_.FullName | Resolve-Path -Relative} | % { Invoke-CustomRequest -Method "MKCOL" -Url "{0}/{1}" -f $REMOTE,$_ -Replace '\\','/' }
|
||||
|
||||
# Copy all files: find all files with relative paths then call PUT
|
||||
Get-ChildItem -File -Recurse | % {$_.FullName | Resolve-Path -Relative} | % { Invoke-WebRequest -Method "PUT" -Headers $authH -Infile $_ "{0}/{1}" -f $REMOTE,$_ -Replace '\\','/' }
|
||||
Reference in New Issue
Block a user