Posts

Showing posts from December, 2020

PowerShell AWS Tools for Fast File Copy

https://www.mssqltips.com/sqlservertip/4894/powershell-aws-tools-for-fast-file-copy/   Copy local files to S3 bucket.  

How to Create a List of Your Installed Programs on Windows

https://www.howtogeek.com/165293/how-to-get-a-list-of-software-installed-on-your-pc-with-a-single-command/   Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize

Import CSV File Demo

 Import the latest CSV file from a UNC path # create reference to UNC path new-psdrive -Name "csvsource" -Root "<unc path>" -PSProvider FileSystem # get the latest file   $latestfile = get-childitem -Path "csvsource:" | sort-object lastwritetime -Descending | select-object -First 1  # check type; returns System.IO.FileInfo $latestfile | get-member # send to Excel $latestfile | select-object -Property Name,Length,LastWriteTime | Export-Excel -Now # get full path to source file $sourcefile = join-path "csvsource:" $latestfile.Name # get type; returns String $sourcefile | get-member $sourcefileinfo = get-item $sourcefile # get type; returns System.IO.FileInfo $sourcefileinfo | get-member copy-item $sourcefile -Destination "C:\temp" get-childitem "c:\temp" get-help copy-item -online

Module Demo

 # show modules available get-module -listavailable Shows modules from directories:  C:\Windows\system32\WindowsPowerShell\v1.0\Modules C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules I want to install the sqlserver module:

File and Folder Demo

 # TypeName: System.IO.DirectoryInfo Get-ChildItem C:\Temp | Get-Member New-Item C:\Temp\SAMPLE.TXT Get-ChildItem C:\Temp | Select-Object Name,CreationTImeUTC,LastWriteTimeUTC,Length # TypeName: System.IO.FileInfo Get-Item C:\Temp | Get-Member Import-Csv C:\Temp\FIMCExport_20200829.csv | Export-Excel -Now

Import Excel Data into SQL Server with PowerShell and ADO.Net

https://www.mssqltips.com/sqlservertip/6674/import-excel-data-into-sql-server-with-powershell/  

New-PSDrive Sample

# # New-PSDrive # # show list of providers get-psprovider # create a psdrive for the dev server c: drive new-psdrive -name "devserver" -psprovider "filesystem" -root "\\<SERVER_NAME>\c$" # list the contents of the c:\temp folder on the dev server get-childitem devserver:\temp # save the output from $psversiontable to a file $psversiontable | out-file -FilePath devserver:\temp\psversiontable.txt #  get-content devserver:\temp\psversiontable.txt

Persistent PowerShell: The PowerShell Profile

  https://www.red-gate.com/simple-talk/sysadmin/powershell/persistent-powershell-the-powershell-profile/