AzureAD thinks a user exists when they don't - azure-powershell

This is using the latest Powershell and Azure modules. The user was deleted. My question is why can't I recreate them?
PS C:\Users\Administrator> Get-MsolUser -UserPrincipalName
"bella.daniel#demo.co.uk"
Get-MsolUser : User Not Found. User: bella.daniel#demo.co.uk.
At line:1 char:1
+ Get-MsolUser -UserPrincipalName "bella.daniel#demo.co.uk"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Get-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UserNotFoundException,Microsoft.Online.Admini
stration.Automation.GetUser
PS C:\Users\Administrator> new-msoluser -DisplayName Daniel -UserPrincipalName bella.daniel#demo.co.uk -UsageLocati
on NO -BlockCredential $false -ImmutableId DANIELB620
new-msoluser : Unable to add this user because a user with the user principal name already exists.
At line:1 char:1
+ new-msoluser -DisplayName Daniel -UserPrincipalName bella.daniel#demo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [New-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UniquenessValidationException,Microsoft.Onlin
e.Administration.Automation.NewUser

Ah....so AAD doesn't fully delete users.
By running
Get-MsolUser –ReturnDeletedUsers -All | Remove-MsolUser –RemoveFromRecycleBin –Force
I was able to clear them all out and "re-use" the UPN

Related

I want to install wsl

Enable-WindowsOptionalFeature : Feature name Microsoft-Windows-Subsytem-Linux is unknown.
At line:1 char:1
+ Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand
I was trying to install wsl in my pc but i get this error

Unable to create Log Alert using New-AzActivityLogAlert

We are trying to automate the creation of log alerts using the Az.Monitor library and getting the following error
New-AzActivityLogAlert : The module 'Az.Monitor.internal' could not be loaded. For more information, run 'Import-Module Az.Monitor.internal'.
At E:\Code\Code\ManageLogAnalyticsAlerts.ps1:28 char:5
New-AzActivityLogAlert -Name 'sometest' -ResourceGroupName $logWo ...
CategoryInfo : ObjectNotFound: (Az.Monitor.inte...ctivityLogAlert:String) [New-AzActivityLogAlert], CommandNotFoundException
FullyQualifiedErrorId : CouldNotAutoLoadModule,New-AzActivityLogAlert
The code that we are using is
$receiverName = $actionGroupName
$actionGroupReceiver = New-AzActionGroupReceiver -Name $receiverName -EmailReceiver -EmailAddress 'emailstub#email.com' -UseCommonAlertSchema -WarningAction silentlyContinue
$actionGroup = Set-AzActionGroup -Name $actionGroupName -ResourceGroup $logWorkspace.ResourceGroupName -ShortName $actionGroupName -Receiver $actionGroupReceiver -WarningAction silentlyContinue
Write-Host '----Action Group: ' $actionGroupName ', Action Group Id: ' $actionGroup.Id ', created with Action Group Receiver: ' $receiverName ' in the log workspace: ' $logWorkspace.Name
$activityGroupObject = New-AzActivityLogAlertActionGroupObject -Id $actionGroup.Id -WebhookProperty #{"sampleWebhookProperty"="SamplePropertyValue"}
$scope = "subscriptions/"+(Get-AzContext).Subscription.ID
$condition1=New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject -Equal Ingestion -Field category
# $condition2=New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject -Equal Error -Field level
$any1=New-AzActivityLogAlertAlertRuleLeafConditionObject -Field properties.Operation -Equal 'Data collection"'
$any2=New-AzActivityLogAlertAlertRuleLeafConditionObject -Field properties.incidentType -Equal Incident
$condition3=New-AzActivityLogAlertAlertRuleAnyOfOrLeafConditionObject -AnyOf $any1,$any2
New-AzActivityLogAlert -Name 'sometest' -ResourceGroupName $logWorkspace.ResourceGroupName -Action $activityGroupObject -Condition #($condition1,$condition3) -Location global -Scope $scope
The line which is causing the error is
New-AzActivityLogAlert -Name 'sometest' -ResourceGroupName $logWorkspace.ResourceGroupName -Action $activityGroupObject -Condition #($condition1,$condition3) -Location global -Scope $scope
The Powershell version we have is
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.18362.628
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.628
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
The Az Powerhshell version that I have is 9.0.1.
Apparently, this was a bug, and the Azure team will be deploying the fix to production. Here is the link https://github.com/Azure/azure-powershell/issues/19927 which gives the timeline.

