Add-AzTableRow command is not available in Azure Cloud Shell - azure-storage

I'm trying to insert new row in my table storage by using Azure Cloud Shell but I'm facing below exception. So let me know any other command that we need to use to insert.
Blockquote
Add-AzTableRow: The term 'Add-AzTableRow' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Blockquote
Below are the command:
$partitionKey1 = "partition1"
$partitionKey2 = "partition2"
Add-AzTableRow `
-table $cloudTable `
-partitionKey $partitionKey1 `
-rowKey ("CA") -property #{"username"="Chris";"userid"=1}

According to the error, it seems that you do not install the module AzTable. Please run the command Get-InstalledModule to check if you have installed the module.
If you have not installed the module, please run the command Install-Module -Name AzTable -Force to install it.
For example
Install-Module -Name AzTable -Force
Import-Module AzTable
$resourceGroup = "<your group name>"
$storageAccountName ="<your account name>"
$storageAccount=Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName
$ctx = $storageAccount.Context
$tableName = "<table name>"
$cloudTable = (Get-AzStorageTable –Name $tableName –Context $ctx).CloudTable
$partitionKey1 = "partition1"
Add-AzTableRow -table $cloudTable -partitionKey $partitionKey1 -rowKey ("CA") -property #{"username"="Chris";"userid"=1}

Related

Cannot Install a Managed Service Account via DevOps

I have a problem i have tried to debug all day now and unable to find a solution.
The Problem
I am trying to automate SQL server builds within a pipeline. I am trying to create and install MSA's. I can add the computer service accounts into AD with the first two commands but when i try to install it on the SQL server, this fails.
My Script so far:
[CmdletBinding()]
param (
[parameter(Mandatory = $true)]
[ValidateNotNullorEmpty()]
[string]$MSA,
[parameter(Mandatory = $true)]
[ValidateNotNullorEmpty()]
[string]$server,
[parameter(Mandatory = $true)]
[ValidateNotNullorEmpty()]
[string]$agentaccount,
[parameter(Mandatory = $true)]
[ValidateNotNullorEmpty()]
[string]$agentpass
)
# Create Creds
[string]$userName = $agentaccount
[string]$userPassword = $agentpass
[SecureString]$secureString = $userPassword | ConvertTo-SecureString -AsPlainText -Force
[PSCredential]$credentialObject = New-Object System.Management.Automation.PSCredential -ArgumentList $userName, $secureString
#Create SVS account and add it to the computer object
$SVS = $MSA + "SVS"
try {
New-ADServiceAccount -name $SVS -Enabled $true -RestrictToSingleComputer -Credential $credentialObject
Add-ADComputerServiceAccount -Identity $server -ServiceAccount $SVS -Credential $credentialObject
Write-Host "$SVS Created"
}
catch {
Write-Host "$SVS already exists"
}
...
#Add the new MSA accounts to the "SQL Server account permissions" group
Add-ADGroupMember "SQL Servers" ($SVS + '$') -Credential $credentialObject
#Create powershell script to install all service accounts onto the required server
#Script Block to run
Add-WindowsFeature RSAT-AD-PowerShell
Import-Module ActiveDirectory -Force
Install-ADServiceAccount -Identity $SVS
...
When i run Install-AdServiceAccount -Identity $SVS the Error output is:
install-adserviceaccount [serviceaccount]
install-adserviceaccount : Cannot install service account. Error Message: 'An unspecified error has occurred'.
At line:1 char:1
+ install-adserviceaccount [serviceaccount]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: ([serviceaccount]:String) [Install-ADServiceAccount], ADException
+ FullyQualifiedErrorId : InstallADServiceAccount:PerformOperation:InstallServiceAcccountFailure,Microsoft.ActiveD
irectory.Management.Commands.InstallADServiceAccount
Tried so far
Ran a powershell task within a Deployment group with the SQL server being a member
Ran a remote target powershell task via an agent to try an invoke the script as an admin.
Created the script locally on the SQL server and invoked the script via a remote target powershell task above too.
** Issue **
When i run this manually on the server when in an Administrator Powershell, the install-adserviceaccount works fine. I guess my question is, is there anyway i can get powershell running as an administrator user from within the pipeline?
Or does anyone have any idea how to solve this.
Thanks.

Using sql query on ssis server sql job using powershell

I want to invoke a sql query/SP on sql job in a ssis server using a powershell script but I don't know how to do that. I've used powershell to run sql queries on sql database but not jobs on ssis. Here is what I have till now-
$ssisServer = New-Object -TypeName Microsoft.SQLServer.Management.Smo.Server($name_of_server)
$IntegrationServices = New-Object "Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices" $ssisServer
$catalog = $IntegrationServices.Catalogs[$catalog]
$folder = $catalog.Folders[$folder]
$project = $folder.Projects[$project]
$sqlJob = $ssisServer.JobServer.Jobs[$existing_job_name]
query= " some sql query "
if ($sqlJob) {
$sqlJob.CurrentRunStatus()
# here I need to run a query on the job
}
The query could be to get details of the job or perform some action on it. Also is this enough as we are just giving the server name here $sqlJob = $ssisServer.JobServer.Jobs[$existing_job_name] to get the job which in a particular folder->project->job? I couldn't try this yet and haven't found much resources on it. Please give me some help to work with.
I didn't work with the SSIS server. But the principle of running SQL queries from SQL is pretty simple.
You should have proper module or you can use snapin of SQL.
I will continue from the second one.
# If you have an SQL server on your server, so this is the possible path where they can be.
$PossiblePaths = 'C:\Program Files\Microsoft SQL Server','C:\Program Files (x86)\Microsoft SQL Server'
# Lets check where we have PSProvider.dll and PSSnapins.dll
$PossiblePaths | ForEach-Object {
Test-Path -Path $_
{
$SQLPSProvider = (Get-ChildItem -Filter "Microsoft.SqlServer.Management.PSProvider.dll" -Path $_ -Recurse).FullName
$SQLPSSnapIn = (Get-ChildItem -Filter "Microsoft.SqlServer.Management.PSSnapins.dll" -Path $_ -Recurse).FullName
}
}
# Lets find Install Utility to add them with it.
$InstallUtil = (Get-ChildItem -Filter "InstallUtil.exe" -Path "$env:windir\Microsoft.NET\Framework64\v2.0*" -Recurse).FullName
if (($null -eq $SQLPSProvider) -or ($null -eq $SQLPSSnapIn))
{
Write-Host "Sorry, SQL PowerShell SnapIn or PowerShell Provider not found." -ForegroundColor Red
}
else
{
# Adding them to our system.
Start-Process -FilePath $InstallUtil -ArgumentList "-i $SQLPSProvider"
Start-Process -FilePath $InstallUtil -ArgumentList "-i $SQLPSSnapIn"
}
# Now they should be in the system and we can add them to our PowerShell session.
Add-PSSnapin -Name SqlServerCmdletSnapin100
Add-PSSnapin -Name SqlServerProviderSnapin100
# Now we should have Invoke-Sqlcmd like if we had SQLServer module.
$SQLServer = "SQL2012"
$SQLInstance = "JustForExample"
$ServerInstance = $SQLServer + '\' + $SQLInstance
# So you typing query for example like attaching DB.
$Query = "CREATE DATABASE ExamleDB ON (FILENAME = `'C:\DBs\ExamleDB.mdf`'), (FILENAME = `'C:\DBs\ExamleDB_log.ldf`') FOR ATTACH"
# And then executing it with Invoke-Sqlcmd like that.
Invoke-Sqlcmd -ServerInstance $ServerInstance -Username 'sa' -Password 'Abcde12345' -Query "Query"

Automatic extract zipped files with passwords in the file name

I analyse data from being sent multiple ZIP files.
They are always in this format:
service_SC30COM_####_20191130_1834.zip
#### is a random number generated by the computer.
Password is SC30COM_####, which is always part of the file name.
Any suggestions on an automation to unzip in bulk?
There is no way to do it on the command prompt without any application.
You can check this
If your remove the password, the code you need, as explain in that microsoft article should be:
$shell=new-object -com shell.application
$CurrentLocation=get-location
$CurrentPath=$CurrentLocation.path
$Location=$shell.namespace($CurrentPath)
$ZipFiles = get-childitem *.zip
$ZipFiles.count | out-default
foreach ($ZipFile in $ZipFiles)
{
$ZipFile.fullname | out-default
$ZipFolder = $shell.namespace($ZipFile.fullname)
$Location.Copyhere($ZipFolder.items())
}
If you install any application that can run on command prompt, you can extract with password. As example, for a individual file, the maximum you will get on Windows 10 is:
PowerShell Expand-Archive -Path "C:\Users\Tuffy\Desktop\PowerShell
Expand-Archive -Path "C:\Users\Whatever\Desktop\service_SC30COM_####_20191130_1834.zip"
-DestinationPath "C:\Users\Whatever\Desktop"p" -DestinationPath "C:\Whatever\Tuffy\Desktop"
Hope it helps!
You can run the following code as a bash script:
#!/bin/bash
for FILE in *.zip
do
echo "Unzipping $FILE ..."
PASSWORD=$(echo $FILE | grep -o -P '(?<=service_)[A-Za-z0-9]*_[0-9]*(?=_)')
unzip -P $PASSWORD $FILE
done
Copy the code
Paste it into FILENAME.sh
Make it executable (chmod +x FILENAME.sh)
Put it besides the zip files
Run it (./FILENAME.sh)

Get-AzScheduledQueryRule what is same funtion script for azurerm

In az Get-AzScheduledQueryRule but in azurerm there is no query rule. I f any alternative script means pls share.
Well, the Get-AzScheduledQueryRule command gets the alert rule whose SIGNAL TYPE is Log Search, its resource type is microsoft.insights/scheduledqueryrules.
For the AzureRM module, your option is to use the Get-AzureRmResource command, specify the -ResourceType with "microsoft.insights/scheduledqueryrules".
Sample:
Get-AzureRmResource -ResourceGroupName "<ResourceGroupName>" -ResourceType "microsoft.insights/scheduledqueryrules" -Name "<alert rule name>" | ConvertTo-Json

How to enable Bitlocker for C drive or any drive?

I am using following PowerShell script to enable BitLocker on C drive,
$SecureString = ConvertTo-SecureString "ABC123" -AsPlainText -Force
Enable-BitLocker -MountPoint "C:" -EncryptionMethod Aes256 -Password $SecureString
And getting the output,
cmdlet Enable-BitLocker at command pipeline position 1
Supply values for the following parameters:
PasswordProtector:
I tried to pass parameters
Enable-BitLocker -MountPoint "C:" -EncryptionMethod Aes256 Add-BitLockerKeyProtector -Password $SecureString -RecoveryKeyPath "\fileserver\keys" -RecoveryKeyProtector
but still, it's showing errors.
Can anyone have a running script to enable BitLocker?
Find the solution for my question, script to configure BitLocker with password,
$SecureString = ConvertTo-SecureString "123456789" -AsPlainText -Force
Enable-BitLocker -MountPoint "D:" -EncryptionMethod Aes256 -PasswordProtector -Password $SecureString