Snippets Collections
# need to try this:
# https://learn.microsoft.com/en-us/azure/batch/quick-run-python

# connect to Azure account:
Connect-AzAccount

# view resource groups 
Get-AzResourceGroup |Format-Table

# list batch accounts
Get-AzBatchAccount

# view batch account info, first create $context parameter:
# https://learn.microsoft.com/en-us/azure/batch/batch-powershell-cmdlets-get-started
$context = Get-AzBatchAccountKeys -AccountName osbatchaccount
# now run this command:
Get-AzBatchPool -Id "osbatchpool" -BatchContext $context

# delete batch account:
Remove-AzBatchAccount -AccountName <account_name>
  
# view batch node information
# https://learn.microsoft.com/en-us/powershell/module/az.batch/?view=azps-11.0.0
Get-AzBatchComputeNode -PoolId "osbatchpool" -Id "nodeid" -BatchContext $context

# view files and URL on a node in batch pool
Get-AzBatchComputeNode "osbatchpool" -Id "nodeid" -BatchContext $context | Get-AzBatchNodeFile -BatchContext $context
#--------------------------------------------------------------------------------
# check if python is installed using powershell:
if ($pythonPath) {
    # Python is installed, get the version
    $pythonVersion = & $pythonPath --version 2>&1
    Write-Output "Python is installed. Version: $pythonVersion"
} else {
    Write-Output "Python is not installed on this node."
}
#--------------------------------------------------------------------------------
# commant to execute PS script 
powershell.exe -ExecutionPolicy Unrestricted -File CheckPython.ps1

# display all system variables unsing Powershell:
dir env:

# remove a single task in azure batch job
Remove-AzBatchTask -JobId "myjob" -Id "mytask10" -BatchContext $context
#--------------------------------------------------------------------------------
# remove all tsks in a batch job:
# Get all tasks in the specified job
$jobId = "adfv2-osbatchpool"
$tasks = Get-AzBatchTask -JobId $jobId -BatchContext $context
# Remove each task in the job
foreach ($task in $tasks) {
     Remove-AzBatchTask -JobId $jobId -Id $task.Id -BatchContext $context
 }
Write-Host "All tasks in the job have been removed."
# generate public key using Powershell
# email at the end is just a signature that you created it
ssh-keygen -t rsa -b 4096 -C "olegserdia@gmail.com"


# if you see an error: WARNING: UNPROTECTED PRIVATE KEY FILE!
# then cd to a folder with files and run this in PS:
icacls * /reset /t /c /q   # https://superuser.com/questions/106181/equivalent-of-chmod-to-change-file-permissions-in-windows

# start the ssh-agent in the background using GIT
eval "$(ssh-agent)"

# using GIT add private key to SSH agent: (PowerShell does not work for some reason)
# cd to .ssh folder first "cd C:/Users/oserdyuk/.ssh"
ssh-add ~/.ssh id_rsa

# add public key to a GitHub repository: Left top corner--> settings

# Clone repository using GIT
# make sure you are in GIT repository : "cd C:/Users/oserdyuk/Documents/AzureProjects/azure-resume"
git clone git@github.com:Serdia/azure-resume.git

######################################################################
						### Push changes to GIT  ###
# save what you've done
git add -A
# say what you've done
git commit -m "Deployed storage and bla bla"
# push what you've done
git push

# if a project created in vs code and then need to be pushed to github
git push --set-upstream git@github.com:Serdia/Flask_WeatherApp.git master


######################################################################
# Troubleshooting

# add Private key to ssh agent using PS
ssh-add C:/Users/oserdyuk/.ssh/id_rsa.pub
# or make sure you are in c:/oserdyuk and run
ssh-add .\.ssh\id_rsa

#if error: Error loading key "C:/Users/oserdyuk/.ssh/id_rsa.pub": invalid format
# you can either overrite key in a right format: (it changes email to oserdyuk@oserdyuk-vm - not sure why)
ssh-keygen -f C:/Users/oserdyuk/.ssh/id_rsa.pub   # click Enter to ignore password

git clone git@github.com:ACloudGuru-Resources/acg-project-azure-resume-starter.git

# to remove keys from SSH agent
ssh-add -D

# service OpenSSH Authentification Agent. Make sure it's running.
C:\WINDOWS\System32\OpenSSH\ssh-agent.exe
# start service in powershell
Start-Service -Name "OpenSSH Authentication Agent"
# check if it started
Get-Service ssh-agent