New-VM command fails when trying to clone from another VM

$sourceVM = get-vm -name LinuxBox
$referenceSnapshot = Get-Snapshot -VM "LinuxBox" -Name "snapshot1"
$myDatastore = Get-Datastore -Name datastore1
##$vmhost = Get-VMHost
##-ResourcePool $vmhost
New-VM -Name LinuxTest -VM $sourceVM -LinkedClone -ReferenceSnapshot $referenceSnapshot -Datastore $myDatastore
Above is the code I am trying to use, below I have the error I am getting. I am connected to the ESX server already and all variables contain values. Any insight would be appreciated. ESXi version 6.0. 12.5.0. VMware.PowerCLI
New-VM : 3/31/2022 9:50:14 AM New-VM
At line:1 char:1
+ New-VM -Name LinuxTest -VM $sourceVM -LinkedClone -ReferenceSnapshot ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], InvalidProperty
+ FullyQualifiedErrorId : ViCore_Util10_EncryptionServiceHelper_UpdateViewD
ata_ViErrror,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

Visual Studio Code extension generator not working

I'm following the "Your first extension" visual studio code guide, and after installing yo and generator-code with npm and running yo code I get this error
C:\Users\[My Name]\AppData\Roaming\npm\node_modules\yo\node_modules\execa\index.js:347
throw err;
^
Error: Command failed: powershell (Get-CimInstance -ClassName Win32_OperatingSystem).caption
The term 'Get-CimInstance' 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.
At line:1 char:17
+ (Get-CimInstance <<<< -ClassName Win32_OperatingSystem).caption
+ CategoryInfo : ObjectNotFound: (Get-CimInstance:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
at makeError (C:\Users\[My Name]\AppData\Roaming\npm\node_modules\yo\node_modules\execa\index.js:174:9)
at Function.module.exports.sync (C:\Users\[My Name]\AppData\Roaming\npm\node_modules\yo\node_modules\execa\index.js:338:15)
at windowsRelease (C:\Users\[My Name]\AppData\Roaming\npm\node_modules\yo\node_modules\windows-release\index.js:39:19)
at osName (C:\Users\[My Name]\AppData\Roaming\npm\node_modules\yo\node_modules\os-name\index.js:39:18)
at new Insight (C:\Users\[My Name]\AppData\Roaming\npm\node_modules\yo\node_modules\insight\lib\index.js:37:13)
at Object.<anonymous> (C:\Users\[My Name]\AppData\Roaming\npm\node_modules\yo\lib\cli.js:54:17)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
I really have no idea what to do so any help would be appriciated
Solved by updating from PowerShell v1.0 to PowerShell v5.1

React Native - Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send

I got below error while trying to run my react-native app
Image of console (same content pasted below)
C:\My Projects\SmartBill\SmartBillApp>npx react-native run-windows --logging
i Verbose: ON
- Locating NuGet executableINFO: Could not find files for the given pattern(s).
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:90
+ ... lyContinue; Invoke-WebRequest https://dist.nuget.org/win-x86-commandl ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId :
WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
× Locating NuGet executable
error Cannot read property 'toString' of undefined. Run CLI with --verbose flag for more details.
TypeError: Cannot read property 'toString' of undefined
at Object.runWindows [as func] (C:\My Projects\SmartBill\SmartBillApp\node_modules\react-native-windows\local-cli\runWindows\runWindows.js:67:61)
at process._tickCallback (internal/process/next_tick.js:68:7)