Wednesday, 18 November 2020

How to create Power shell script class

 Step1: 


Below is the code script which we have to mention in power shell script file let say , example.ps1



class CommonInformation
{
[string]$folderName
}


[CommonInformation]$cInfo = [CommonInformation]::new()

$cInfo.folderName = Get-Date -Format 'yyyyMMdd_hh_mm_ss'

Write-Host $cInfo.folderName

Power Shell Script Send Parameters to .ps1 file from another .ps1 file

 


Step 1: 

Source file , let say     parent.ps1 file contains below code fragment (script line ) to call  child powershell script file let say child1.ps1



& (path)  parameters

& ((Split-Path $MyInvocation.InvocationName)+'\child1.ps1') 'param1'


Information : 
Here & is command executable statement.
Here path is the path of child1.ps1 file
Here parameters are parameters which you would pass to child1.ps1 powershell script file



Read the parameters from child1.ps1 power shell script file 
Below are the script to read the parameter into power shell script 

$parValue = $args[0]
Write-Host $parValue










Power Shell Scripts

1: 
Q1) Execute power-shell script ps1 file from another power-shell script file.


Ans: 
$archiveModelsPS = '\Untitled4.ps1'

&((SPLIT-PATH $MyInvocation.InvocationName)+$archiveModelsPS)

Friday, 13 November 2020

Power Shell Script SQL

 

MVKSPA_DB_Script.ps1 cannot be loaded. The file 

D:\upload\MVKSPA\MVKSPA\DB\DBDesign\PowerShellScript\MVKSPA_DB_Script.ps1 is not digitally signed. You cannot run this 

script on the current system. For more information about running scripts and setting execution policy, see 

about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.





#Step 1: Check SQLServer Powershell module exist in your system or not , you can find using below command.

Get-module  SQLServer -ListAvailable



#Step 2: If SQL server module is not exist we need to install module , by using below power shell command.

Install-Module -Name SQLServer


Get-Module SqlServer -ListAvailable