# start the ssh-agent in the background
eval "$(ssh-agent)"


echo "$(ssh-agent)"

# check whether agent is running or not (GIT)
if ps -p $SSH_AGENT_PID > /dev/null
then
   echo "ssh-agent is already running"
   # Do something knowing the pid exists, i.e. the process with $PID is running
else
eval `ssh-agent -s`
fi


# list all keys that are present in the agent PS or GIT
ssh-add -l



# overwrite the key. Just please enter (to ignore password)
 ssh-keygen -f C:/Users/oserdyuk/.ssh/id_rsa.pub

ssh-add -L # copy the key, place it into GitHub. Worked



ssh-add "C:/Users/oserdyuk/.ssh/id_rsa.pub.pub"  -- Error loading key. Invalid format

ssh-add ~/.ssh my_id_rsa
# make sure the module is installed:
Install-Module -Name ReportingServicesTools

# add computername to trusted hosts list to be able to connect remotely
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "POWERBI"

# view content of the folder
$reportServerUri = 'http://10.36.8.17/ReportServer/'
$folderName = "/AFH/Align General/Programs"
Get-RsFolderContent -ReportServerUri $reportServerUri -RsFolder $folderName | Format-Table -AutoSize


# Return existing data source information for "GrossBudget" report. If multiple datasources uses for queries - it will return all of them. 
$ReportPortalUri = "http://10.36.8.17/Reports"
Get-RsRestItemDataSource -RsItem "/AFH/GrossBudget" -ReportPortalUri $ReportPortalUri

# Get connection string info for "Construction - AY Loss Ratios" report
$ReportPortalUri = "http://10.36.8.17/Reports"
Get-RsRestItemDataSource -RsItem "/AFH/Align General/Programs/Construction - AY Loss Ratios" -ReportPortalUri $ReportPortalUri

#----------------------------------------------------------------------------------------------
#----------Change connection string username and passwork in PowerBI reports-------------------
#----------------------------------------------------------------------------------------------

# connect remotely to POWERBI server
Enter-PSSession -ComputerName POWERBI -Credential ssrsserviceaccount
# specify parameters
$ReportPortalUri = "http://10.36.8.17/Reports"
$ReportName = '/AFH/Catalytic/Underwriter Reports/Underwriter Production'
$Username = 'catalyticSSRS'
$Password = 'RND1101!'
$ServerName = '10.36.8.18'
# grab parameters that are currently exists in a report
$parameters = Get-RsRestItemDataModelParameters $ReportName -ReportPortalUri $ReportPortalUri
$parameters
# Map to a dictionary to access the parameter values.
$parameterdictionary = @{}
foreach ($parameter in $parameters) { $parameterdictionary.Add($parameter.Name, $parameter); }
# change parameter value. "ServerName" or "datasource" whatever the name of the parameter in PowerBI
$parameterdictionary[“ServerName”].Value = $ServerName
# update parameters that are currentl in a report
Set-RsRestItemDataModelParameters -RsItem $ReportName -ReportPortalUri $ReportPortalUri -DataModelParameters $parameters
# print what changed
$parameterdictionary.Values
# set authentification mode, username and password
$dataSources = Get-RsRestItemDataSource -RsItem $ReportName -ReportPortalUri $ReportPortalUri
$dataSources[0].DataModelDataSource.AuthType = 'UsernamePassword' # UsernamePassword should be used when specifying SQL or Basic Credentials
$dataSources[0].DataModelDataSource.Username = $Username
$dataSources[0].DataModelDataSource.Secret = $Password
Set-RsRestItemDataSource -RsItem $ReportName -RsItemType PowerBIReport -DataSources $datasources
Get-Content "\\fs01\Align\Public\OLEGSQLSWITCH\Servers.txt" |
     ForEach-Object{
          if(Test-Connection $_ -Count 1 -quiet){
               "$_ Up"
          }else{
               "$_ Down"
          }
     } 
star

Sat Nov 18 2023 22:30:16 GMT+0000 (Coordinated Universal Time)

#powershell #ping
star

Tue Jun 21 2022 23:59:51 GMT+0000 (Coordinated Universal Time)

#powershell #ping
star

Tue May 24 2022 20:02:11 GMT+0000 (Coordinated Universal Time)

#powershell #ping
star

Wed Nov 03 2021 21:37:07 GMT+0000 (Coordinated Universal Time)

#powershell #ping

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension